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 #=======================================================================
15 # push(@INC, "$ENV{'HOME'}/bin/STDlibdirDTS");
16 use Test
::More
qw{no_plan
};
26 our $CMD = "../../gpst-file";
40 $progname =~ s/^.*\/(.*?)$/$1/;
41 our $VERSION = "0.00";
43 Getopt
::Long
::Configure
("bundling");
46 "all|a" => \
$Opt{'all'},
47 "debug" => \
$Opt{'debug'},
48 "help|h" => \
$Opt{'help'},
49 "todo|t" => \
$Opt{'todo'},
50 "verbose|v+" => \
$Opt{'verbose'},
51 "version" => \
$Opt{'version'},
53 ) || die("$progname: Option error. Use -h for help.\n");
55 $Opt{'debug'} && ($Debug = 1);
56 $Opt{'help'} && usage
(0);
57 if ($Opt{'version'}) {
62 diag
(sprintf("========== Executing %s v%s ==========",
66 chdir("files") || die("$progname: files/: Cannot chdir: $!\n");
67 system("tar xzf testfile.tar.gz");
70 if ($Opt{'todo'} && !$Opt{'all'}) {
76 testcmd("$CMD command", # {{{
88 diag
("Testing --author option...");
89 testcmd
("$CMD -a sunny files/testfile/file.txt", # {{{
91 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\tsunny
94 "--author option works",
98 testcmd
("$CMD -a sunny -o xml files/testfile/file.txt", # {{{
100 <?xml version="1.0" encoding="UTF-8"?>
103 <filename>file.txt</filename>
104 <date>2009-02-23T21:58:01</date>
105 <author>sunny</author>
110 "Author info is included with -o xml",
114 # diag("Testing --debug option...");
115 diag
("Testing --description option...");
116 testcmd
("$CMD -d 'Description stuff \\&<>' files/testfile/file.txt", # {{{
118 1\t2009-02-23T21:58:01\t\\N\tDescription stuff \\\\&<>\tfile.txt\t\\N
121 "--description with backslash and stuff",
125 testcmd
("$CMD -o xml -d 'Description stuff \\&<>' files/testfile/file.txt", # {{{
127 <?xml version="1.0" encoding="UTF-8"?>
130 <filename>file.txt</filename>
131 <date>2009-02-23T21:58:01</date>
132 <desc>Description stuff \\&<></desc>
137 "--description with backslash and stuff",
141 diag
("Testing -h (--help) option...");
142 likecmd
("$CMD -h", # {{{
143 '/ Show this help\./',
145 "Option -h prints help screen",
149 diag
("Testing --output-format option..."); # {{{
151 testcmd
("$CMD -o pgtab files/testfile/file.txt", # {{{
153 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
156 "Output pgtab format from DSC_4426.JPG",
161 testcmd
("$CMD -o xml files/testfile/file.txt", # {{{
163 <?xml version="1.0" encoding="UTF-8"?>
166 <filename>file.txt</filename>
167 <date>2009-02-23T21:58:01</date>
172 "Output XML information for DSC_4426.JPG",
177 testcmd
("$CMD -o blurfl files/testfile/file.txt", # {{{
179 "gpst-file: blurfl: Unknown output format\n",
180 "Unknown output format specified",
184 # }}} --output-format
185 diag
("Testing -w (--strip-whitespace) option...");
186 testcmd
("$CMD -w -o xml files/testfile/file.txt", # {{{
188 <?xml version="1.0" encoding="UTF-8"?>
191 <filename>file.txt</filename>
192 <date>2009-02-23T21:58:01</date>
197 "Strip whitespace from XML",
201 diag
("Testing -T (--timezone) option...");
202 testcmd
("$CMD --timezone +1234 files/testfile/file.txt", # {{{
204 1\t2009-02-23T21:58:01+1234\t\\N\t\\N\tfile.txt\t\\N
211 testcmd
("$CMD -T +0200 files/testfile/file.txt", # {{{
213 1\t2009-02-23T21:58:01+0200\t\\N\t\\N\tfile.txt\t\\N
216 "Positive time zone",
220 testcmd
("$CMD -T-0600 files/testfile/file.txt", # {{{
222 1\t2009-02-23T21:58:01-0600\t\\N\t\\N\tfile.txt\t\\N
225 "Negative time zone",
229 testcmd
("$CMD -T CET files/testfile/file.txt", # {{{
231 1\t2009-02-23T21:58:01 CET\t\\N\t\\N\tfile.txt\t\\N
234 "Time zone abbreviation",
238 testcmd
("$CMD -T cet files/testfile/file.txt", # {{{
240 1\t2009-02-23T21:58:01 CET\t\\N\t\\N\tfile.txt\t\\N
243 "Time zone is converted to upper case",
247 testcmd
("$CMD -T Z files/testfile/file.txt", # {{{
249 1\t2009-02-23T21:58:01Z\t\\N\t\\N\tfile.txt\t\\N
256 testcmd
("$CMD -T erf324 files/testfile/file.txt", # {{{
258 "gpst-file: erf324: Invalid time zone\n",
259 "Invalid time zone abbr, contains digits",
263 testcmd
("$CMD -T CET -o xml files/testfile/file.txt", # {{{
265 <?xml version="1.0" encoding="UTF-8"?>
268 <filename>file.txt</filename>
269 <date>2009-02-23T21:58:01 CET</date>
274 "Time zone abbr. works with -o xml",
278 testcmd
("$CMD -T Z -o xml files/testfile/file.txt", # {{{
280 <?xml version="1.0" encoding="UTF-8"?>
283 <filename>file.txt</filename>
284 <date>2009-02-23T21:58:01Z</date>
289 "Zulu time zone works with -o xml",
293 diag
("Testing -v (--verbose) option...");
294 likecmd
("$CMD -hv", # {{{
295 '/^\n\S+ v\d\.\d\d\n/s',
297 "Option --version with -h returns version number and help screen",
301 diag
("Testing --version option...");
302 likecmd
("$CMD --version", # {{{
303 '/^\S+ v\d\.\d\d\n/',
305 "Option --version returns version number",
310 testcmd
("$CMD files/testfile/file.txt", # {{{
312 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
319 testcmd
("echo files/testfile/file.txt | $CMD", # {{{
321 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
324 "Read filename from stdin",
332 if ($Opt{'all'} || $Opt{'todo'}) {
333 diag
("Running TODO tests..."); # {{{
338 # Insert TODO tests here.
344 unlink("files/testfile/file.txt") || warn("$progname: files/testfile/file.txt: Cannot remove file: $!\n");
345 rmdir("files/testfile") || warn("$progname: files/testfile: Cannot remove directory: $!\n");
347 diag
("Testing finished.");
351 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
353 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
360 my $TMP_STDERR = "gpst-file-stderr.tmp";
362 if (defined($Exp_stderr) && !length($deb_str)) {
363 $stderr_cmd = " 2>$TMP_STDERR";
365 is
(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
366 if (defined($Exp_stderr)) {
367 if (!length($deb_str)) {
368 is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
372 diag
("Warning: stderr not defined for '$Txt'");
379 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
381 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
388 my $TMP_STDERR = "gpst-file-stderr.tmp";
390 if (defined($Exp_stderr) && !length($deb_str)) {
391 $stderr_cmd = " 2>$TMP_STDERR";
393 like
(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
394 if (defined($Exp_stderr)) {
395 if (!length($deb_str)) {
396 like
(file_data
($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
400 diag
("Warning: stderr not defined for '$Txt'");
406 # Return file content as a string {{{
409 if (open(FP
, "<", $File)) {
410 $Txt = join("", <FP
>);
420 # Print program version {{{
421 print("$progname v$VERSION\n");
426 # Send the help message to stdout {{{
429 if ($Opt{'verbose'}) {
435 Usage: $progname [options] [file [files [...]]]
437 Contains tests for the gpst-file(1) program.
442 Run all tests, also TODOs.
446 Run only the TODO tests.
448 Increase level of verbosity. Can be repeated.
450 Print version information.
452 Print debugging messages.
460 # Print a status message to stderr based on verbosity level {{{
461 my ($verbose_level, $Txt) = @_;
463 if ($Opt{'verbose'} >= $verbose_level) {
464 print(STDERR
"$progname: $Txt\n");
471 # Plain Old Documentation (POD) {{{
481 ./gpst-file.t [options] [file [files [...]]]
485 Contains tests for the gpst-file(1) program.
491 =item B<-a>, B<--all>
493 Run all tests, also TODOs.
495 =item B<-h>, B<--help>
497 Print a brief help summary.
499 =item B<-t>, B<--todo>
501 Run only the TODO tests.
503 =item B<-v>, B<--verbose>
505 Increase level of verbosity. Can be repeated.
509 Print version information.
513 Print debugging messages.
519 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
523 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
524 This is free software; see the file F<COPYING> for legalese stuff.
528 This program is free software: you can redistribute it and/or modify it
529 under the terms of the GNU General Public License as published by the
530 Free Software Foundation, either version 3 of the License, or (at your
531 option) any later version.
533 This program is distributed in the hope that it will be useful, but
534 WITHOUT ANY WARRANTY; without even the implied warranty of
535 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
536 See the GNU General Public License for more details.
538 You should have received a copy of the GNU General Public License along
540 If not, see L<http://www.gnu.org/licenses/>.
548 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :