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 #=======================================================================
18 # push(@INC, "$ENV{'HOME'}/bin/STDlibdirDTS");
19 use Test
::More
qw{no_plan
};
28 our $CMD = "../../gpst-file";
42 $progname =~ s/^.*\/(.*?)$/$1/;
43 our $VERSION = "0.00";
45 Getopt
::Long
::Configure
("bundling");
48 "all|a" => \
$Opt{'all'},
49 "debug" => \
$Opt{'debug'},
50 "help|h" => \
$Opt{'help'},
51 "todo|t" => \
$Opt{'todo'},
52 "verbose|v+" => \
$Opt{'verbose'},
53 "version" => \
$Opt{'version'},
55 ) || die("$progname: Option error. Use -h for help.\n");
57 $Opt{'debug'} && ($Debug = 1);
58 $Opt{'help'} && usage
(0);
59 if ($Opt{'version'}) {
64 diag
(sprintf("========== Executing %s v%s ==========",
68 chdir("files") || die("$progname: files/: Cannot chdir: $!\n");
69 system("tar xzf testfile.tar.gz");
72 if ($Opt{'todo'} && !$Opt{'all'}) {
78 testcmd("$CMD command", # {{{
90 diag
("Testing --author option...");
91 testcmd
("$CMD -a sunny files/testfile/file.txt", # {{{
93 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\tsunny
96 "--author option works",
100 testcmd
("$CMD -a sunny -o xml files/testfile/file.txt", # {{{
102 <?xml version="1.0" encoding="UTF-8"?>
105 <filename>file.txt</filename>
106 <date>2009-02-23T21:58:01</date>
107 <author>sunny</author>
112 "Author info is included with -o xml",
116 # diag("Testing --debug option...");
117 diag
("Testing --description option...");
118 testcmd
("$CMD -d 'Description stuff \\&<>' files/testfile/file.txt", # {{{
120 1\t2009-02-23T21:58:01\t\\N\tDescription stuff \\\\&<>\tfile.txt\t\\N
123 "--description with backslash and stuff",
127 testcmd
("$CMD -o xml -d 'Description stuff \\&<>' files/testfile/file.txt", # {{{
129 <?xml version="1.0" encoding="UTF-8"?>
132 <filename>file.txt</filename>
133 <date>2009-02-23T21:58:01</date>
134 <desc>Description stuff \\&<></desc>
139 "--description with backslash and stuff",
143 diag
("Testing -h (--help) option...");
144 likecmd
("$CMD -h", # {{{
145 '/ Show this help\./',
147 "Option -h prints help screen",
151 diag
("Testing --output-format option..."); # {{{
153 testcmd
("$CMD -o pgtab files/testfile/file.txt", # {{{
155 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
158 "Output pgtab format from DSC_4426.JPG",
163 testcmd
("$CMD -o xml files/testfile/file.txt", # {{{
165 <?xml version="1.0" encoding="UTF-8"?>
168 <filename>file.txt</filename>
169 <date>2009-02-23T21:58:01</date>
174 "Output XML information for DSC_4426.JPG",
179 testcmd
("$CMD -o blurfl files/testfile/file.txt", # {{{
181 "gpst-file: blurfl: Unknown output format\n",
182 "Unknown output format specified",
186 # }}} --output-format
187 diag
("Testing -w (--strip-whitespace) option...");
188 testcmd
("$CMD -w -o xml files/testfile/file.txt", # {{{
190 <?xml version="1.0" encoding="UTF-8"?>
193 <filename>file.txt</filename>
194 <date>2009-02-23T21:58:01</date>
199 "Strip whitespace from XML",
203 diag
("Testing -T (--timezone) option...");
204 testcmd
("$CMD --timezone +1234 files/testfile/file.txt", # {{{
206 1\t2009-02-23T21:58:01+1234\t\\N\t\\N\tfile.txt\t\\N
213 testcmd
("$CMD -T +0200 files/testfile/file.txt", # {{{
215 1\t2009-02-23T21:58:01+0200\t\\N\t\\N\tfile.txt\t\\N
218 "Positive time zone",
222 testcmd
("$CMD -T-0600 files/testfile/file.txt", # {{{
224 1\t2009-02-23T21:58:01-0600\t\\N\t\\N\tfile.txt\t\\N
227 "Negative time zone",
231 testcmd
("$CMD -T CET files/testfile/file.txt", # {{{
233 1\t2009-02-23T21:58:01 CET\t\\N\t\\N\tfile.txt\t\\N
236 "Time zone abbreviation",
240 testcmd
("$CMD -T cet files/testfile/file.txt", # {{{
242 1\t2009-02-23T21:58:01 CET\t\\N\t\\N\tfile.txt\t\\N
245 "Time zone is converted to upper case",
249 testcmd
("$CMD -T Z files/testfile/file.txt", # {{{
251 1\t2009-02-23T21:58:01Z\t\\N\t\\N\tfile.txt\t\\N
258 testcmd
("$CMD -T erf324 files/testfile/file.txt", # {{{
260 "gpst-file: erf324: Invalid time zone\n",
261 "Invalid time zone abbr, contains digits",
265 testcmd
("$CMD -T CET -o xml files/testfile/file.txt", # {{{
267 <?xml version="1.0" encoding="UTF-8"?>
270 <filename>file.txt</filename>
271 <date>2009-02-23T21:58:01 CET</date>
276 "Time zone abbr. works with -o xml",
280 testcmd
("$CMD -T Z -o xml files/testfile/file.txt", # {{{
282 <?xml version="1.0" encoding="UTF-8"?>
285 <filename>file.txt</filename>
286 <date>2009-02-23T21:58:01Z</date>
291 "Zulu time zone works with -o xml",
295 diag
("Testing -v (--verbose) option...");
296 likecmd
("$CMD -hv", # {{{
297 '/^\n\S+ v\d\.\d\d\n/s',
299 "Option --version with -h returns version number and help screen",
303 diag
("Testing --version option...");
304 likecmd
("$CMD --version", # {{{
305 '/^\S+ v\d\.\d\d\n/',
307 "Option --version returns version number",
312 testcmd
("$CMD files/testfile/file.txt", # {{{
314 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
321 testcmd
("echo files/testfile/file.txt | $CMD", # {{{
323 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
326 "Read filename from stdin",
334 if ($Opt{'all'} || $Opt{'todo'}) {
335 diag
("Running TODO tests..."); # {{{
340 # Insert TODO tests here.
346 unlink("files/testfile/file.txt") || warn("$progname: files/testfile/file.txt: Cannot remove file: $!\n");
347 rmdir("files/testfile") || warn("$progname: files/testfile: Cannot remove directory: $!\n");
349 diag
("Testing finished.");
353 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
355 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
362 my $TMP_STDERR = "gpst-file-stderr.tmp";
364 if (defined($Exp_stderr) && !length($deb_str)) {
365 $stderr_cmd = " 2>$TMP_STDERR";
367 is
(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
368 if (defined($Exp_stderr)) {
369 if (!length($deb_str)) {
370 is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
374 diag
("Warning: stderr not defined for '$Txt'");
381 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
383 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
390 my $TMP_STDERR = "gpst-file-stderr.tmp";
392 if (defined($Exp_stderr) && !length($deb_str)) {
393 $stderr_cmd = " 2>$TMP_STDERR";
395 like
(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
396 if (defined($Exp_stderr)) {
397 if (!length($deb_str)) {
398 like
(file_data
($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
402 diag
("Warning: stderr not defined for '$Txt'");
408 # Return file content as a string {{{
411 if (open(my $fp, "<", $File)) {
412 $Txt = join("", <$fp>);
422 # Print program version {{{
423 print("$progname v$VERSION\n");
428 # Send the help message to stdout {{{
431 if ($Opt{'verbose'}) {
437 Usage: $progname [options] [file [files [...]]]
439 Contains tests for the gpst-file(1) program.
444 Run all tests, also TODOs.
448 Run only the TODO tests.
450 Increase level of verbosity. Can be repeated.
452 Print version information.
454 Print debugging messages.
462 # Print a status message to stderr based on verbosity level {{{
463 my ($verbose_level, $Txt) = @_;
465 if ($Opt{'verbose'} >= $verbose_level) {
466 print(STDERR
"$progname: $Txt\n");
473 # Plain Old Documentation (POD) {{{
483 ./gpst-file.t [options] [file [files [...]]]
487 Contains tests for the gpst-file(1) program.
493 =item B<-a>, B<--all>
495 Run all tests, also TODOs.
497 =item B<-h>, B<--help>
499 Print a brief help summary.
501 =item B<-t>, B<--todo>
503 Run only the TODO tests.
505 =item B<-v>, B<--verbose>
507 Increase level of verbosity. Can be repeated.
511 Print version information.
515 Print debugging messages.
521 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
525 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
526 This is free software; see the file F<COPYING> for legalese stuff.
530 This program is free software: you can redistribute it and/or modify it
531 under the terms of the GNU General Public License as published by the
532 Free Software Foundation, either version 3 of the License, or (at your
533 option) any later version.
535 This program is distributed in the hope that it will be useful, but
536 WITHOUT ANY WARRANTY; without even the implied warranty of
537 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
538 See the GNU General Public License for more details.
540 You should have received a copy of the GNU General Public License along
542 If not, see L<http://www.gnu.org/licenses/>.
550 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :