Commits

Palmer, 2E0EOL committed 486d65b Draft

Allow unit testing one data set at a time -n <num>

Comments (0)

Files changed (2)

bin/check_disks_zpool

 	return $status;
 }
 
-exit(3) if ( !getopts('df:', \%opts) );
-exit(main(%opts)) if ( !caller() );
+sub _entrypoint {
+	exit(3) if ( !getopts('df:', \%opts) );
+	exit(main(%opts));
+}
+
+_entrypoint unless caller();
 1;

t/check_disks_zpool.t

 #
 
 package main;
+use Getopt::Std;
+
 use strict;
 use warnings;
 use diagnostics;
 
 require 'bin/check_disks_zpool';
 
-use Test::More tests => 10;
+use Test::More;
 
 sub t_main()
 {
+	my $test_count;
+	my %opts;
 	my %fn_ec_map = (
 		'degraded' => 2,
 		'rebuild'  => 1,
 	);
 
 	my $testdir = 'testdata/check_disks_zpool';
+	return 1 if ( !getopts('t:', \%opts) );
+	return 1 if ( $opts{'t'} && $opts{'t'} !~ m/^\d+/ );
+	$test_count = ( $opts{'t'} ) ? ( 1 ) : ( 10 );
+	plan tests => $test_count;
+
 	if ( opendir(my $d, $testdir) ) {
 		my ( %dentries, %dentries_codes );
 		while ( my $ent = readdir($d) ) {
 			my $filename = "$testdir/$ent";
 			next if ( $ent =~ m/^\./ );
 			if ( $ent =~ m/^(\d{1,2})\_(\w+)\.txt$/ ) {
+				next if ( $opts{'t'} && $opts{'t'} != $1 );
 				$dentries{$1} = $ent;
 				$dentries_codes{$1} = $fn_ec_map{$2};
 				next;
 			my $ent = $dentries{$testn};
 			my $filename = "$testdir/$ent";
 			my $expect_exit = $dentries_codes{$testn};
+
 			if ( !defined($expect_exit) ) {
 				warn "Not running unit test (unknown filename): $ent";
 				next;