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 my $top = 'gpst-file-files';
69 chdir($top) || die("$progname: $top/: Cannot chdir: $!\n");
70 system("tar xzf testfile.tar.gz");
73 if ($Opt{'todo'} && !$Opt{'all'}) {
79 testcmd("$CMD command", # {{{
91 diag
("Testing --author option...");
92 testcmd
("$CMD -a sunny $top/testfile/file.txt", # {{{
94 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\tsunny
97 "--author option works",
101 testcmd
("$CMD -a sunny -o xml $top/testfile/file.txt", # {{{
103 <?xml version="1.0" encoding="UTF-8"?>
106 <filename>file.txt</filename>
107 <date>2009-02-23T21:58:01</date>
108 <author>sunny</author>
113 "Author info is included with -o xml",
117 # diag("Testing --debug option...");
118 diag
("Testing --description option...");
119 testcmd
("$CMD -d 'Description stuff \\&<>' $top/testfile/file.txt", # {{{
121 1\t2009-02-23T21:58:01\t\\N\tDescription stuff \\\\&<>\tfile.txt\t\\N
124 "--description with backslash and stuff",
128 testcmd
("$CMD -o xml -d 'Description stuff \\&<>' $top/testfile/file.txt", # {{{
130 <?xml version="1.0" encoding="UTF-8"?>
133 <filename>file.txt</filename>
134 <date>2009-02-23T21:58:01</date>
135 <desc>Description stuff \\&<></desc>
140 "--description with backslash and stuff",
144 diag
("Testing -h (--help) option...");
145 likecmd
("$CMD -h", # {{{
146 '/ Show this help\./',
148 "Option -h prints help screen",
152 diag
("Testing --output-format option..."); # {{{
154 testcmd
("$CMD -o pgtab $top/testfile/file.txt", # {{{
156 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
159 "Output pgtab format from DSC_4426.JPG",
164 testcmd
("$CMD -o xml $top/testfile/file.txt", # {{{
166 <?xml version="1.0" encoding="UTF-8"?>
169 <filename>file.txt</filename>
170 <date>2009-02-23T21:58:01</date>
175 "Output XML information for DSC_4426.JPG",
180 testcmd
("$CMD -o blurfl $top/testfile/file.txt", # {{{
182 "gpst-file: blurfl: Unknown output format\n",
183 "Unknown output format specified",
187 # }}} --output-format
188 diag
("Testing -w (--strip-whitespace) option...");
189 testcmd
("$CMD -w -o xml $top/testfile/file.txt", # {{{
191 <?xml version="1.0" encoding="UTF-8"?>
194 <filename>file.txt</filename>
195 <date>2009-02-23T21:58:01</date>
200 "Strip whitespace from XML",
204 diag
("Testing -T (--timezone) option...");
205 testcmd
("$CMD --timezone +1234 $top/testfile/file.txt", # {{{
207 1\t2009-02-23T21:58:01+1234\t\\N\t\\N\tfile.txt\t\\N
214 testcmd
("$CMD -T +0200 $top/testfile/file.txt", # {{{
216 1\t2009-02-23T21:58:01+0200\t\\N\t\\N\tfile.txt\t\\N
219 "Positive time zone",
223 testcmd
("$CMD -T-0600 $top/testfile/file.txt", # {{{
225 1\t2009-02-23T21:58:01-0600\t\\N\t\\N\tfile.txt\t\\N
228 "Negative time zone",
232 testcmd
("$CMD -T CET $top/testfile/file.txt", # {{{
234 1\t2009-02-23T21:58:01 CET\t\\N\t\\N\tfile.txt\t\\N
237 "Time zone abbreviation",
241 testcmd
("$CMD -T cet $top/testfile/file.txt", # {{{
243 1\t2009-02-23T21:58:01 CET\t\\N\t\\N\tfile.txt\t\\N
246 "Time zone is converted to upper case",
250 testcmd
("$CMD -T Z $top/testfile/file.txt", # {{{
252 1\t2009-02-23T21:58:01Z\t\\N\t\\N\tfile.txt\t\\N
259 testcmd
("$CMD -T erf324 $top/testfile/file.txt", # {{{
261 "gpst-file: erf324: Invalid time zone\n",
262 "Invalid time zone abbr, contains digits",
266 testcmd
("$CMD -T CET -o xml $top/testfile/file.txt", # {{{
268 <?xml version="1.0" encoding="UTF-8"?>
271 <filename>file.txt</filename>
272 <date>2009-02-23T21:58:01 CET</date>
277 "Time zone abbr. works with -o xml",
281 testcmd
("$CMD -T Z -o xml $top/testfile/file.txt", # {{{
283 <?xml version="1.0" encoding="UTF-8"?>
286 <filename>file.txt</filename>
287 <date>2009-02-23T21:58:01Z</date>
292 "Zulu time zone works with -o xml",
296 diag
("Testing -v (--verbose) option...");
297 likecmd
("$CMD -hv", # {{{
298 '/^\n\S+ v\d\.\d\d\n/s',
300 "Option --version with -h returns version number and help screen",
304 diag
("Testing --version option...");
305 likecmd
("$CMD --version", # {{{
306 '/^\S+ v\d\.\d\d\n/',
308 "Option --version returns version number",
313 testcmd
("$CMD $top/testfile/file.txt", # {{{
315 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
322 testcmd
("echo $top/testfile/file.txt | $CMD", # {{{
324 1\t2009-02-23T21:58:01\t\\N\t\\N\tfile.txt\t\\N
327 "Read filename from stdin",
335 if ($Opt{'all'} || $Opt{'todo'}) {
336 diag
("Running TODO tests..."); # {{{
341 # Insert TODO tests here.
347 unlink("$top/testfile/file.txt") || warn("$progname: $top/testfile/file.txt: Cannot remove file: $!\n");
348 rmdir("$top/testfile") || warn("$progname: $top/testfile: Cannot remove directory: $!\n");
350 diag
("Testing finished.");
354 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
356 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
363 my $TMP_STDERR = "gpst-file-stderr.tmp";
365 if (defined($Exp_stderr) && !length($deb_str)) {
366 $stderr_cmd = " 2>$TMP_STDERR";
368 is
(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
369 if (defined($Exp_stderr)) {
370 if (!length($deb_str)) {
371 is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
375 diag
("Warning: stderr not defined for '$Txt'");
382 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
384 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
391 my $TMP_STDERR = "gpst-file-stderr.tmp";
393 if (defined($Exp_stderr) && !length($deb_str)) {
394 $stderr_cmd = " 2>$TMP_STDERR";
396 like
(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
397 if (defined($Exp_stderr)) {
398 if (!length($deb_str)) {
399 like
(file_data
($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
403 diag
("Warning: stderr not defined for '$Txt'");
409 # Return file content as a string {{{
412 if (open(my $fp, "<", $File)) {
413 $Txt = join("", <$fp>);
423 # Print program version {{{
424 print("$progname v$VERSION\n");
429 # Send the help message to stdout {{{
432 if ($Opt{'verbose'}) {
438 Usage: $progname [options] [file [files [...]]]
440 Contains tests for the gpst-file(1) program.
445 Run all tests, also TODOs.
449 Run only the TODO tests.
451 Increase level of verbosity. Can be repeated.
453 Print version information.
455 Print debugging messages.
463 # Print a status message to stderr based on verbosity level {{{
464 my ($verbose_level, $Txt) = @_;
466 if ($Opt{'verbose'} >= $verbose_level) {
467 print(STDERR
"$progname: $Txt\n");
474 # Plain Old Documentation (POD) {{{
484 ./gpst-file.t [options] [file [files [...]]]
488 Contains tests for the gpst-file(1) program.
494 =item B<-a>, B<--all>
496 Run all tests, also TODOs.
498 =item B<-h>, B<--help>
500 Print a brief help summary.
502 =item B<-t>, B<--todo>
504 Run only the TODO tests.
506 =item B<-v>, B<--verbose>
508 Increase level of verbosity. Can be repeated.
512 Print version information.
516 Print debugging messages.
522 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
526 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
527 This is free software; see the file F<COPYING> for legalese stuff.
531 This program is free software: you can redistribute it and/or modify it
532 under the terms of the GNU General Public License as published by the
533 Free Software Foundation, either version 3 of the License, or (at your
534 option) any later version.
536 This program is distributed in the hope that it will be useful, but
537 WITHOUT ANY WARRANTY; without even the implied warranty of
538 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
539 See the GNU General Public License for more details.
541 You should have received a copy of the GNU General Public License along
543 If not, see L<http://www.gnu.org/licenses/>.
551 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :