| 1 | #!./perl |
| 2 | |
| 3 | # quickie tests to see if h2ph actually runs and does more or less what is |
| 4 | # expected |
| 5 | |
| 6 | BEGIN { |
| 7 | chdir 't' if -d 't'; |
| 8 | @INC = '../lib'; |
| 9 | } |
| 10 | |
| 11 | require './test.pl'; |
| 12 | |
| 13 | my $extracted_program = '../utils/h2ph'; # unix, nt, ... |
| 14 | if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2ph.com'; } |
| 15 | if (!(-e $extracted_program)) { |
| 16 | print "1..0 # Skip: $extracted_program was not built\n"; |
| 17 | exit 0; |
| 18 | } |
| 19 | |
| 20 | plan(6); |
| 21 | |
| 22 | # quickly compare two text files |
| 23 | sub txt_compare { |
| 24 | local $/; |
| 25 | my ($A, $B); |
| 26 | for (($A,$B) = @_) { open(_,"<",$_) ? $_ = <_> : die "$_ : $!"; close _ } |
| 27 | $A cmp $B; |
| 28 | } |
| 29 | |
| 30 | my $result = runperl( progfile => $extracted_program, |
| 31 | stderr => 1, |
| 32 | args => ['-d.', '-Q', 'lib/h2ph.h']); |
| 33 | is( $result, '', "output is free of warnings" ); |
| 34 | is( $?, 0, "$extracted_program runs successfully" ); |
| 35 | |
| 36 | is ( txt_compare("lib/h2ph.ph", "lib/h2ph.pht"), |
| 37 | 0, |
| 38 | "generated file has expected contents" ); |
| 39 | |
| 40 | $result = runperl( progfile => 'lib/h2ph.pht', |
| 41 | switches => ['-c'], |
| 42 | stderr => 1 ); |
| 43 | like( $result, qr/syntax OK$/, "output compiles"); |
| 44 | |
| 45 | $result = runperl( progfile => '_h2ph_pre.ph', |
| 46 | switches => ['-c'], |
| 47 | stderr => 1 ); |
| 48 | like( $result, qr/syntax OK$/, "preamble compiles"); |
| 49 | |
| 50 | $result = runperl( switches => ['-I.', "-w"], |
| 51 | stderr => 1, |
| 52 | prog => <<'PROG' ); |
| 53 | $SIG{__WARN__} = sub { die $_[0] }; require q(lib/h2ph.pht); |
| 54 | PROG |
| 55 | is( $result, '', "output free of warnings" ); |
| 56 | |
| 57 | # cleanup |
| 58 | END { |
| 59 | 1 while unlink("lib/h2ph.ph"); |
| 60 | 1 while unlink("_h2ph_pre.ph"); |
| 61 | } |