Creating top-level Makefile.
[gpstools.git] / tests / csv2gpx.t
blob63081adf1bac9e1a30b89fea3d28223d819c9b07
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # csv2gpx.t
5 # File ID: d4031198-f987-11dd-9f3b-000475e441b9
6 # Test suite for csv2gpx(1).
8 # Character set: UTF-8
9 # ©opyleft 2008– Ø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 #=======================================================================
14 BEGIN {
15 # push(@INC, "$ENV{'HOME'}/bin/STDlibdirDTS");
16 use Test::More qw{no_plan};
17 # use_ok() goes here
20 use strict;
21 use Getopt::Long;
23 $| = 1;
25 our $Debug = 0;
26 our $CMD = "../csv2gpx";
28 our %Opt = (
30 'all' => 0,
31 'debug' => 0,
32 'help' => 0,
33 'todo' => 0,
34 'verbose' => 0,
35 'version' => 0,
39 our $progname = $0;
40 $progname =~ s/^.*\/(.*?)$/$1/;
41 our $VERSION = "0.00";
43 Getopt::Long::Configure("bundling");
44 GetOptions(
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'}) {
58 print_version();
59 exit(0);
62 diag(sprintf("========== Executing %s v%s ==========",
63 $progname,
64 $VERSION));
66 if ($Opt{'todo'} && !$Opt{'all'}) {
67 goto todo_section;
70 =pod
72 testcmd("$CMD command", # {{{
73 <<END,
74 [expected stdin]
75 END
76 "",
77 "description",
80 # }}}
82 =cut
84 diag("Testing -h (--help) option...");
85 likecmd("$CMD -h", # {{{
86 '/ Show this help\./',
87 '/^$/',
88 "Option -h prints help screen",
91 # }}}
92 ok(`$CMD -h` !~ /^\n\S+ v\d\.\d\d\n/s, "\"$CMD -h\" - No Id with only -h");
93 diag("Testing -v (--verbose) option...");
94 likecmd("$CMD -hv", # {{{
95 '/^\n\S+ v\d\.\d\d\n/s',
96 '/^$/',
97 "Option --version with -h returns version number and help screen",
100 # }}}
101 diag("Testing --version option...");
102 likecmd("$CMD --version", # {{{
103 '/^\S+ v\d\.\d\d\n/',
104 '/^$/',
105 "Option --version returns version number",
108 # }}}
110 todo_section:
113 if ($Opt{'all'} || $Opt{'todo'}) {
114 diag("Running TODO tests..."); # {{{
116 TODO: {
118 local $TODO = "";
119 # Insert TODO tests here.
122 # TODO tests }}}
125 diag("Testing finished.");
127 sub testcmd {
128 # {{{
129 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
130 my $stderr_cmd = "";
131 my $deb_str = $Opt{'debug'} ? " --debug" : "";
132 my $Txt = join("",
133 "\"$Cmd\"",
134 defined($Desc)
135 ? " - $Desc"
136 : ""
138 my $TMP_STDERR = "csv2gpx-stderr.tmp";
140 if (defined($Exp_stderr) && !length($deb_str)) {
141 $stderr_cmd = " 2>$TMP_STDERR";
143 is(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
144 if (defined($Exp_stderr)) {
145 if (!length($deb_str)) {
146 is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
147 unlink($TMP_STDERR);
149 } else {
150 diag("Warning: stderr not defined for '$Txt'");
152 # }}}
153 } # testcmd()
155 sub likecmd {
156 # {{{
157 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
158 my $stderr_cmd = "";
159 my $deb_str = $Opt{'debug'} ? " --debug" : "";
160 my $Txt = join("",
161 "\"$Cmd\"",
162 defined($Desc)
163 ? " - $Desc"
164 : ""
166 my $TMP_STDERR = "csv2gpx-stderr.tmp";
168 if (defined($Exp_stderr) && !length($deb_str)) {
169 $stderr_cmd = " 2>$TMP_STDERR";
171 like(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
172 if (defined($Exp_stderr)) {
173 if (!length($deb_str)) {
174 like(file_data($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
175 unlink($TMP_STDERR);
177 } else {
178 diag("Warning: stderr not defined for '$Txt'");
180 # }}}
181 } # likecmd()
183 sub file_data {
184 # Return file content as a string {{{
185 my $File = shift;
186 my $Txt;
187 if (open(FP, "<", $File)) {
188 $Txt = join("", <FP>);
189 close(FP);
190 return($Txt);
191 } else {
192 return undef;
194 # }}}
195 } # file_data()
197 sub print_version {
198 # Print program version {{{
199 print("$progname v$VERSION\n");
200 # }}}
201 } # print_version()
203 sub usage {
204 # Send the help message to stdout {{{
205 my $Retval = shift;
207 if ($Opt{'verbose'}) {
208 print("\n");
209 print_version();
211 print(<<END);
213 Usage: $progname [options] [file [files [...]]]
215 Contains tests for the csv2gpx(1) program.
217 Options:
219 -a, --all
220 Run all tests, also TODOs.
221 -h, --help
222 Show this help.
223 -t, --todo
224 Run only the TODO tests.
225 -v, --verbose
226 Increase level of verbosity. Can be repeated.
227 --version
228 Print version information.
229 --debug
230 Print debugging messages.
233 exit($Retval);
234 # }}}
235 } # usage()
237 sub msg {
238 # Print a status message to stderr based on verbosity level {{{
239 my ($verbose_level, $Txt) = @_;
241 if ($Opt{'verbose'} >= $verbose_level) {
242 print(STDERR "$progname: $Txt\n");
244 # }}}
245 } # msg()
247 __END__
249 # Plain Old Documentation (POD) {{{
251 =pod
253 =head1 NAME
255 run-tests.pl
257 =head1 SYNOPSIS
259 csv2gpx.t [options] [file [files [...]]]
261 =head1 DESCRIPTION
263 Contains tests for the csv2gpx(1) program.
265 =head1 OPTIONS
267 =over 4
269 =item B<-a>, B<--all>
271 Run all tests, also TODOs.
273 =item B<-h>, B<--help>
275 Print a brief help summary.
277 =item B<-t>, B<--todo>
279 Run only the TODO tests.
281 =item B<-v>, B<--verbose>
283 Increase level of verbosity. Can be repeated.
285 =item B<--version>
287 Print version information.
289 =item B<--debug>
291 Print debugging messages.
293 =back
295 =head1 AUTHOR
297 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
299 =head1 COPYRIGHT
301 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
302 This is free software; see the file F<COPYING> for legalese stuff.
304 =head1 LICENCE
306 This program is free software: you can redistribute it and/or modify it
307 under the terms of the GNU General Public License as published by the
308 Free Software Foundation, either version 3 of the License, or (at your
309 option) any later version.
311 This program is distributed in the hope that it will be useful, but
312 WITHOUT ANY WARRANTY; without even the implied warranty of
313 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
314 See the GNU General Public License for more details.
316 You should have received a copy of the GNU General Public License along
317 with this program.
318 If not, see L<http://www.gnu.org/licenses/>.
320 =head1 SEE ALSO
322 =cut
324 # }}}
326 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :