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