From 04605389d7ac89c32e4b2576d4894b4da94d3a24 Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Tue, 30 Apr 2013 15:38:24 -0400 Subject: [PATCH] tests: make a plan for man page checks Split the man page check routine into two routines; one to get the list of sub-commands for a command, and another to verify a man page exists for each sub-command. Use the list of sub-commands to set up the Test::More plan before running the tests. Setting the plan before running the tests allows the the man page tests to run on systems which ship older versions the Test::More module. Change-Id: I1ed6fb87989e1deff4696562f3b917140592ed17 Reviewed-on: http://gerrit.openafs.org/9835 Tested-by: BuildBot Reviewed-by: Ken Dreyer Reviewed-by: Derrick Brashear --- tests/bozo/bos-man-t | 9 +++--- tests/bucoord/backup-man-t | 9 +++--- tests/kauth/kas-man-t | 9 +++--- tests/ptserver/pts-man-t | 9 +++--- tests/tests-lib/perl5/mancheck_utils.pm | 44 +++++++++++++++++-------------- tests/venus/fs-man-t | 9 +++--- tests/volser/vos-man-t | 12 +++----- 7 files changed, 49 insertions(+), 52 deletions(-) diff --git a/tests/bozo/bos-man-t b/tests/bozo/bos-man-t index 73facd2..fedcf58 100755 --- a/tests/bozo/bos-man-t +++ b/tests/bozo/bos-man-t @@ -18,9 +18,8 @@ my $srcdir = "$builddir/src/bozo"; #--------------------------------------------------------------------- -# Keep track of number of tests we ran. We don't know up front. -my $testcount = 0; +my @sub_commands = lookup_sub_commands($srcdir, $command); +plan tests => scalar @sub_commands; + +test_command_man_pages($builddir, $command, @sub_commands); -check_command_binary("$srcdir/$command"); -my $count = test_command_man_pages($builddir, "$srcdir/$command"); -done_testing($count); diff --git a/tests/bucoord/backup-man-t b/tests/bucoord/backup-man-t index 714df26..d8df2c8 100755 --- a/tests/bucoord/backup-man-t +++ b/tests/bucoord/backup-man-t @@ -18,9 +18,8 @@ my $srcdir = "$builddir/src/bucoord"; #--------------------------------------------------------------------- -# Keep track of number of tests we ran. We don't know up front. -my $testcount = 0; +my @sub_commands = lookup_sub_commands($srcdir, $command); +plan tests => scalar @sub_commands; + +test_command_man_pages($builddir, $command, @sub_commands); -check_command_binary("$srcdir/$command"); -my $count = test_command_man_pages($builddir, "$srcdir/$command"); -done_testing($count); diff --git a/tests/kauth/kas-man-t b/tests/kauth/kas-man-t index e45b707..1629588 100755 --- a/tests/kauth/kas-man-t +++ b/tests/kauth/kas-man-t @@ -18,9 +18,8 @@ my $srcdir = "$builddir/src/kauth"; #--------------------------------------------------------------------- -# Keep track of number of tests we ran. We don't know up front. -my $testcount = 0; +my @sub_commands = lookup_sub_commands($srcdir, $command); +plan tests => scalar @sub_commands; + +test_command_man_pages($builddir, $command, @sub_commands); -check_command_binary("$srcdir/$command"); -my $count = test_command_man_pages($builddir, "$srcdir/$command"); -done_testing($count); diff --git a/tests/ptserver/pts-man-t b/tests/ptserver/pts-man-t index cac87e0..60645ea 100755 --- a/tests/ptserver/pts-man-t +++ b/tests/ptserver/pts-man-t @@ -18,9 +18,8 @@ my $srcdir = "$builddir/src/ptserver"; #--------------------------------------------------------------------- -# Keep track of number of tests we ran. We don't know up front. -my $testcount = 0; +my @sub_commands = lookup_sub_commands($srcdir, $command); +plan tests => scalar @sub_commands; + +test_command_man_pages($builddir, $command, @sub_commands); -check_command_binary("$srcdir/$command"); -my $count = test_command_man_pages($builddir, "$srcdir/$command"); -done_testing($count); diff --git a/tests/tests-lib/perl5/mancheck_utils.pm b/tests/tests-lib/perl5/mancheck_utils.pm index 834e603..6b56274 100644 --- a/tests/tests-lib/perl5/mancheck_utils.pm +++ b/tests/tests-lib/perl5/mancheck_utils.pm @@ -19,27 +19,14 @@ sub check_command_binary { } } -# TAP test: test_command_man_pages -# -# Gather a list of a command's subcommands (like listvol for vos) -# by running a command with the "help" argument. From that list -# of subcommands spit out, see if a man page exists for that -# command_subcommand -# -# Arguments: two scalars: -# -# builddir : A path to the OpenAFS build directory, -# such as /tmp/1.4.14 -# -# fullpathcommand : The full path to the actual command's -# binary, such as /tmp/1.4.14/src/volser/vos # -# Returns: the number of tests run +# Run the command help to determine the list of sub-commands. # -sub test_command_man_pages { - my ($builddir, $fullpathcommand) = @_; +sub lookup_sub_commands { + my ($srcdir, $command) = @_; - my $command = basename($fullpathcommand); + my $fullpathcommand = "$srcdir/$command"; + check_command_binary($fullpathcommand); # build up our list of available commands from the help output open(HELPOUT, "$fullpathcommand help 2>&1 |") or BAIL_OUT("can't fork: $!"); @@ -53,6 +40,25 @@ sub test_command_man_pages { } close HELPOUT; @subcommlist = sort(@subcommlist); + return @subcommlist; +} + +# TAP test: test_command_man_pages +# +# Test if a man page exists for each command sub-command. +# Runs one test per sub-command. +# +# Arguments: +# +# builddir : A path to the OpenAFS build directory, +# such as /tmp/1.4.14 +# +# command : the name of the command (e.g. vos) +# +# subcommlist : a list of sub-commands for command +# +sub test_command_man_pages { + my ($builddir, $command, @subcommlist) = @_; # The following is because File::Find makes no sense to me # for this purpose, and actually seems totally misnamed @@ -78,9 +84,7 @@ sub test_command_man_pages { last; } } - $testcount = $testcount + 1; ok($found eq 1, "existence of man page for $command" . "_$subcommand"); } - return $testcount; } 1; diff --git a/tests/venus/fs-man-t b/tests/venus/fs-man-t index 6e29fd3..3267b5d 100755 --- a/tests/venus/fs-man-t +++ b/tests/venus/fs-man-t @@ -18,9 +18,8 @@ my $srcdir = "$builddir/src/venus"; #--------------------------------------------------------------------- -# Keep track of number of tests we ran. We don't know up front. -my $testcount = 0; +my @sub_commands = lookup_sub_commands($srcdir, $command); +plan tests => scalar @sub_commands; + +test_command_man_pages($builddir, $command, @sub_commands); -check_command_binary("$srcdir/$command"); -my $count = test_command_man_pages($builddir, "$srcdir/$command"); -done_testing($count); diff --git a/tests/volser/vos-man-t b/tests/volser/vos-man-t index 4f7aad9..2e2cc35 100755 --- a/tests/volser/vos-man-t +++ b/tests/volser/vos-man-t @@ -3,6 +3,8 @@ use strict; use warnings; use File::Basename; +use lib "./tests-lib/perl5"; +use mancheck_utils; # Set this to the bare command to test my $command = 'vos'; @@ -16,12 +18,8 @@ my $srcdir = "$builddir/src/volser"; #--------------------------------------------------------------------- -# Keep track of number of tests we ran. We don't know up front. -my $testcount = 0; +my @sub_commands = lookup_sub_commands($srcdir, $command); +plan tests => scalar @sub_commands; -use lib "./tests-lib/perl5"; -use mancheck_utils; +test_command_man_pages($builddir, $command, @sub_commands); -check_command_binary("$srcdir/$command"); -my $count = test_command_man_pages($builddir, "$srcdir/$command"); -done_testing($count); -- 1.7.1