1# -*- cperl -*- 2 3use strict; 4use warnings; 5 6use Test::More; 7use Config::AutoConf; 8 9END 10{ 11 foreach my $f (<config*.*>) 12 { 13 -e $f and unlink $f; 14 } 15} 16 17Config::AutoConf->check_header("stdio.h") or plan skip_all => "No working compile environment"; 18 19my $ac_1; 20 21ok($ac_1 = Config::AutoConf->new(logfile => "config3.log"), "Instantiating Config::AutoConf for check_lib() tests"); 22ok($ac_1->check_header("stdio.h")) or plan skip_all => "No working compile environment"; 23 24ok($ac_1->check_func("printf"), "Every system should have a printf"); 25my $set_me; 26$ac_1->check_func( 27 "scanf", 28 { 29 action_on_true => sub { $set_me = 1 }, 30 action_on_false => sub { $set_me = 0 } 31 } 32); 33ok(defined $set_me, "Having scanf or not, but now we know"); 34ok($ac_1->check_funcs([qw(sprintf sscanf)]), "Every system should have sprintf and sscanf"); 35 36TODO: 37{ 38 local $TODO = "It seems some Windows machine doesn't have -lm" if $^O eq "MSWin32"; 39 40 ## OK, we really hope people have -lm around 41 ok(!$ac_1->check_lib("m", "foobar"), "foobar() not in -lm"); 42 ok($ac_1->check_lib("m", "atan"), "atan() in -lm"); 43 44 my ($where_atan, $ac_2); 45 ok($ac_2 = Config::AutoConf->new(logfile => "config4.log"), "Instantiating Config::AutoConf for search_libs() tests"); 46 ok($where_atan = $ac_2->search_libs("atan", [qw(m)]), "searching lib for atan()"); 47 isnt($where_atan, 0, "library for atan() found (or none required)"); 48} 49 50TODO: 51{ 52 local $TODO = "__builtin_\$1 isn't supported overall - sane prove would need compiler detection"; 53 54 ok($ac_1->check_builtin("expect"), "__buitin_expect available"); 55} 56 57my ($ac_3, %math_funcs); 58ok($ac_3 = Config::AutoConf->new(logfile => "config4_2.log"), "Instantiating Config::AutoConf for check_lm() tests"); 59$ac_3->check_lm( 60 { 61 action_on_func_lib_true => sub { my ($func, $lib, @extra) = @_; $math_funcs{$func} = $lib }, 62 action_on_func_lib_false => sub { my ($func, $lib, @extra) = @_; $math_funcs{$func} = 0 }, 63 } 64); 65is_deeply( 66 [sort keys %math_funcs], 67 [sort $ac_3->_check_lm_funcs], 68 "Math functions (" . join(", ", $ac_3->_check_lm_funcs) . ") tested for -lm" 69); 70 71eval { 72 $ac_3->check_lm( 73 { 74 action_on_lib_true => sub { }, 75 action_on_func_lib_true => sub { }, 76 } 77 ); 78}; 79ok($@, "action_on_lib_true and action_on_func_lib_true cannot be used together"); 80 81eval { 82 $ac_3->check_lm( 83 { 84 action_on_lib_false => sub { }, 85 action_on_func_lib_false => sub { }, 86 } 87 ); 88}; 89ok($@, "action_on_lib_false and action_on_func_lib_false cannot be used together"); 90 91TODO: 92{ 93 -f "META.yml" or $ENV{AUTOMATED_TESTING} = 1; 94 local $TODO = "Quick fix: TODO - analyse diag later" unless $ENV{AUTOMATED_TESTING}; 95 my ($fh, $fbuf, $dbuf, @old_logfh); 96 $dbuf = ""; 97 98 if ($] < 5.008) 99 { 100 require IO::String; 101 $fh = IO::String->new($dbuf); 102 } 103 else 104 { 105 open($fh, "+>", \$dbuf); 106 } 107 @old_logfh = @{$ac_1->{logfh}}; 108 $ac_1->add_log_fh($fh); 109 cmp_ok(scalar @{$ac_1->{logfh}}, "==", 2, "Successfully added 2nd loghandle"); 110 ok($ac_1->check_link_perlapi(), "Could link perl extensions") or diag($dbuf); 111 scalar @old_logfh and $ac_1->delete_log_fh($fh); 112 scalar @old_logfh and is_deeply(\@old_logfh, $ac_1->{logfh}, "add_log_fh/delete_log_fh"); 113 defined $fh and close($fh); 114 $fh = undef; 115} 116 117done_testing; 118