build/unix/test/uniq.tpl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/unix/test/uniq.tpl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,151 @@
     1.4 +#!/usr/bin/env perl
     1.5 +###########################################################################
     1.6 +## Intent: Unit test to verify uniq.pl
     1.7 +###########################################################################
     1.8 +
     1.9 +##----------------------------##
    1.10 +##---] CORE/CPAN INCLUDES [---##
    1.11 +##----------------------------##
    1.12 +use strict;
    1.13 +use warnings;
    1.14 +use Cwd;
    1.15 +use Getopt::Long;  # GetOptions
    1.16 +
    1.17 +use Test;
    1.18 +sub BEGIN { plan tests => 12 }
    1.19 +
    1.20 +##-------------------##
    1.21 +##---]  EXPORTS  [---##
    1.22 +##-------------------##
    1.23 +our $VERSION = qw(1.0);
    1.24 +
    1.25 +##------------------##
    1.26 +##---] INCLUDES [---##
    1.27 +##------------------##
    1.28 +use FindBin;
    1.29 +
    1.30 +##-------------------##
    1.31 +##---]  GLOBALS  [---##
    1.32 +##-------------------##
    1.33 +my %argv;
    1.34 +
    1.35 +
    1.36 +###########################################################################
    1.37 +## Intent: Run the arch command for output
    1.38 +##
    1.39 +## Returns:
    1.40 +##    0   on success
    1.41 +##    $?  command shell exit status
    1.42 +###########################################################################
    1.43 +sub uniq_pl
    1.44 +{
    1.45 +    my $cmd = "perl $FindBin::RealBin/../uniq.pl @_";
    1.46 +    print "Running: $cmd\n" if ($argv{debug});
    1.47 +    my @tmp = `$cmd 2>&1`;
    1.48 +    my @output = map{ split(/\s+/o); } @tmp;
    1.49 +    wantarray ? @output : "@output";
    1.50 +} # uniq_pl
    1.51 +
    1.52 +###########################################################################
    1.53 +## Intent:
    1.54 +##
    1.55 +## Returns:
    1.56 +##    0 on success
    1.57 +###########################################################################
    1.58 +sub check_uniq
    1.59 +{
    1.60 +    print STDERR "Running test: check_uniq\n" if ($argv{debug});
    1.61 +
    1.62 +    # TODO: improve test, uniq.pl regexpr handling not quite right
    1.63 +
    1.64 +    my @todo =
    1.65 +      (
    1.66 +       [ '', qw(a a/b a/b/c) ] => [  qw(a a/b a/b/c) ],
    1.67 +       [ '', qw(a/b a a/b/c) ] => [ qw(a/b a a/b/c) ],
    1.68 +       [ '', qw(a/b/c a/b a) ] => [ qw(a/b/c a/b a) ],
    1.69 +
    1.70 +       [ '', qw(a a/b a/b/c a/b a) ] => [  qw(a a/b a/b/c) ], # dup removal
    1.71 +
    1.72 +       [ '-s', qw(a a/b a/b/c) ] => [ qw(a a/b a/b/c)  ],
    1.73 +       [ '-s', qw(a/b a a/b/c) ] => [ qw(a a/b a/b/c) ],
    1.74 +       [ '-s', qw(a/b/c a/b a) ] => [ qw(a a/b a/b/c) ],
    1.75 +
    1.76 +       [ '-r', qw(a a/b a/b/c) ] => [ qw(a) ],
    1.77 +       [ '-r', qw(a/b a a/b/c) ] => [ qw(a/b a) ],
    1.78 +       [ '-r', qw(a/b/c a/b a) ] => [ qw(a/b/c a/b a) ],
    1.79 +
    1.80 +       [ '-r', qw(. .. a/b ../a aa/bb) ] => [ qw(. .. a/b aa/bb) ],
    1.81 +       [ '-r', qw(.. a/b ../a . aa/bb) ] => [ qw(.. a/b . aa/bb) ],
    1.82 +      );
    1.83 +
    1.84 +    my $ct=1;
    1.85 +    while (@todo)
    1.86 +    {
    1.87 +        my ($a, $b) = splice(@todo, 0, 2);
    1.88 +	my @args = @{ $a };
    1.89 +	my @exp = @{ $b };
    1.90 +
    1.91 +	my @out = uniq_pl(@args);
    1.92 +#	compareExp(\@out, \@exp, 'Failed on line ' . __LINE__ . ", dataset $ct");
    1.93 +	if (0 && 7 == $ct)
    1.94 +	  {
    1.95 +	    print STDERR "\n";
    1.96 +	    print STDERR map{ "args> $_\n" }@args;
    1.97 +	    print STDERR "\n";
    1.98 +	    print STDERR map{ "exp> $_\n" }@exp;
    1.99 +	    print STDERR "\n";
   1.100 +	    print STDERR map{ "out> $_\n" }@out;
   1.101 +	  }
   1.102 +
   1.103 +	ok("@out", "@exp", 'Failed on line ' . __LINE__ . ", dataset $ct");
   1.104 +	$ct++;
   1.105 +    }
   1.106 +
   1.107 +} # check_uniq
   1.108 +
   1.109 +###########################################################################
   1.110 +## Intent: Smoke tests for the unittests module
   1.111 +###########################################################################
   1.112 +sub smoke
   1.113 +{
   1.114 +    print STDERR "Running test: smoke()\n" if ($argv{debug});
   1.115 +} # smoke()
   1.116 +
   1.117 +###########################################################################
   1.118 +## Intent: Intitialize global test objects and consts
   1.119 +###########################################################################
   1.120 +sub init
   1.121 +{
   1.122 +    print "Running: init()\n" if ($argv{debug});
   1.123 +#    testplan(24, 0);
   1.124 +} # init()
   1.125 +
   1.126 +##----------------##
   1.127 +##---]  MAIN  [---##
   1.128 +##----------------##
   1.129 +unless(GetOptions(\%argv,
   1.130 +		  qw(
   1.131 +		     debug|d
   1.132 +                     manual
   1.133 +		     test=s@
   1.134 +		     verbose
   1.135 +		     )))
   1.136 +{
   1.137 +    print "USAGE: $0\n";
   1.138 +    print "  --debug    Enable script debug mode\n";
   1.139 +    print "  --fail     Force a testing failure condition\n";
   1.140 +    print "  --manual   Also run disabled tests\n";
   1.141 +    print "  --smoke    Run smoke tests then exit\n";
   1.142 +    print "  --test     Run a list of tests by function name\n";
   1.143 +    print "  --verbose  Enable script verbose mode\n";
   1.144 +    exit 1;
   1.145 +}
   1.146 +
   1.147 +init();
   1.148 +testbyname(@{ $argv{test} }) if ($argv{test});
   1.149 +smoke();
   1.150 +
   1.151 +check_uniq();
   1.152 +ok(1, 0, 'Forced failure by command line arg --fail') if ($argv{fail});
   1.153 +
   1.154 +# EOF

mercurial