3 #=======================================================================
4 # tests/gpst-file/gpst-file.t
5 # File ID: bbcbed10-009f-11de-824e-000475e441b9
6 # Test suite for gpst-file(1).
9 # ©opyleft 2009– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 3 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
17 # push(@INC, "$ENV{'HOME'}/bin/STDlibdirDTS");
18 use Test
::More
qw{no_plan
};
27 our $CMD = "../../gpst-file";
41 $progname =~ s/^.*\/(.*?)$/$1/;
42 our $VERSION = "0.00";
44 Getopt
::Long
::Configure
("bundling");
47 "all|a" => \
$Opt{'all'},
48 "debug" => \
$Opt{'debug'},
49 "help|h" => \
$Opt{'help'},
50 "todo|t" => \
$Opt{'todo'},
51 "verbose|v+" => \
$Opt{'verbose'},
52 "version" => \
$Opt{'version'},
54 ) || die("$progname: Option error. Use -h for help.\n");
56 $Opt{'debug'} && ($Debug = 1);
57 $Opt{'help'} && usage
(0);
58 if ($Opt{'version'}) {
63 diag
(sprintf("========== Executing %s v%s ==========",
67 chdir("files") || die("$progname: files/: Cannot chdir: $!\n");
68 system("tar xzf testfile.tar.gz");
71 if ($Opt{'todo'} && !$Opt{'all'}) {
77 testcmd("$CMD command", # {{{
89 diag
("Testing --author option...");
90 testcmd
("$CMD -a sunny files/testfile/file.txt", # {{{
92 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\tsunny
95 "--author option works",
99 testcmd
("$CMD -a sunny -o xml files/testfile/file.txt", # {{{
101 <?xml version="1.0" encoding="UTF-8"?>
104 <filename>file.txt</filename>
105 <date>2009-02-23T21:58:01</date>
106 <author>sunny</author>
111 "Author info is included with -o xml",
115 # diag("Testing --debug option...");
116 diag
("Testing --description option...");
117 testcmd
("$CMD -d 'Description stuff \\&<>' files/testfile/file.txt", # {{{
119 1\t2009-02-23T21:58:01\t\\N\tDescription stuff \\\\&<>\tfile.txt\t\\N
122 "--description with backslash and stuff",
126 testcmd
("$CMD -o xml -d 'Description stuff \\&<>' files/testfile/file.txt", # {{{
128 <?xml version="1.0" encoding="UTF-8"?>
131 <filename>file.txt</filename>
132 <date>2009-02-23T21:58:01</date>
133 <desc>Description stuff \\&<></desc>
138 "--description with backslash and stuff",
142 diag
("Testing -h (--help) option...");
143 likecmd
("$CMD -h", # {{{
144 '/ Show this help\./',
146 "Option -h prints help screen",
150 diag
("Testing --output-format option..."); # {{{
152 testcmd
("$CMD -o pgtab files/testfile/file.txt", # {{{
154 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
157 "Output pgtab format from DSC_4426.JPG",
162 testcmd
("$CMD -o xml files/testfile/file.txt", # {{{
164 <?xml version="1.0" encoding="UTF-8"?>
167 <filename>file.txt</filename>
168 <date>2009-02-23T21:58:01</date>
173 "Output XML information for DSC_4426.JPG",
178 testcmd
("$CMD -o blurfl files/testfile/file.txt", # {{{
180 "gpst-file: blurfl: Unknown output format\n",
181 "Unknown output format specified",
185 # }}} --output-format
186 diag
("Testing -w (--strip-whitespace) option...");
187 testcmd
("$CMD -w -o xml files/testfile/file.txt", # {{{
189 <?xml version="1.0" encoding="UTF-8"?>
192 <filename>file.txt</filename>
193 <date>2009-02-23T21:58:01</date>
198 "Strip whitespace from XML",
202 diag
("Testing -T (--timezone) option...");
203 testcmd
("$CMD --timezone +1234 files/testfile/file.txt", # {{{
205 1\t2009-02-23T21:58:01+1234\t\\N\t\\N\tfile.txt\t\\N
212 testcmd
("$CMD -T +0200 files/testfile/file.txt", # {{{
214 1\t2009-02-23T21:58:01+0200\t\\N\t\\N\tfile.txt\t\\N
217 "Positive time zone",
221 testcmd
("$CMD -T-0600 files/testfile/file.txt", # {{{
223 1\t2009-02-23T21:58:01-0600\t\\N\t\\N\tfile.txt\t\\N
226 "Negative time zone",
230 testcmd
("$CMD -T CET files/testfile/file.txt", # {{{
232 1\t2009-02-23T21:58:01 CET\t\\N\t\\N\tfile.txt\t\\N
235 "Time zone abbreviation",
239 testcmd
("$CMD -T cet files/testfile/file.txt", # {{{
241 1\t2009-02-23T21:58:01 CET\t\\N\t\\N\tfile.txt\t\\N
244 "Time zone is converted to upper case",
248 testcmd
("$CMD -T Z files/testfile/file.txt", # {{{
250 1\t2009-02-23T21:58:01Z\t\\N\t\\N\tfile.txt\t\\N
257 testcmd
("$CMD -T erf324 files/testfile/file.txt", # {{{
259 "gpst-file: erf324: Invalid time zone\n",
260 "Invalid time zone abbr, contains digits",
264 testcmd
("$CMD -T CET -o xml files/testfile/file.txt", # {{{
266 <?xml version="1.0" encoding="UTF-8"?>
269 <filename>file.txt</filename>
270 <date>2009-02-23T21:58:01 CET</date>
275 "Time zone abbr. works with -o xml",
279 testcmd
("$CMD -T Z -o xml files/testfile/file.txt", # {{{
281 <?xml version="1.0" encoding="UTF-8"?>
284 <filename>file.txt</filename>
285 <date>2009-02-23T21:58:01Z</date>
290 "Zulu time zone works with -o xml",
294 diag
("Testing -v (--verbose) option...");
295 likecmd
("$CMD -hv", # {{{
296 '/^\n\S+ v\d\.\d\d\n/s',
298 "Option --version with -h returns version number and help screen",
302 diag
("Testing --version option...");
303 likecmd
("$CMD --version", # {{{
304 '/^\S+ v\d\.\d\d\n/',
306 "Option --version returns version number",
311 testcmd
("$CMD files/testfile/file.txt", # {{{
313 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
320 testcmd
("echo files/testfile/file.txt | $CMD", # {{{
322 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
325 "Read filename from stdin",
333 if ($Opt{'all'} || $Opt{'todo'}) {
334 diag
("Running TODO tests..."); # {{{
339 # Insert TODO tests here.
345 unlink("files/testfile/file.txt") || warn("$progname: files/testfile/file.txt: Cannot remove file: $!\n");
346 rmdir("files/testfile") || warn("$progname: files/testfile: Cannot remove directory: $!\n");
348 diag
("Testing finished.");
352 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
354 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
361 my $TMP_STDERR = "gpst-file-stderr.tmp";
363 if (defined($Exp_stderr) && !length($deb_str)) {
364 $stderr_cmd = " 2>$TMP_STDERR";
366 is
(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
367 if (defined($Exp_stderr)) {
368 if (!length($deb_str)) {
369 is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
373 diag
("Warning: stderr not defined for '$Txt'");
380 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
382 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
389 my $TMP_STDERR = "gpst-file-stderr.tmp";
391 if (defined($Exp_stderr) && !length($deb_str)) {
392 $stderr_cmd = " 2>$TMP_STDERR";
394 like
(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
395 if (defined($Exp_stderr)) {
396 if (!length($deb_str)) {
397 like
(file_data
($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
401 diag
("Warning: stderr not defined for '$Txt'");
407 # Return file content as a string {{{
410 if (open(my $fp, "<", $File)) {
411 $Txt = join("", <$fp>);
421 # Print program version {{{
422 print("$progname v$VERSION\n");
427 # Send the help message to stdout {{{
430 if ($Opt{'verbose'}) {
436 Usage: $progname [options] [file [files [...]]]
438 Contains tests for the gpst-file(1) program.
443 Run all tests, also TODOs.
447 Run only the TODO tests.
449 Increase level of verbosity. Can be repeated.
451 Print version information.
453 Print debugging messages.
461 # Print a status message to stderr based on verbosity level {{{
462 my ($verbose_level, $Txt) = @_;
464 if ($Opt{'verbose'} >= $verbose_level) {
465 print(STDERR
"$progname: $Txt\n");
472 # Plain Old Documentation (POD) {{{
482 ./gpst-file.t [options] [file [files [...]]]
486 Contains tests for the gpst-file(1) program.
492 =item B<-a>, B<--all>
494 Run all tests, also TODOs.
496 =item B<-h>, B<--help>
498 Print a brief help summary.
500 =item B<-t>, B<--todo>
502 Run only the TODO tests.
504 =item B<-v>, B<--verbose>
506 Increase level of verbosity. Can be repeated.
510 Print version information.
514 Print debugging messages.
520 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
524 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
525 This is free software; see the file F<COPYING> for legalese stuff.
529 This program is free software: you can redistribute it and/or modify it
530 under the terms of the GNU General Public License as published by the
531 Free Software Foundation, either version 3 of the License, or (at your
532 option) any later version.
534 This program is distributed in the hope that it will be useful, but
535 WITHOUT ANY WARRANTY; without even the implied warranty of
536 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
537 See the GNU General Public License for more details.
539 You should have received a copy of the GNU General Public License along
541 If not, see L<http://www.gnu.org/licenses/>.
549 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :