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() |
46b277d5 | 19 | use Test; |
31022a5a | 20 | use File::Spec; |
3a9c887e PK |
21 | |
22 | my $extracted_program = '../utils/h2xs'; # unix, nt, ... | |
23 | if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; } | |
45ea237c | 24 | if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; } |
3a9c887e PK |
25 | if (!(-e $extracted_program)) { |
26 | print "1..0 # Skip: $extracted_program was not built\n"; | |
27 | exit 0; | |
28 | } | |
29 | # You might also wish to bail out if your perl platform does not | |
30 | # do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity. | |
31 | ||
fa1e5b33 JH |
32 | # ok on unix, nt, VMS, ... |
33 | my $dupe = '2>&1'; | |
34 | # ok on unix, nt, The extra \" are for VMS | |
35 | my $lib = '"-I../lib" "-I../../lib"'; | |
3a9c887e PK |
36 | # The >&1 would create a file named &1 on MPW (STDERR && STDOUT are |
37 | # already merged). | |
38 | if ($^O eq 'MacOS') { | |
39 | $dupe = ''; | |
fa1e5b33 JH |
40 | # -x overcomes MPW $Config{startperl} anomaly |
41 | $lib = '-x -I::lib: -I:::lib:'; | |
3a9c887e PK |
42 | } |
43 | # $name should differ from system header file names and must | |
44 | # not already be found in the t/ subdirectory for perl. | |
45 | my $name = 'h2xst'; | |
46b277d5 | 46 | my $header = "$name.h"; |
3e6e4ea8 | 47 | my $thisversion = sprintf "%vd", $^V; |
3a9c887e | 48 | |
46b277d5 | 49 | my @tests = ( |
3e6e4ea8 NC |
50 | "-f -n $name", $], <<"EOXSFILES", |
51 | Defaulting to backwards compatibility with perl $thisversion | |
52 | If you intend this module to be compatible with earlier perl versions, please | |
53 | specify a minimum perl version with the -b option. | |
54 | ||
0a7c7f4f | 55 | Writing $name/ppport.h |
3a9c887e PK |
56 | Writing $name/$name.pm |
57 | Writing $name/$name.xs | |
9a7df4f2 NC |
58 | Writing $name/fallback.c |
59 | Writing $name/fallback.xs | |
3a9c887e PK |
60 | Writing $name/Makefile.PL |
61 | Writing $name/README | |
62 | Writing $name/t/1.t | |
63 | Writing $name/Changes | |
64 | Writing $name/MANIFEST | |
65 | EOXSFILES | |
66 | ||
3e6e4ea8 | 67 | "-f -n $name -b $thisversion", $], <<"EOXSFILES", |
0a7c7f4f | 68 | Writing $name/ppport.h |
3e6e4ea8 NC |
69 | Writing $name/$name.pm |
70 | Writing $name/$name.xs | |
71 | Writing $name/fallback.c | |
72 | Writing $name/fallback.xs | |
73 | Writing $name/Makefile.PL | |
74 | Writing $name/README | |
75 | Writing $name/t/1.t | |
76 | Writing $name/Changes | |
77 | Writing $name/MANIFEST | |
78 | EOXSFILES | |
79 | ||
80 | "-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES", | |
0a7c7f4f | 81 | Writing $name/ppport.h |
3e6e4ea8 NC |
82 | Writing $name/$name.pm |
83 | Writing $name/$name.xs | |
84 | Writing $name/fallback.c | |
85 | Writing $name/fallback.xs | |
86 | Writing $name/Makefile.PL | |
87 | Writing $name/README | |
88 | Writing $name/t/1.t | |
89 | Writing $name/Changes | |
90 | Writing $name/MANIFEST | |
91 | EOXSFILES | |
92 | ||
93 | "-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES", | |
0a7c7f4f | 94 | Writing $name/ppport.h |
3e6e4ea8 NC |
95 | Writing $name/$name.pm |
96 | Writing $name/$name.xs | |
97 | Writing $name/fallback.c | |
98 | Writing $name/fallback.xs | |
99 | Writing $name/Makefile.PL | |
100 | Writing $name/README | |
101 | Writing $name/t/1.t | |
102 | Writing $name/Changes | |
103 | Writing $name/MANIFEST | |
104 | EOXSFILES | |
105 | ||
106 | "\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES", | |
3a9c887e PK |
107 | Writing $name/$name.pm |
108 | Writing $name/Makefile.PL | |
109 | Writing $name/README | |
110 | Writing $name/t/1.t | |
111 | Writing $name/Changes | |
112 | Writing $name/MANIFEST | |
113 | EONOXSFILES | |
114 | ||
3e6e4ea8 | 115 | "-f -n $name $header -b $thisversion", $], <<"EOXSFILES", |
0a7c7f4f | 116 | Writing $name/ppport.h |
46b277d5 NC |
117 | Writing $name/$name.pm |
118 | Writing $name/$name.xs | |
9a7df4f2 NC |
119 | Writing $name/fallback.c |
120 | Writing $name/fallback.xs | |
46b277d5 NC |
121 | Writing $name/Makefile.PL |
122 | Writing $name/README | |
123 | Writing $name/t/1.t | |
124 | Writing $name/Changes | |
125 | Writing $name/MANIFEST | |
126 | EOXSFILES | |
127 | ); | |
128 | ||
129 | my $total_tests = 3; # opening, closing and deleting the header file. | |
3e6e4ea8 | 130 | for (my $i = $#tests; $i > 0; $i-=3) { |
46b277d5 | 131 | # 1 test for running it, 1 test for the expected result, and 1 for each file |
3e6e4ea8 | 132 | # plus 1 to open and 1 to check for the use in $name.pm and Makefile.PL |
46b277d5 | 133 | # use the () to force list context and hence count the number of matches. |
3e6e4ea8 | 134 | $total_tests += 6 + (() = $tests[$i] =~ /(Writing)/sg); |
46b277d5 NC |
135 | } |
136 | ||
137 | plan tests => $total_tests; | |
138 | ||
139 | ok (open (HEADER, ">$header")); | |
140 | print HEADER <<HEADER or die $!; | |
141 | #define Camel 2 | |
142 | #define Dromedary 1 | |
143 | HEADER | |
144 | ok (close (HEADER)); | |
145 | ||
3e6e4ea8 | 146 | while (my ($args, $version, $expectation) = splice @tests, 0, 3) { |
46b277d5 NC |
147 | # h2xs warns about what it is writing hence the (possibly unportable) |
148 | # 2>&1 dupe: | |
149 | # does it run? | |
150 | my $prog = "$^X $lib $extracted_program $args $dupe"; | |
151 | @result = `$prog`; | |
fa1e5b33 | 152 | ok ($?, 0, "running $prog "); |
46b277d5 NC |
153 | $result = join("",@result); |
154 | ||
155 | # accomodate MPW # comment character prependage | |
156 | if ($^O eq 'MacOS') { | |
157 | $result =~ s/#\s*//gs; | |
158 | } | |
159 | ||
160 | #print "# expectation is >$expectation<\n"; | |
161 | #print "# result is >$result<\n"; | |
162 | # Was the output the list of files that were expected? | |
163 | ok ($result, $expectation, "running $prog"); | |
164 | ||
3e6e4ea8 | 165 | foreach ($expectation =~ /Writing\s+(\S+)/gm) { |
45ea237c | 166 | if ($^O eq 'MacOS') { |
46b277d5 NC |
167 | $_ = ':' . join(':',split(/\//,$_)); |
168 | $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug? | |
45ea237c | 169 | } |
46b277d5 NC |
170 | ok (-e $_, 1, "$_ missing"); |
171 | } | |
3a9c887e | 172 | |
3e6e4ea8 | 173 | foreach my $leaf ("$name.pm", 'Makefile.PL') { |
31022a5a | 174 | my $file = File::Spec->catfile($name, $leaf); |
3e6e4ea8 NC |
175 | if (ok (open (FILE, $file), 1, "open $file")) { |
176 | my $match = qr/use $version;/; | |
177 | my $found; | |
178 | while (<FILE>) { | |
179 | last if $found = /$match/; | |
180 | } | |
181 | ok ($found, 1, "looking for /$match/ in $file"); | |
182 | close FILE or die "close $file: $!"; | |
183 | } | |
184 | } | |
46b277d5 NC |
185 | # clean up |
186 | rmtree($name); | |
187 | } | |
3a9c887e | 188 | |
46b277d5 | 189 | ok (unlink ($header), 1, $!); |