3 #=======================================================================
5 # File ID: 72d68c8c-f988-11dd-989d-000475e441b9
7 # Test suite for sumdup(1).
10 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
19 use Test
::More
qw{no_plan
};
28 our $CMD = "../$CMDB";
42 $progname =~ s/^.*\/(.*?)$/$1/;
43 our $VERSION = '0.0.0';
45 my %descriptions = ();
47 Getopt
::Long
::Configure
('bundling');
50 'all|a' => \
$Opt{'all'},
51 'help|h' => \
$Opt{'help'},
52 'quiet|q+' => \
$Opt{'quiet'},
53 'todo|t' => \
$Opt{'todo'},
54 'verbose|v+' => \
$Opt{'verbose'},
55 'version' => \
$Opt{'version'},
57 ) || die("$progname: Option error. Use -h for help.\n");
59 $Opt{'verbose'} -= $Opt{'quiet'};
60 $Opt{'help'} && usage
(0);
61 if ($Opt{'version'}) {
72 diag
(sprintf('========== Executing %s v%s ==========',
73 $progname, $VERSION));
75 if ($Opt{'todo'} && !$Opt{'all'}) {
81 testcmd("$CMD command", # {{{
94 diag
('Testing -h (--help) option...');
95 likecmd
("$CMD -h", # {{{
99 'Option -h prints help screen',
103 diag
('Testing -v (--verbose) option...');
104 likecmd
("$CMD -hv", # {{{
105 '/^\n\S+ \d+\.\d+\.\d+/s',
108 'Option -v with -h returns version number and help screen',
112 diag
('Testing --version option...');
113 likecmd
("$CMD --version", # {{{
114 '/^\S+ \d+\.\d+\.\d+/',
117 'Option --version returns version number',
121 diag
('Testing sorted input...');
122 testcmd
("sort sumdup-files/files.md5 | $CMD", # {{{
125 99754106633f94d350db34d548d6091a file2
126 99754106633f94d350db34d548d6091a file4
127 99754106633f94d350db34d548d6091a file5
129 ab4e78bf3b9d8b1aa18537c3f780245c file3
130 ab4e78bf3b9d8b1aa18537c3f780245c file6
134 'Finds duplicates in sorted output from sumdup-files/files.md5',
138 testcmd
("sort sumdup-files/files.sha1 | $CMD", # {{{
141 38d0f91a99c57d189416439ce377ccdcd92639d0 file2
142 38d0f91a99c57d189416439ce377ccdcd92639d0 file4
143 38d0f91a99c57d189416439ce377ccdcd92639d0 file5
144 38d0f91a99c57d189416439ce377ccdcd92639d0 file6
145 38d0f91a99c57d189416439ce377ccdcd92639d0 file7
147 ad2aeab58d53f21a7004250c49fa0a6bff59477d file0
148 ad2aeab58d53f21a7004250c49fa0a6bff59477d file3
150 f62e5bcda4fae4f82370da0c6f20697b8f8447ef file1
151 f62e5bcda4fae4f82370da0c6f20697b8f8447ef file8
152 f62e5bcda4fae4f82370da0c6f20697b8f8447ef file9
156 'Finds duplicates in sorted output from sumdup-files/files.sha1',
160 testcmd
("sort sumdup-files/files.sha256 | $CMD", # {{{
163 6ac3c336e4094835293a3fed8a4b5fedde1b5e2626d9838fed50693bba00af0e file2
164 6ac3c336e4094835293a3fed8a4b5fedde1b5e2626d9838fed50693bba00af0e file6
166 dfc7027894e168c3292c50b5461ef8ec635a5e04874b1e13b5ad7596a98f3bda file1
167 dfc7027894e168c3292c50b5461ef8ec635a5e04874b1e13b5ad7596a98f3bda file4
168 dfc7027894e168c3292c50b5461ef8ec635a5e04874b1e13b5ad7596a98f3bda file5
170 e2c4470a88f236a403c49d4be7c8f2f9e5e54f914e0d342ff24ee707ca85f070 file3
171 e2c4470a88f236a403c49d4be7c8f2f9e5e54f914e0d342ff24ee707ca85f070 file7
175 'Finds duplicates in sorted output from sumdup-files/files.sha256',
183 if ($Opt{'all'} || $Opt{'todo'}) {
184 diag
('Running TODO tests...'); # {{{
189 # Insert TODO tests here.
195 diag
('Testing finished.');
202 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
203 defined($descriptions{$Desc}) &&
204 BAIL_OUT
("testcmd(): '$Desc' description is used twice");
205 $descriptions{$Desc} = 1;
207 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
208 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
209 my $TMP_STDERR = "$CMDB-stderr.tmp";
212 if (defined($Exp_stderr)) {
213 $stderr_cmd = " 2>$TMP_STDERR";
215 $retval &= is
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
217 if (defined($Exp_stderr)) {
218 $retval &= is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
221 diag
("Warning: stderr not defined for '$Txt'");
223 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
231 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
232 defined($descriptions{$Desc}) &&
233 BAIL_OUT
("likecmd(): '$Desc' description is used twice");
234 $descriptions{$Desc} = 1;
236 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
237 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
238 my $TMP_STDERR = "$CMDB-stderr.tmp";
241 if (defined($Exp_stderr)) {
242 $stderr_cmd = " 2>$TMP_STDERR";
244 $retval &= like
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
246 if (defined($Exp_stderr)) {
247 $retval &= like
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
250 diag
("Warning: stderr not defined for '$Txt'");
252 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
259 # Return file content as a string {{{
263 open(my $fp, '<', $File) or return undef;
272 # Print program version {{{
273 print("$progname $VERSION\n");
279 # Send the help message to stdout {{{
282 if ($Opt{'verbose'}) {
288 Usage: $progname [options]
290 Contains tests for the $CMDB(1) program.
295 Run all tests, also TODOs.
299 Be more quiet. Can be repeated to increase silence.
301 Run only the TODO tests.
303 Increase level of verbosity. Can be repeated.
305 Print version information.
313 # Print a status message to stderr based on verbosity level {{{
314 my ($verbose_level, $Txt) = @_;
316 $verbose_level > $Opt{'verbose'} && return;
317 print(STDERR
"$progname: $Txt\n");
324 # This program is free software; you can redistribute it and/or modify
325 # it under the terms of the GNU General Public License as published by
326 # the Free Software Foundation; either version 2 of the License, or (at
327 # your option) any later version.
329 # This program is distributed in the hope that it will be useful, but
330 # WITHOUT ANY WARRANTY; without even the implied warranty of
331 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
332 # See the GNU General Public License for more details.
334 # You should have received a copy of the GNU General Public License
335 # along with this program.
336 # If not, see L<http://www.gnu.org/licenses/>.
338 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :