Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
1 #!/usr/bin/env perl
2 ###########################################################################
3 ## Intent: Unit test to verify uniq.pl
4 ###########################################################################
6 ##----------------------------##
7 ##---] CORE/CPAN INCLUDES [---##
8 ##----------------------------##
9 use strict;
10 use warnings;
11 use Cwd;
12 use Getopt::Long; # GetOptions
14 use Test;
15 sub BEGIN { plan tests => 12 }
17 ##-------------------##
18 ##---] EXPORTS [---##
19 ##-------------------##
20 our $VERSION = qw(1.0);
22 ##------------------##
23 ##---] INCLUDES [---##
24 ##------------------##
25 use FindBin;
27 ##-------------------##
28 ##---] GLOBALS [---##
29 ##-------------------##
30 my %argv;
33 ###########################################################################
34 ## Intent: Run the arch command for output
35 ##
36 ## Returns:
37 ## 0 on success
38 ## $? command shell exit status
39 ###########################################################################
40 sub uniq_pl
41 {
42 my $cmd = "perl $FindBin::RealBin/../uniq.pl @_";
43 print "Running: $cmd\n" if ($argv{debug});
44 my @tmp = `$cmd 2>&1`;
45 my @output = map{ split(/\s+/o); } @tmp;
46 wantarray ? @output : "@output";
47 } # uniq_pl
49 ###########################################################################
50 ## Intent:
51 ##
52 ## Returns:
53 ## 0 on success
54 ###########################################################################
55 sub check_uniq
56 {
57 print STDERR "Running test: check_uniq\n" if ($argv{debug});
59 # TODO: improve test, uniq.pl regexpr handling not quite right
61 my @todo =
62 (
63 [ '', qw(a a/b a/b/c) ] => [ qw(a a/b a/b/c) ],
64 [ '', qw(a/b a a/b/c) ] => [ qw(a/b a a/b/c) ],
65 [ '', qw(a/b/c a/b a) ] => [ qw(a/b/c a/b a) ],
67 [ '', qw(a a/b a/b/c a/b a) ] => [ qw(a a/b a/b/c) ], # dup removal
69 [ '-s', qw(a a/b a/b/c) ] => [ qw(a a/b a/b/c) ],
70 [ '-s', qw(a/b a a/b/c) ] => [ qw(a a/b a/b/c) ],
71 [ '-s', qw(a/b/c a/b a) ] => [ qw(a a/b a/b/c) ],
73 [ '-r', qw(a a/b a/b/c) ] => [ qw(a) ],
74 [ '-r', qw(a/b a a/b/c) ] => [ qw(a/b a) ],
75 [ '-r', qw(a/b/c a/b a) ] => [ qw(a/b/c a/b a) ],
77 [ '-r', qw(. .. a/b ../a aa/bb) ] => [ qw(. .. a/b aa/bb) ],
78 [ '-r', qw(.. a/b ../a . aa/bb) ] => [ qw(.. a/b . aa/bb) ],
79 );
81 my $ct=1;
82 while (@todo)
83 {
84 my ($a, $b) = splice(@todo, 0, 2);
85 my @args = @{ $a };
86 my @exp = @{ $b };
88 my @out = uniq_pl(@args);
89 # compareExp(\@out, \@exp, 'Failed on line ' . __LINE__ . ", dataset $ct");
90 if (0 && 7 == $ct)
91 {
92 print STDERR "\n";
93 print STDERR map{ "args> $_\n" }@args;
94 print STDERR "\n";
95 print STDERR map{ "exp> $_\n" }@exp;
96 print STDERR "\n";
97 print STDERR map{ "out> $_\n" }@out;
98 }
100 ok("@out", "@exp", 'Failed on line ' . __LINE__ . ", dataset $ct");
101 $ct++;
102 }
104 } # check_uniq
106 ###########################################################################
107 ## Intent: Smoke tests for the unittests module
108 ###########################################################################
109 sub smoke
110 {
111 print STDERR "Running test: smoke()\n" if ($argv{debug});
112 } # smoke()
114 ###########################################################################
115 ## Intent: Intitialize global test objects and consts
116 ###########################################################################
117 sub init
118 {
119 print "Running: init()\n" if ($argv{debug});
120 # testplan(24, 0);
121 } # init()
123 ##----------------##
124 ##---] MAIN [---##
125 ##----------------##
126 unless(GetOptions(\%argv,
127 qw(
128 debug|d
129 manual
130 test=s@
131 verbose
132 )))
133 {
134 print "USAGE: $0\n";
135 print " --debug Enable script debug mode\n";
136 print " --fail Force a testing failure condition\n";
137 print " --manual Also run disabled tests\n";
138 print " --smoke Run smoke tests then exit\n";
139 print " --test Run a list of tests by function name\n";
140 print " --verbose Enable script verbose mode\n";
141 exit 1;
142 }
144 init();
145 testbyname(@{ $argv{test} }) if ($argv{test});
146 smoke();
148 check_uniq();
149 ok(1, 0, 'Forced failure by command line arg --fail') if ($argv{fail});
151 # EOF