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
|
#!/usr/bin/env perl
use strict;
use warnings;
=head1 NAME
20-TestScript-autodocs - test QtQA::TestScript module `usage' feature
=head1 SYNOPSIS
This autotest attempts to verify the automatic generation of script
documentation via print_usage, POD, --help.
It uses (.pl, .txt) pairs of files in the autodocs-data directory as
testdata. Each .pl file is invoked with `--help', and the generated
output is compared against the content of the .txt file.
=cut
use FindBin;
use lib "$FindBin::Bin/../..";
use Test::More;
use File::Basename qw( basename );
use IO::CaptureOutput qw( qxy );
use Text::Diff qw( diff );
#==============================================================================
sub test_script_against_expected
{
my ($script_filename, $usage_filename) = @_;
my $testname = basename($script_filename);
my ($combined, $success) = qxy('perl', $script_filename, '--help');
# using `--help' implies non-zero exit
ok( !$success, "$testname exited with non-zero exit code" );
my $diff = diff( $usage_filename, \$combined, {
STYLE => 'Unified',
FILENAME_A => $usage_filename,
FILENAME_B => "output of `$testname --help'",
});
ok( !$diff, "$testname output looks OK" )
|| diag("Output not as expected:\n$diff");
return;
}
sub run_test
{
foreach my $script_filename (glob "$FindBin::Bin/autodocs-data/*.pl") {
my $usage_filename = $script_filename;
$usage_filename =~ s{\.pl \z}{.txt}xms;
test_script_against_expected($script_filename, $usage_filename);
}
return;
}
#==============================================================================
if (!caller) {
run_test;
done_testing;
}
1;
|