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