3
# tests for xref-helpmsgs-manpages
12
use File::Path qw(make_path);
13
use File::Temp qw(tempdir);
20
require_ok "$FindBin::Bin/xref-helpmsgs-manpages";
23
my $workdir = tempdir(basename($0) . ".XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
25
# Copy man pages to tmpdir, so we can fiddle with them
28
"$LibPod::CI::XrefHelpmsgsManpages::Markdown_Path";
31
make_path "$workdir/$doc_path"
32
or die "Internal error: could not make_path $workdir/$doc_path";
33
system('rsync', '-a', "$doc_path/." => "$workdir/$doc_path/.") == 0
34
or die "Internal error: could not rsync $doc_path to $workdir";
37
or die "Internal error: could not cd $workdir: $!";
43
$msg =~ s/^xref-\S+?:\s+//; # strip "$ME: "
44
$msg =~ s!(^|\s+)$doc_path/!$1!g; # strip "doc/source/markdown"
45
$msg =~ s!:\d+:!:NNN:!; # file line numbers can change
46
push @warnings_seen, $msg;
49
# When we get errors (hopefully only when adding new functionality
50
# to this test!), this format is MUCH easier to read and copy-paste.
53
# Helper function for running xref tests.
58
my $expect_by_help = shift;
59
my $expect_by_man = shift;
62
LibPod::CI::XrefHelpmsgsManpages::xref_by_help($h, $m);
63
eq_or_diff_text \@warnings_seen, $expect_by_help, "$name: xref_by_help()";
66
LibPod::CI::XrefHelpmsgsManpages::xref_by_man($h, $m);
67
eq_or_diff_text \@warnings_seen, $expect_by_man, "$name: xref_by_man()";
70
###############################################################################
73
# Confirm that everything passes in the current tree
75
my $help = LibPod::CI::XrefHelpmsgsManpages::podman_help();
76
eq_or_diff_text \@warnings_seen, [], "podman_help() runs cleanly, no warnings";
79
my $man = LibPod::CI::XrefHelpmsgsManpages::podman_man('podman');
80
eq_or_diff_text \@warnings_seen, [], "podman_man() runs cleanly, no warnings";
82
# If this doesn't pass, we've got big problems.
83
test_xref("baseline", $help, $man, [], []);
85
#use Data::Dump; dd $man; exit 0;
88
##########################################################################
89
# BEGIN fault injection tests on xref_by_man()
91
# These are really simple: only two different warnings.
93
my $hclone = clone($help);
94
my $mclone = clone($man);
96
delete $hclone->{network}{ls}{"--format"};
97
delete $hclone->{save};
98
$mclone->{"command-in-man"} = {};
99
$mclone->{"system"}{"subcommand-in-man"} = {};
101
# --format field documented in man page but not in autocomplete
102
delete $hclone->{events}{"--format"}{".HealthStatus"};
104
test_xref("xref_by_man injection", $hclone, $mclone,
107
"'podman ': 'command-in-man' in podman.1.md, but not in --help",
108
"'podman events --format': '.HealthStatus' in podman-events.1.md, but not in command completion",
109
"'podman network ls': --format options documented in man page, but not available via autocomplete",
110
"'podman ': 'save' in podman.1.md, but not in --help",
111
"'podman system': 'subcommand-in-man' in podman-system.1.md, but not in --help",
115
# END fault injection tests on xref_by_man()
116
###############################################################################
117
# BEGIN fault injection tests on xref_by_help()
119
# These are much more complicated.
121
$hclone = clone($help);
122
$mclone = clone($man);
124
# --format is not documented in man page
125
delete $mclone->{"auto-update"}{"--format"};
126
# --format is documented, but without a table
127
$mclone->{container}{list}{"--format"} = 1;
128
# --format is documented, with a table, but entries are wrong
129
$mclone->{events}{"--format"}{".Attributes"} = 0;
130
$mclone->{events}{"--format"}{".Image"} = '...';
131
$mclone->{events}{"--format"}{".Status"} = 1;
132
$hclone->{events}{"--format"}{".Status"} = '...';
133
$mclone->{pod}{ps}{"--format"}{".Label"} = 3;
134
$mclone->{ps}{"--format"}{".Label"} = 0;
135
# --format is documented, with a table, but one entry missing
136
delete $mclone->{events}{"--format"}{".Type"};
138
# -l option is not documented
139
delete $mclone->{pod}{inspect}{"-l"};
141
# Command and subcommand in podman --help, but not in man pages
142
$hclone->{"new-command-in-help"} = {};
143
$hclone->{"secret"}{"subcommand-in-help"} = {};
145
# Can happen if podman-partlydocumented exists in --help, and is listed
146
# in podman.1.md, but does not have its own actual man page.
147
$hclone->{partlydocumented} = { "something" => 1 };
148
$mclone->{partlydocumented} = undef;
150
test_xref("xref_by_help() injection", $hclone, $mclone,
152
"'podman auto-update --help' lists '--format', which is not in podman-auto-update.1.md",
153
"'podman container list': --format options are available through autocomplete, but are not documented in podman-ps.1.md",
154
"'podman events --format {{.Attributes' is a nested structure. Please add '...' to man page.",
155
"'podman events --format {{.Image' is a simple value, not a nested structure. Please remove '...' from man page.",
156
"'podman events --format {{.Status' is a nested structure, but the man page documents it as a function?!?",
157
"'podman events --format <TAB>' lists '.Type', which is not in podman-events.1.md",
158
"'podman --help' lists 'new-command-in-help', which is not in podman.1.md",
159
"'podman partlydocumented' is not documented in man pages!",
160
"'podman pod inspect --help' lists '-l', which is not in podman-pod-inspect.1.md",
161
"'podman pod ps --format {{.Label' is a function that calls for 1 args; the man page lists 3. Please fix the man page.",
162
"'podman ps --format {{.Label' is a function that calls for 1 args. Please investigate what those are, then add them to the man page. E.g., '.Label *bool*' or '.Label *path* *bool*'",
163
"'podman secret --help' lists 'subcommand-in-help', which is not in podman-secret.1.md",
168
# END fault injection tests on xref_by_help()
169
###############################################################################
170
# BEGIN fault injection tests on podman_man()
172
# This function has a ton of sanity checks. To test them we need to
173
# perform minor surgery on lots of .md files: reordering lines,
174
# adding inconsistencies.
177
# Ordered list of the warnings we expect to see
180
# Helper function: given a filename and a function, reads filename
181
# line by line, invoking filter on each line and writing out the
184
my $path = shift; # in: filename (something.md)
185
my $action = shift; # in: filter function
187
# The rest of our arguments are the warnings introduced into this man page
188
push @expect_warnings, @_;
190
open my $fh_in, '<', "$doc_path/$path"
191
or die "Cannot read $doc_path/$path: $!";
192
my $tmpfile = "$doc_path/$path.tmp.$$";
193
open my $fh_out, '>', $tmpfile
194
or die "Cannot create $doc_path/$tmpfile: $!";
196
while (my $line = <$fh_in>) {
197
# This is what does all the magic
198
print { $fh_out } $action->($line);
202
or die "Error writing $doc_path/$tmpfile: $!";
203
rename "$tmpfile" => "$doc_path/$path"
204
or die "Could not rename $doc_path/$tmpfile: $!";
209
# podman-attach is a deliberate choice here: it also serves as the man page
210
# for podman-container-attach. Prior to 2023-12-20 we would read the file
211
# twice, issuing two warnings, which is anti-helpful. Here we confirm that
212
# the dup-removing code works.
213
sed('podman-attach.1.md', sub {
215
$line =~ s/^(%\s+podman)-(attach\s+1)/$1 $2/;
219
"podman-attach.1.md:NNN: wrong title line '% podman attach 1'; should be '% podman-attach 1'",
223
# Tests for broken command-line options
224
# IMPORTANT NOTE: podman-exec precedes podman-container (below),
225
# because podman-exec.1.md is actually read while podman-container.1.md
226
# is still processing; so these messages are printed earlier:
227
# podman-container.1.md -> list of subcommands -> exec -> read -exec.1.md
228
# Sorry for the confusion.
229
sed('podman-exec.1.md', sub {
232
if ($line =~ /^#### \*\*--env\*\*/) {
233
$line = $line . "\ndup dup dup\n\n" . $line;
235
elsif ($line =~ /^#### \*\*--privileged/) {
236
$line = "#### \*\*--put-me-back-in-order\*\*\n\nbogus option\n\n" . $line;
238
elsif ($line =~ /^#### \*\*--tty\*\*/) {
242
elsif ($line =~ /^#### \*\*--workdir\*\*/) {
244
#### **--workdir**=*dir*, **-w**
246
blah blah bogus description
248
#### **--yucca**=*cactus*|*starch*|*both*
252
#### **--zydeco**=*true* | *false*
260
"podman-exec.1.md:NNN: flag '--env' is a dup",
261
"podman-exec.1.md:NNN: --privileged should precede --put-me-back-in-order",
262
"podman-exec.1.md:NNN: could not parse ' xyz' in option description",
263
"podman-exec.1.md:NNN: please rewrite as ', **-w**=*dir*'",
264
"podman-exec.1.md:NNN: values must be space-separated: '=*cactus*|*starch*|*both*'",
265
"podman-exec.1.md:NNN: Do not enumerate true/false for boolean-only options",
269
# Tests for subcommands in a table
270
sed('podman-container.1.md', sub {
273
# "podman container diff": force an out-of-order error
275
if ($line =~ /^\|\s+diff\s+\|/) {
284
# "podman init": force a duplicate-command error
285
if ($line =~ /^\|\s+init\s+\|/) {
289
# "podman container port": force a wrong-man-page error
290
if ($line =~ /^\|\s+port\s+\|/) {
291
$line =~ s/-port\.1\.md/-top.1.md/;
297
"podman-container.1.md:NNN: 'exec' and 'diff' are out of order",
298
"podman-container.1.md:NNN: duplicate subcommand 'init'",
299
# FIXME: this is not technically correct; it could be the other way around.
300
"podman-container.1.md:NNN: 'podman-port' should be 'podman-top' in '[podman-port(1)](podman-top.1.md)'",
304
# Tests for --format specifiers in a table
305
sed('podman-image-inspect.1.md', sub {
309
if ($line =~ /^\|\s+\.Digest\s+\|/) {
318
if ($line =~ /^\|\s+\.ID\s+\|/) {
319
$line = $line . $line;
322
$line =~ s/^\|\s+\.Parent\s+\|/| .Parent BAD-ARG |/;
323
$line =~ s/^\|\s+\.Size\s+\|/| .Size *arg1* arg2 |/;
328
"podman-image-inspect.1.md:NNN: format specifier '.Digest' should precede '.GraphDriver'",
329
"podman-image-inspect.1.md:NNN: format specifier '.ID' is a dup",
330
"podman-image-inspect.1.md:NNN: unknown args 'BAD-ARG' for '.Parent'. Valid args are '...' for nested structs or, for functions, one or more asterisk-wrapped argument names.",
331
"podman-image-inspect.1.md:NNN: unknown args '*arg1* arg2' for '.Size'. Valid args are '...' for nested structs or, for functions, one or more asterisk-wrapped argument names.",
335
# Tests for SEE ALSO section
336
sed('podman-version.1.md', sub {
339
if ($line =~ /^## SEE ALSO/) {
340
$line .= "**foo**,**bar**"
343
. ", **[podman-info(1)](podman-cp.1.md)**"
344
. ", **[podman-foo(1)](podman-wait.1.md)**"
345
. ", **[podman-x](podman-bar.1.md)**"
346
. ", **podman-logs(1)**"
347
. ", **podman-image-rm(1)**"
355
"podman-version.1.md:NNN: please add space after comma: '**foo**,**bar**'",
356
"podman-version.1.md:NNN: invalid token 'baz**baz'",
357
"podman-version.1.md:NNN: 'missingstars' should be bracketed by '**'",
358
"podman-version.1.md:NNN: inconsistent link podman-info(1) -> podman-cp.1.md, expected podman-info.1.md",
359
"podman-version.1.md:NNN: invalid link podman-foo(1) -> podman-wait.1.md",
360
"podman-version.1.md:NNN: could not parse 'podman-x' as 'manpage(N)'",
361
"podman-version.1.md:NNN: 'podman-logs(1)' should be '[podman-logs(1)](podman-logs.1.md)'",
362
"podman-version.1.md:NNN: 'podman-image-rm(1)' refers to a command alias; please use the canonical command name instead",
363
"podman-version.1.md:NNN: invalid token 'sdfsdf'"
367
# Tests for --filter specifiers
368
sed('podman-volume-prune.1.md', sub {
371
if ($line =~ /^\|\s+driver\s+\|/) {
372
$line = "| name! | sdfsdf |\n" . $line;
374
if ($line =~ /^\|\s+opt\s+\|/) {
381
"podman-volume-prune.1.md:NNN: filter 'name!' only allowed immediately after its positive",
382
"podman-volume-prune.1.md:NNN: filter specifier 'opt' is a dup",
385
# DONE with fault injection. Reread man pages and verify warnings.
389
%LibPod::CI::XrefHelpmsgsManpages::Man_Seen = ();
391
$man = LibPod::CI::XrefHelpmsgsManpages::podman_man('podman');
392
eq_or_diff_text \@warnings_seen, \@expect_warnings, "podman_man() with faults";
394
# END fault injection tests on podman_man()
395
###############################################################################
396
# BEGIN fault injection tests on podman_help()
398
# Nope, this is not likely to happen. In order to do this we'd need to:
400
# * instrument podman and cobra to emit fake output; or
401
# * write a podman wrapper that selectively munges output; or
402
# * write a dummy podman that generates the right form of (broken) output.
404
# podman_help() has few sanity checks, and those are unlikely, so doing this
405
# is way more effort than it's worth.
407
# END fault injection tests on podman_help()
408
###############################################################################