Commit | Line | Data |
---|---|---|
46b277d5 | 1 | #!./perl -w |
3a9c887e PK |
2 | |
3 | # Some quick tests to see if h2xs actually runs and creates files as | |
4 | # expected. File contents include date stamps and/or usernames | |
5 | # hence are not checked. File existence is checked with -e though. | |
6 | # This test depends on File::Path::rmtree() to clean up with. | |
7 | # - pvhp | |
3e6e4ea8 NC |
8 | # |
9 | # We are now checking that the correct use $version; is present in | |
10 | # Makefile.PL and $module.pm | |
fa1e5b33 | 11 | |
3a9c887e PK |
12 | BEGIN { |
13 | chdir 't' if -d 't'; | |
14 | @INC = '../lib'; | |
15 | } | |
16 | ||
45ea237c | 17 | # use strict; # we are not really testing this |
3a9c887e | 18 | use File::Path; # for cleaning up with rmtree() |
1cb0fb50 | 19 | use Test::More; |
31022a5a | 20 | use File::Spec; |
1cb0fb50 NC |
21 | use File::Find; |
22 | use ExtUtils::Manifest; | |
23 | # Don't want its diagnostics getting in the way of ours. | |
24 | $ExtUtils::Manifest::Quiet=1; | |
25 | my $up = File::Spec->updir(); | |
3a9c887e PK |
26 | |
27 | my $extracted_program = '../utils/h2xs'; # unix, nt, ... | |
28 | if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; } | |
45ea237c | 29 | if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; } |
3a9c887e PK |
30 | if (!(-e $extracted_program)) { |
31 | print "1..0 # Skip: $extracted_program was not built\n"; | |
32 | exit 0; | |
33 | } | |
34 | # You might also wish to bail out if your perl platform does not | |
35 | # do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity. | |
36 | ||
fa1e5b33 JH |
37 | # ok on unix, nt, VMS, ... |
38 | my $dupe = '2>&1'; | |
39 | # ok on unix, nt, The extra \" are for VMS | |
40 | my $lib = '"-I../lib" "-I../../lib"'; | |
3a9c887e PK |
41 | # The >&1 would create a file named &1 on MPW (STDERR && STDOUT are |
42 | # already merged). | |
43 | if ($^O eq 'MacOS') { | |
44 | $dupe = ''; | |
fa1e5b33 JH |
45 | # -x overcomes MPW $Config{startperl} anomaly |
46 | $lib = '-x -I::lib: -I:::lib:'; | |
3a9c887e PK |
47 | } |
48 | # $name should differ from system header file names and must | |
49 | # not already be found in the t/ subdirectory for perl. | |
50 | my $name = 'h2xst'; | |
46b277d5 | 51 | my $header = "$name.h"; |
3e6e4ea8 | 52 | my $thisversion = sprintf "%vd", $^V; |
3a9c887e | 53 | |
46b277d5 | 54 | my @tests = ( |
3e6e4ea8 NC |
55 | "-f -n $name", $], <<"EOXSFILES", |
56 | Defaulting to backwards compatibility with perl $thisversion | |
57 | If you intend this module to be compatible with earlier perl versions, please | |
58 | specify a minimum perl version with the -b option. | |
59 | ||
0a7c7f4f | 60 | Writing $name/ppport.h |
3a9c887e PK |
61 | Writing $name/$name.pm |
62 | Writing $name/$name.xs | |
1cb0fb50 NC |
63 | Writing $name/fallback/const-c.inc |
64 | Writing $name/fallback/const-xs.inc | |
3a9c887e PK |
65 | Writing $name/Makefile.PL |
66 | Writing $name/README | |
67 | Writing $name/t/1.t | |
68 | Writing $name/Changes | |
69 | Writing $name/MANIFEST | |
70 | EOXSFILES | |
71 | ||
3e6e4ea8 | 72 | "-f -n $name -b $thisversion", $], <<"EOXSFILES", |
0a7c7f4f | 73 | Writing $name/ppport.h |
3e6e4ea8 NC |
74 | Writing $name/$name.pm |
75 | Writing $name/$name.xs | |
1cb0fb50 NC |
76 | Writing $name/fallback/const-c.inc |
77 | Writing $name/fallback/const-xs.inc | |
3e6e4ea8 NC |
78 | Writing $name/Makefile.PL |
79 | Writing $name/README | |
80 | Writing $name/t/1.t | |
81 | Writing $name/Changes | |
82 | Writing $name/MANIFEST | |
83 | EOXSFILES | |
84 | ||
85 | "-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES", | |
0a7c7f4f | 86 | Writing $name/ppport.h |
3e6e4ea8 NC |
87 | Writing $name/$name.pm |
88 | Writing $name/$name.xs | |
1cb0fb50 NC |
89 | Writing $name/fallback/const-c.inc |
90 | Writing $name/fallback/const-xs.inc | |
3e6e4ea8 NC |
91 | Writing $name/Makefile.PL |
92 | Writing $name/README | |
93 | Writing $name/t/1.t | |
94 | Writing $name/Changes | |
95 | Writing $name/MANIFEST | |
96 | EOXSFILES | |
97 | ||
98 | "-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES", | |
0a7c7f4f | 99 | Writing $name/ppport.h |
3e6e4ea8 NC |
100 | Writing $name/$name.pm |
101 | Writing $name/$name.xs | |
1cb0fb50 NC |
102 | Writing $name/fallback/const-c.inc |
103 | Writing $name/fallback/const-xs.inc | |
3e6e4ea8 NC |
104 | Writing $name/Makefile.PL |
105 | Writing $name/README | |
106 | Writing $name/t/1.t | |
107 | Writing $name/Changes | |
108 | Writing $name/MANIFEST | |
109 | EOXSFILES | |
110 | ||
111 | "\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES", | |
3a9c887e PK |
112 | Writing $name/$name.pm |
113 | Writing $name/Makefile.PL | |
114 | Writing $name/README | |
115 | Writing $name/t/1.t | |
116 | Writing $name/Changes | |
117 | Writing $name/MANIFEST | |
118 | EONOXSFILES | |
119 | ||
3e6e4ea8 | 120 | "-f -n $name $header -b $thisversion", $], <<"EOXSFILES", |
0a7c7f4f | 121 | Writing $name/ppport.h |
46b277d5 NC |
122 | Writing $name/$name.pm |
123 | Writing $name/$name.xs | |
1cb0fb50 NC |
124 | Writing $name/fallback/const-c.inc |
125 | Writing $name/fallback/const-xs.inc | |
46b277d5 NC |
126 | Writing $name/Makefile.PL |
127 | Writing $name/README | |
128 | Writing $name/t/1.t | |
129 | Writing $name/Changes | |
130 | Writing $name/MANIFEST | |
131 | EOXSFILES | |
132 | ); | |
133 | ||
134 | my $total_tests = 3; # opening, closing and deleting the header file. | |
3e6e4ea8 | 135 | for (my $i = $#tests; $i > 0; $i-=3) { |
46b277d5 | 136 | # 1 test for running it, 1 test for the expected result, and 1 for each file |
3e6e4ea8 | 137 | # plus 1 to open and 1 to check for the use in $name.pm and Makefile.PL |
1cb0fb50 | 138 | # And 1 more for our check for "bonus" files, 2 more for ExtUtil::Manifest. |
46b277d5 | 139 | # use the () to force list context and hence count the number of matches. |
1cb0fb50 | 140 | $total_tests += 9 + (() = $tests[$i] =~ /(Writing)/sg); |
46b277d5 NC |
141 | } |
142 | ||
143 | plan tests => $total_tests; | |
144 | ||
1cb0fb50 | 145 | ok (open (HEADER, ">$header"), "open '$header'"); |
46b277d5 NC |
146 | print HEADER <<HEADER or die $!; |
147 | #define Camel 2 | |
148 | #define Dromedary 1 | |
149 | HEADER | |
1cb0fb50 | 150 | ok (close (HEADER), "close '$header'"); |
46b277d5 | 151 | |
3e6e4ea8 | 152 | while (my ($args, $version, $expectation) = splice @tests, 0, 3) { |
46b277d5 NC |
153 | # h2xs warns about what it is writing hence the (possibly unportable) |
154 | # 2>&1 dupe: | |
155 | # does it run? | |
156 | my $prog = "$^X $lib $extracted_program $args $dupe"; | |
157 | @result = `$prog`; | |
1cb0fb50 | 158 | cmp_ok ($?, "==", 0, "running $prog "); |
46b277d5 NC |
159 | $result = join("",@result); |
160 | ||
161 | # accomodate MPW # comment character prependage | |
162 | if ($^O eq 'MacOS') { | |
163 | $result =~ s/#\s*//gs; | |
164 | } | |
165 | ||
166 | #print "# expectation is >$expectation<\n"; | |
167 | #print "# result is >$result<\n"; | |
168 | # Was the output the list of files that were expected? | |
1cb0fb50 NC |
169 | is ($result, $expectation, "running $prog"); |
170 | ||
171 | my (%got); | |
172 | find (sub {$got{$File::Find::name}++ unless -d $_}, $name); | |
46b277d5 | 173 | |
3e6e4ea8 | 174 | foreach ($expectation =~ /Writing\s+(\S+)/gm) { |
45ea237c | 175 | if ($^O eq 'MacOS') { |
46b277d5 NC |
176 | $_ = ':' . join(':',split(/\//,$_)); |
177 | $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug? | |
45ea237c | 178 | } |
7ce7e561 CB |
179 | if ($^O eq 'VMS') { |
180 | $_ .= '.' unless $_ =~ m/\./; | |
181 | $_ = lc($_) unless exists $got{$_}; | |
182 | } | |
1cb0fb50 NC |
183 | ok (-e $_, "check for $_") and delete $got{$_}; |
184 | } | |
185 | my @extra = keys %got; | |
186 | unless (ok (!@extra, "Are any extra files present?")) { | |
187 | print "# These files are unexpectedly present:\n"; | |
188 | print "# $_\n" foreach sort @extra; | |
46b277d5 | 189 | } |
3a9c887e | 190 | |
1cb0fb50 NC |
191 | chdir ($name) or die "chdir $name failed: $!"; |
192 | # Aargh. Something wants to load a bit of regexp. And we have to chdir | |
193 | # for ExtUtils::Manifest. Caught between a rock and a hard place, so this | |
194 | # seems the least evil thing to do: | |
195 | push @INC, "../../lib"; | |
196 | my ($missing, $extra) = ExtUtils::Manifest::fullcheck(); | |
197 | is_deeply ($missing, [], "No files in the MANIFEST should be missing"); | |
198 | is_deeply ($extra, [], "and all files present should be in the MANIFEST"); | |
199 | pop @INC; | |
200 | chdir ($up) or die "chdir $up failed: $!"; | |
201 | ||
3e6e4ea8 | 202 | foreach my $leaf ("$name.pm", 'Makefile.PL') { |
31022a5a | 203 | my $file = File::Spec->catfile($name, $leaf); |
1cb0fb50 | 204 | if (ok (open (FILE, $file), "open $file")) { |
3e6e4ea8 NC |
205 | my $match = qr/use $version;/; |
206 | my $found; | |
207 | while (<FILE>) { | |
208 | last if $found = /$match/; | |
209 | } | |
1cb0fb50 | 210 | ok ($found, "looking for /$match/ in $file"); |
3e6e4ea8 NC |
211 | close FILE or die "close $file: $!"; |
212 | } | |
213 | } | |
46b277d5 NC |
214 | # clean up |
215 | rmtree($name); | |
216 | } | |
3a9c887e | 217 | |
1cb0fb50 | 218 | cmp_ok (unlink ($header), "==", 1, "unlink '$header'") or die "\$! is $!"; |