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 |
8 | |
9 | BEGIN { |
10 | chdir 't' if -d 't'; |
11 | @INC = '../lib'; |
12 | } |
13 | |
45ea237c |
14 | # use strict; # we are not really testing this |
3a9c887e |
15 | use File::Path; # for cleaning up with rmtree() |
46b277d5 |
16 | use Test; |
17 | |
3a9c887e |
18 | |
19 | my $extracted_program = '../utils/h2xs'; # unix, nt, ... |
20 | if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; } |
45ea237c |
21 | if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; } |
3a9c887e |
22 | if (!(-e $extracted_program)) { |
23 | print "1..0 # Skip: $extracted_program was not built\n"; |
24 | exit 0; |
25 | } |
26 | # You might also wish to bail out if your perl platform does not |
27 | # do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity. |
28 | |
29 | my $dupe = '2>&1'; # ok on unix, nt, VMS, ... |
30 | my $lib = '"-I../lib"'; # ok on unix, nt, The extra \" are for VMS |
31 | # The >&1 would create a file named &1 on MPW (STDERR && STDOUT are |
32 | # already merged). |
33 | if ($^O eq 'MacOS') { |
34 | $dupe = ''; |
45ea237c |
35 | $lib = '-x -I::lib:'; # -x overcomes MPW $Config{startperl} anomaly |
3a9c887e |
36 | } |
37 | # $name should differ from system header file names and must |
38 | # not already be found in the t/ subdirectory for perl. |
39 | my $name = 'h2xst'; |
46b277d5 |
40 | my $header = "$name.h"; |
3a9c887e |
41 | |
46b277d5 |
42 | my @tests = ( |
43 | "-f -n $name", <<"EOXSFILES", |
3a9c887e |
44 | Writing $name/$name.pm |
45 | Writing $name/$name.xs |
9a7df4f2 |
46 | Writing $name/fallback.c |
47 | Writing $name/fallback.xs |
3a9c887e |
48 | Writing $name/Makefile.PL |
49 | Writing $name/README |
50 | Writing $name/t/1.t |
51 | Writing $name/Changes |
52 | Writing $name/MANIFEST |
53 | EOXSFILES |
54 | |
46b277d5 |
55 | "\"-X\" -f -n $name", <<"EONOXSFILES", |
3a9c887e |
56 | Writing $name/$name.pm |
57 | Writing $name/Makefile.PL |
58 | Writing $name/README |
59 | Writing $name/t/1.t |
60 | Writing $name/Changes |
61 | Writing $name/MANIFEST |
62 | EONOXSFILES |
63 | |
46b277d5 |
64 | "-f -n $name $header", <<"EOXSFILES", |
65 | Writing $name/$name.pm |
66 | Writing $name/$name.xs |
9a7df4f2 |
67 | Writing $name/fallback.c |
68 | Writing $name/fallback.xs |
46b277d5 |
69 | Writing $name/Makefile.PL |
70 | Writing $name/README |
71 | Writing $name/t/1.t |
72 | Writing $name/Changes |
73 | Writing $name/MANIFEST |
74 | EOXSFILES |
75 | ); |
76 | |
77 | my $total_tests = 3; # opening, closing and deleting the header file. |
78 | for (my $i = $#tests; $i > 0; $i-=2) { |
79 | # 1 test for running it, 1 test for the expected result, and 1 for each file |
80 | # use the () to force list context and hence count the number of matches. |
81 | $total_tests += 2 + (() = $tests[$i] =~ /(Writing)/sg); |
82 | } |
83 | |
84 | plan tests => $total_tests; |
85 | |
86 | ok (open (HEADER, ">$header")); |
87 | print HEADER <<HEADER or die $!; |
88 | #define Camel 2 |
89 | #define Dromedary 1 |
90 | HEADER |
91 | ok (close (HEADER)); |
92 | |
93 | while (my ($args, $expectation) = splice @tests, 0, 2) { |
94 | # h2xs warns about what it is writing hence the (possibly unportable) |
95 | # 2>&1 dupe: |
96 | # does it run? |
97 | my $prog = "$^X $lib $extracted_program $args $dupe"; |
98 | @result = `$prog`; |
99 | ok ($?, 0, "running $prog"); |
100 | $result = join("",@result); |
101 | |
102 | # accomodate MPW # comment character prependage |
103 | if ($^O eq 'MacOS') { |
104 | $result =~ s/#\s*//gs; |
105 | } |
106 | |
107 | #print "# expectation is >$expectation<\n"; |
108 | #print "# result is >$result<\n"; |
109 | # Was the output the list of files that were expected? |
110 | ok ($result, $expectation, "running $prog"); |
111 | |
112 | $expectation =~ s/Writing //; # remove leader |
113 | foreach (split(/Writing /,$expectation)) { |
3a9c887e |
114 | chomp; # remove \n |
45ea237c |
115 | if ($^O eq 'MacOS') { |
46b277d5 |
116 | $_ = ':' . join(':',split(/\//,$_)); |
117 | $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug? |
45ea237c |
118 | } |
46b277d5 |
119 | ok (-e $_, 1, "$_ missing"); |
120 | } |
3a9c887e |
121 | |
46b277d5 |
122 | # clean up |
123 | rmtree($name); |
124 | } |
3a9c887e |
125 | |
46b277d5 |
126 | ok (unlink ($header), 1, $!); |