3 #=======================================================================
5 # File ID: 9e63b5fe-f989-11dd-9357-000475e441b9
7 # Test suite for sident(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 without options...");
122 testcmd
("$CMD sident-files/textfile", # {{{
125 sident-files/textfile:
126 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
127 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
128 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
129 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
130 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
131 $Date: 1999/12/23 21:59:22 $
132 $Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
133 $Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
138 "Read textfile, no arguments",
142 testcmd
("$CMD sident-files/random", # {{{
146 $Id: randomstuff 314159 1969-01-21 17:12:16Z sunny $
150 "Read random binary data, no arguments",
154 diag
("Testing stdin...");
155 testcmd
("$CMD - <sident-files/random", # {{{
159 $Id: randomstuff 314159 1969-01-21 17:12:16Z sunny $
163 "Read random binary data from stdin with hyphen as filename",
167 testcmd
("cat sident-files/random | $CMD -", # {{{
171 $Id: randomstuff 314159 1969-01-21 17:12:16Z sunny $
175 "Read random binary through pipe, hyphen filename",
179 diag
("Testing -e (--expanded-only) option...");
180 testcmd
("$CMD -e sident-files/unexpanded sident-files/textfile", # {{{
183 sident-files/textfile:
184 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
185 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
186 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
187 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
188 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
189 $Date: 1999/12/23 21:59:22 $
190 $Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
191 $Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
196 "List only expanded keywords",
200 testcmd
("$CMD -ev sident-files/unexpanded sident-files/textfile", # {{{
203 sident-files/unexpanded:
205 sident-files/textfile:
206 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
207 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
208 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
209 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
210 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
211 $Date: 1999/12/23 21:59:22 $
212 $Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
213 $Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
218 "List only expanded keywords, plus list filename without expanded kw",
222 diag
("Testing -f (--filenames-from) option...");
223 testcmd
("$CMD -f sident-files/filenames", # {{{
227 $Id: randomstuff 314159 1969-01-21 17:12:16Z sunny $
229 sident-files/textfile:
230 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
231 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
232 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
233 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
234 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
235 $Date: 1999/12/23 21:59:22 $
236 $Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
237 $Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
240 sident-files/unexpanded:
248 $LastChangedRevision$
254 "Read filenames from file",
258 diag
("Testing -k (--known-keywords-only) option...");
259 testcmd
("$CMD -k sident-files/textfile", # {{{
262 sident-files/textfile:
263 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
264 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
265 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
266 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
267 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
268 $Date: 1999/12/23 21:59:22 $
269 $Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
270 $Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
274 "List only known keywords",
278 diag
("Testing -l (--filenames-only) option...");
279 testcmd
("$CMD -le sident-files/*", # {{{
282 sident-files/textfile
286 "Only list names of files with expanded keywords",
290 diag
("Testing -u (--unique-keywords) option...");
291 testcmd
("$CMD -u sident-files/textfile", # {{{
294 sident-files/textfile:
295 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
296 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
297 $Date: 1999/12/23 21:59:22 $
298 $Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
299 $Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
304 "Remove duplicates from textfile",
308 testcmd
("$CMD -v sident-files/*", # {{{
311 sident-files/filenames:
313 sident-files/nothing_here:
316 $Id: randomstuff 314159 1969-01-21 17:12:16Z sunny $
318 sident-files/textfile:
319 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
320 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
321 $Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $
322 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
323 $Id: yeh 1234 2008-09-22 12:25:05Z sunny $
324 $Date: 1999/12/23 21:59:22 $
325 $Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
326 $Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $
329 sident-files/unexpanded:
337 $LastChangedRevision$
343 "Also list files without keywords",
347 testcmd
("$CMD -vx sident-files/*", # {{{
349 <?xml version="1.0"?>
352 <filename>sident-files/filenames</filename>
355 <filename>sident-files/nothing_here</filename>
358 <filename>sident-files/random</filename>
360 <keyword>$Id: randomstuff 314159 1969-01-21 17:12:16Z sunny $</keyword>
364 <filename>sident-files/textfile</filename>
366 <keyword>$Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $</keyword>
367 <keyword>$Id: yeh 1234 2008-09-22 12:25:05Z sunny $</keyword>
368 <keyword>$Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $</keyword>
369 <keyword>$Id: yeh 1234 2008-09-22 12:25:05Z sunny $</keyword>
370 <keyword>$Id: yeh 1234 2008-09-22 12:25:05Z sunny $</keyword>
371 <keyword>$Date: 1999/12/23 21:59:22 $</keyword>
372 <keyword>$Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $</keyword>
373 <keyword>$Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $</keyword>
374 <keyword>$Weirdo: blah blah $</keyword>
378 <filename>sident-files/unexpanded</filename>
380 <keyword>$URL$</keyword>
381 <keyword>$HeadURL$</keyword>
382 <keyword>$LastChangedBy$</keyword>
383 <keyword>$Date$</keyword>
384 <keyword>$LastChangedDate$</keyword>
385 <keyword>$Rev$</keyword>
386 <keyword>$Revision$</keyword>
387 <keyword>$LastChangedRevision$</keyword>
388 <keyword>$Id$</keyword>
389 <keyword>$RealLyuNKoWN$</keyword>
396 "Output XML, including files without keywords",
400 diag
("Testing -x (--xml) option...");
401 testcmd
("$CMD -x sident-files/textfile", # {{{
403 <?xml version="1.0"?>
406 <filename>sident-files/textfile</filename>
408 <keyword>$Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $</keyword>
409 <keyword>$Id: yeh 1234 2008-09-22 12:25:05Z sunny $</keyword>
410 <keyword>$Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $</keyword>
411 <keyword>$Id: yeh 1234 2008-09-22 12:25:05Z sunny $</keyword>
412 <keyword>$Id: yeh 1234 2008-09-22 12:25:05Z sunny $</keyword>
413 <keyword>$Date: 1999/12/23 21:59:22 $</keyword>
414 <keyword>$Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $</keyword>
415 <keyword>$Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $</keyword>
416 <keyword>$Weirdo: blah blah $</keyword>
423 "Output XML from textfile",
427 testcmd
("$CMD -ux sident-files/textfile", # {{{
429 <?xml version="1.0"?>
432 <filename>sident-files/textfile</filename>
434 <keyword>$Id: plain_old_textfile 93653 2008-09-22 14:15:10Z sunny $</keyword>
435 <keyword>$Id: yeh 1234 2008-09-22 12:25:05Z sunny $</keyword>
436 <keyword>$Date: 1999/12/23 21:59:22 $</keyword>
437 <keyword>$Header: /cvsweb/cvs-guide/keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $</keyword>
438 <keyword>$Id: keyword.html,v 1.3 1999/12/23 21:59:22 markd Exp $</keyword>
439 <keyword>$Weirdo: blah blah $</keyword>
446 "Output XML, remove duplicates",
450 diag
("Error conditions...");
451 testcmd
("$CMD sident-files", # {{{
455 "Ignore directories",
459 testcmd
("$CMD -v sident-files", # {{{
463 "Ignore directories, even with --verbose",
467 likecmd
("$CMD sident-files/shbvkdsvsdfv", # {{{
469 '/^sident: sident-files/shbvkdsvsdfv: .*$/',
475 likecmd
("$CMD -x sident-files/shbvkdsvsdfv", # {{{
476 '/^<\?xml version="1\.0"\?>\n<sident>\n<\/sident>$/',
477 '/^sident: sident-files/shbvkdsvsdfv: .*$/',
479 "File not found, don’t break the XML",
483 diag
("Validate POD (Plain Old Documentation)");
484 testcmd
("podchecker $CMD", # {{{
486 "$CMD pod syntax OK.\n",
488 "$CMD contains valid POD",
496 if ($Opt{'all'} || $Opt{'todo'}) {
497 diag
('Running TODO tests...'); # {{{
502 # Insert TODO tests here.
508 diag
('Testing finished.');
515 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
516 defined($descriptions{$Desc}) &&
517 BAIL_OUT
("testcmd(): '$Desc' description is used twice");
518 $descriptions{$Desc} = 1;
520 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
521 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
522 my $TMP_STDERR = "$CMDB-stderr.tmp";
525 if (defined($Exp_stderr)) {
526 $stderr_cmd = " 2>$TMP_STDERR";
528 $retval &= is
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
530 if (defined($Exp_stderr)) {
531 $retval &= is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
534 diag
("Warning: stderr not defined for '$Txt'");
536 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
544 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
545 defined($descriptions{$Desc}) &&
546 BAIL_OUT
("likecmd(): '$Desc' description is used twice");
547 $descriptions{$Desc} = 1;
549 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
550 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
551 my $TMP_STDERR = "$CMDB-stderr.tmp";
554 if (defined($Exp_stderr)) {
555 $stderr_cmd = " 2>$TMP_STDERR";
557 $retval &= like
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
559 if (defined($Exp_stderr)) {
560 $retval &= like
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
563 diag
("Warning: stderr not defined for '$Txt'");
565 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
572 # Return file content as a string {{{
576 open(my $fp, '<', $File) or return undef;
585 # Print program version {{{
586 print("$progname $VERSION\n");
592 # Send the help message to stdout {{{
595 if ($Opt{'verbose'}) {
601 Usage: $progname [options]
603 Contains tests for the $CMDB(1) program.
608 Run all tests, also TODOs.
612 Be more quiet. Can be repeated to increase silence.
614 Run only the TODO tests.
616 Increase level of verbosity. Can be repeated.
618 Print version information.
626 # Print a status message to stderr based on verbosity level {{{
627 my ($verbose_level, $Txt) = @_;
629 $verbose_level > $Opt{'verbose'} && return;
630 print(STDERR
"$progname: $Txt\n");
637 # This program is free software; you can redistribute it and/or modify
638 # it under the terms of the GNU General Public License as published by
639 # the Free Software Foundation; either version 2 of the License, or (at
640 # your option) any later version.
642 # This program is distributed in the hope that it will be useful, but
643 # WITHOUT ANY WARRANTY; without even the implied warranty of
644 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
645 # See the GNU General Public License for more details.
647 # You should have received a copy of the GNU General Public License
648 # along with this program.
649 # If not, see L<http://www.gnu.org/licenses/>.
651 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :