michael@0: #!/usr/bin/env perl michael@0: ########################################################################### michael@0: ## Intent: Unit test to verify uniq.pl michael@0: ########################################################################### michael@0: michael@0: ##----------------------------## michael@0: ##---] CORE/CPAN INCLUDES [---## michael@0: ##----------------------------## michael@0: use strict; michael@0: use warnings; michael@0: use Cwd; michael@0: use Getopt::Long; # GetOptions michael@0: michael@0: use Test; michael@0: sub BEGIN { plan tests => 12 } michael@0: michael@0: ##-------------------## michael@0: ##---] EXPORTS [---## michael@0: ##-------------------## michael@0: our $VERSION = qw(1.0); michael@0: michael@0: ##------------------## michael@0: ##---] INCLUDES [---## michael@0: ##------------------## michael@0: use FindBin; michael@0: michael@0: ##-------------------## michael@0: ##---] GLOBALS [---## michael@0: ##-------------------## michael@0: my %argv; michael@0: michael@0: michael@0: ########################################################################### michael@0: ## Intent: Run the arch command for output michael@0: ## michael@0: ## Returns: michael@0: ## 0 on success michael@0: ## $? command shell exit status michael@0: ########################################################################### michael@0: sub uniq_pl michael@0: { michael@0: my $cmd = "perl $FindBin::RealBin/../uniq.pl @_"; michael@0: print "Running: $cmd\n" if ($argv{debug}); michael@0: my @tmp = `$cmd 2>&1`; michael@0: my @output = map{ split(/\s+/o); } @tmp; michael@0: wantarray ? @output : "@output"; michael@0: } # uniq_pl michael@0: michael@0: ########################################################################### michael@0: ## Intent: michael@0: ## michael@0: ## Returns: michael@0: ## 0 on success michael@0: ########################################################################### michael@0: sub check_uniq michael@0: { michael@0: print STDERR "Running test: check_uniq\n" if ($argv{debug}); michael@0: michael@0: # TODO: improve test, uniq.pl regexpr handling not quite right michael@0: michael@0: my @todo = michael@0: ( michael@0: [ '', qw(a a/b a/b/c) ] => [ qw(a a/b a/b/c) ], michael@0: [ '', qw(a/b a a/b/c) ] => [ qw(a/b a a/b/c) ], michael@0: [ '', qw(a/b/c a/b a) ] => [ qw(a/b/c a/b a) ], michael@0: michael@0: [ '', qw(a a/b a/b/c a/b a) ] => [ qw(a a/b a/b/c) ], # dup removal michael@0: michael@0: [ '-s', qw(a a/b a/b/c) ] => [ qw(a a/b a/b/c) ], michael@0: [ '-s', qw(a/b a a/b/c) ] => [ qw(a a/b a/b/c) ], michael@0: [ '-s', qw(a/b/c a/b a) ] => [ qw(a a/b a/b/c) ], michael@0: michael@0: [ '-r', qw(a a/b a/b/c) ] => [ qw(a) ], michael@0: [ '-r', qw(a/b a a/b/c) ] => [ qw(a/b a) ], michael@0: [ '-r', qw(a/b/c a/b a) ] => [ qw(a/b/c a/b a) ], michael@0: michael@0: [ '-r', qw(. .. a/b ../a aa/bb) ] => [ qw(. .. a/b aa/bb) ], michael@0: [ '-r', qw(.. a/b ../a . aa/bb) ] => [ qw(.. a/b . aa/bb) ], michael@0: ); michael@0: michael@0: my $ct=1; michael@0: while (@todo) michael@0: { michael@0: my ($a, $b) = splice(@todo, 0, 2); michael@0: my @args = @{ $a }; michael@0: my @exp = @{ $b }; michael@0: michael@0: my @out = uniq_pl(@args); michael@0: # compareExp(\@out, \@exp, 'Failed on line ' . __LINE__ . ", dataset $ct"); michael@0: if (0 && 7 == $ct) michael@0: { michael@0: print STDERR "\n"; michael@0: print STDERR map{ "args> $_\n" }@args; michael@0: print STDERR "\n"; michael@0: print STDERR map{ "exp> $_\n" }@exp; michael@0: print STDERR "\n"; michael@0: print STDERR map{ "out> $_\n" }@out; michael@0: } michael@0: michael@0: ok("@out", "@exp", 'Failed on line ' . __LINE__ . ", dataset $ct"); michael@0: $ct++; michael@0: } michael@0: michael@0: } # check_uniq michael@0: michael@0: ########################################################################### michael@0: ## Intent: Smoke tests for the unittests module michael@0: ########################################################################### michael@0: sub smoke michael@0: { michael@0: print STDERR "Running test: smoke()\n" if ($argv{debug}); michael@0: } # smoke() michael@0: michael@0: ########################################################################### michael@0: ## Intent: Intitialize global test objects and consts michael@0: ########################################################################### michael@0: sub init michael@0: { michael@0: print "Running: init()\n" if ($argv{debug}); michael@0: # testplan(24, 0); michael@0: } # init() michael@0: michael@0: ##----------------## michael@0: ##---] MAIN [---## michael@0: ##----------------## michael@0: unless(GetOptions(\%argv, michael@0: qw( michael@0: debug|d michael@0: manual michael@0: test=s@ michael@0: verbose michael@0: ))) michael@0: { michael@0: print "USAGE: $0\n"; michael@0: print " --debug Enable script debug mode\n"; michael@0: print " --fail Force a testing failure condition\n"; michael@0: print " --manual Also run disabled tests\n"; michael@0: print " --smoke Run smoke tests then exit\n"; michael@0: print " --test Run a list of tests by function name\n"; michael@0: print " --verbose Enable script verbose mode\n"; michael@0: exit 1; michael@0: } michael@0: michael@0: init(); michael@0: testbyname(@{ $argv{test} }) if ($argv{test}); michael@0: smoke(); michael@0: michael@0: check_uniq(); michael@0: ok(1, 0, 'Forced failure by command line arg --fail') if ($argv{fail}); michael@0: michael@0: # EOF