/
70-wikidoc-script.t
154 lines (109 loc) · 3.82 KB
/
70-wikidoc-script.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use Test::More;
use File::Spec;
use File::Temp;
use lib "./t";;
use CLI;
#--------------------------------------------------------------------------#
# Get optional test support
#--------------------------------------------------------------------------#
eval "use Test::Differences";
my $HAVE_DIFF = $@ eq '' ? 1 : 0;
sub diff_or_is {
my ($got, $expected, $label ) = @_;
if ( $HAVE_DIFF ) {
eq_or_diff( $got, $expected, $label );
}
else {
is( $got, $expected, $label );
}
}
#--------------------------------------------------------------------------#
# setup program
#--------------------------------------------------------------------------#
my $script = File::Spec->catfile( "bin", "wikidoc" );
if ( ! -r $script ) {
plan skip_all => "because I couldn't find the wikidoc script to test";
}
else {
plan tests => 9;
}
my $wikidoc = CLI->new($script);
#--------------------------------------------------------------------------#
# setup input and expected
#--------------------------------------------------------------------------#
my $input_string = <<'INPUT';
=for wikidoc = START
=cut
### = NAME
### wikidoc - a script
INPUT
my $expected = <<'EXPECTED';
=pod
=head1 START
EXPECTED
my $expected_c = <<'EXPECTED_C';
=pod
=head1 START
=head1 NAME
wikidoc - a script
EXPECTED_C
#--------------------------------------------------------------------------#
# setup temporary files
#--------------------------------------------------------------------------#
my $output_file = File::Temp->new();
my $input_file = File::Temp->new();
# File::Temp defaults to binmode so change that on Windows
if ( $^O eq 'MSWin32' ) {
binmode $output_file, ":crlf";
binmode $input_file, ":crlf";
}
# init the input file
print $input_file $input_string;
seek $input_file, 0, 0;
#--------------------------------------------------------------------------#
# Start testing
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
# wikidoc file file
#--------------------------------------------------------------------------#
$wikidoc->runs_ok( "$input_file", "$output_file" );
$wikidoc->stdout_like( qr/Extracting Pod from \Q$input_file\E/,
"'wikidoc file file' status message"
);
# recover output for testing
seek $output_file, 0, 0;
$got = do { local $/; <$output_file> };
$got =~ s{\A [^\n]+ \n \n}{}xms; # strip "Generated by" line
diff_or_is( $got, $expected,
"'wikidoc file file' output file contents"
);
#--------------------------------------------------------------------------#
# wikidoc -c file file
#--------------------------------------------------------------------------#
$wikidoc->runs_ok( "-c", "$input_file", "$output_file" );
# recover output for testing
seek $output_file, 0, 0;
$got = do { local $/; <$output_file> };
$got =~ s{\A [^\n]+ \n \n}{}xms; # strip "Generated by" line
diff_or_is( $got, $expected_c,
"'wikidoc -c file file' output file contents"
);
#--------------------------------------------------------------------------#
# wikidoc -c file
#--------------------------------------------------------------------------#
$wikidoc->runs_ok( "-c", "$input_file" );
my $script_output = $wikidoc->stdout();
$script_output =~ s{\A [^\n]+ \n \n}{}xms; # strip "Generated by" line
diff_or_is( $script_output, $expected_c,
"'wikidoc -c file' output file contents"
);
#--------------------------------------------------------------------------#
# wikidoc -c
#--------------------------------------------------------------------------#
$wikidoc->stdin( $input_string );
$wikidoc->runs_ok( "-c" );
$script_output = $wikidoc->stdout();
$script_output =~ s{\A [^\n]+ \n \n}{}xms; # strip "Generated by" line
diff_or_is( $script_output, $expected_c,
"'wikidoc -c' output file contents"
);