roundgpx-test: Legger elementene på hver sin linje og legger inn <ele>
[gpstools.git] / tests / roundgpx / roundgpx.t
blob17d1840f8a5f9042e2cdcad5c42ba89862b04bae
1 #!/usr/bin/perl
3 #=======================================================================
4 # roundgpx.t
5 # File ID: 88233274-7669-11e0-919c-574686701d8e
6 # Test suite for roundgpx(1).
8 # Character set: UTF-8
9 # ©opyleft 2011– Ø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 use strict;
15 use warnings;
17 BEGIN {
18 # push(@INC, "$ENV{'HOME'}/bin/STDlibdirDTS");
19 use Test::More qw{no_plan};
20 # use_ok() goes here
23 use Getopt::Long;
25 local $| = 1;
27 our $Debug = 0;
28 our $CMD = '../../roundgpx';
30 our %Opt = (
32 'all' => 0,
33 'debug' => 0,
34 'help' => 0,
35 'todo' => 0,
36 'verbose' => 0,
37 'version' => 0,
41 our $progname = $0;
42 $progname =~ s/^.*\/(.*?)$/$1/;
43 our $VERSION = '0.00';
45 Getopt::Long::Configure('bundling');
46 GetOptions(
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'}) {
60 print_version();
61 exit(0);
64 diag(sprintf('========== Executing %s v%s ==========',
65 $progname,
66 $VERSION));
68 if ($Opt{'todo'} && !$Opt{'all'}) {
69 goto todo_section;
72 =pod
74 testcmd("$CMD command", # {{{
75 <<'END',
76 [expected stdin]
77 END
78 '',
80 'description',
83 # }}}
85 =cut
87 diag('Testing -h (--help) option...');
88 likecmd("$CMD -h", # {{{
89 '/ Show this help\./',
90 '/^$/',
92 'Option -h prints help screen',
95 # }}}
96 diag('Testing -v (--verbose) option...');
97 likecmd("$CMD -hv", # {{{
98 '/^\n\S+ v\d\.\d\d\n/s',
99 '/^$/',
101 'Option --version with -h returns version number and help screen',
104 # }}}
105 diag('Testing --version option...');
106 likecmd("$CMD --version", # {{{
107 '/^\S+ v\d\.\d\d\n/',
108 '/^$/',
110 'Option --version returns version number',
113 # }}}
115 chomp(my $gpx_header = <<'END');
116 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
117 <gpx
118 version="1.1"
119 creator="gpst - http://sunny256.github.com/gpstools/"
120 xmlns="http://www.topografix.com/GPX/1/1"
121 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
122 xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
126 testcmd("$CMD files/rounding.gpx", # {{{
127 <<"END",
128 $gpx_header
129 <trk>
130 <trkseg>
131 <trkpt lat="51.483816" lon="0.000053">
132 <time>2003-02-11T12:17:05Z</time>
133 </trkpt>
134 <trkpt lat="51.483777" lon="-0.000021">
135 <ele>3</ele>
136 <time>2003-02-11T12:17:15Z</time>
137 </trkpt>
138 <trkpt lat="51.483754" lon="-0.000089">
139 <ele>0.002</ele>
140 <time>2003-02-11T12:17:21Z</time>
141 </trkpt>
142 <trkpt lat="51.483622" lon="0.000027">
143 <time>2003-02-11T12:27:41Z</time>
144 </trkpt>
145 </trkseg>
146 </trk>
147 </gpx>
151 'Round files/rounding.gpx',
154 # }}}
156 todo_section:
159 if ($Opt{'all'} || $Opt{'todo'}) {
160 diag('Running TODO tests...'); # {{{
162 TODO: {
164 local $TODO = '';
165 # Insert TODO tests here.
168 # TODO tests }}}
171 diag('Testing finished.');
173 sub testcmd {
174 # {{{
175 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
176 my $stderr_cmd = '';
177 my $deb_str = $Opt{'debug'} ? ' --debug' : '';
178 my $Txt = join('',
179 "\"$Cmd\"",
180 defined($Desc)
181 ? " - $Desc"
182 : ''
184 my $TMP_STDERR = 'roundgpx-stderr.tmp';
186 if (defined($Exp_stderr) && !length($deb_str)) {
187 $stderr_cmd = " 2>$TMP_STDERR";
189 is(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
190 my $ret_val = $?;
191 if (defined($Exp_stderr)) {
192 if (!length($deb_str)) {
193 is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
194 unlink($TMP_STDERR);
196 } else {
197 diag("Warning: stderr not defined for '$Txt'");
199 is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
200 return;
201 # }}}
202 } # testcmd()
204 sub likecmd {
205 # {{{
206 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
207 my $stderr_cmd = '';
208 my $deb_str = $Opt{'debug'} ? ' --debug' : '';
209 my $Txt = join('',
210 "\"$Cmd\"",
211 defined($Desc)
212 ? " - $Desc"
213 : ''
215 my $TMP_STDERR = 'roundgpx-stderr.tmp';
217 if (defined($Exp_stderr) && !length($deb_str)) {
218 $stderr_cmd = " 2>$TMP_STDERR";
220 like(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
221 my $ret_val = $?;
222 if (defined($Exp_stderr)) {
223 if (!length($deb_str)) {
224 like(file_data($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
225 unlink($TMP_STDERR);
227 } else {
228 diag("Warning: stderr not defined for '$Txt'");
230 is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
231 return;
232 # }}}
233 } # likecmd()
235 sub file_data {
236 # Return file content as a string {{{
237 my $File = shift;
238 my $Txt;
239 if (open(my $fp, '<', $File)) {
240 local $/ = undef;
241 $Txt = <$fp>;
242 close($fp);
243 return($Txt);
244 } else {
245 return;
247 # }}}
248 } # file_data()
250 sub print_version {
251 # Print program version {{{
252 print("$progname v$VERSION\n");
253 return;
254 # }}}
255 } # print_version()
257 sub usage {
258 # Send the help message to stdout {{{
259 my $Retval = shift;
261 if ($Opt{'verbose'}) {
262 print("\n");
263 print_version();
265 print(<<"END");
267 Usage: $progname [options] [file [files [...]]]
269 Contains tests for the roundgpx(1) program.
271 Options:
273 -a, --all
274 Run all tests, also TODOs.
275 -h, --help
276 Show this help.
277 -t, --todo
278 Run only the TODO tests.
279 -v, --verbose
280 Increase level of verbosity. Can be repeated.
281 --version
282 Print version information.
283 --debug
284 Print debugging messages.
287 exit($Retval);
288 # }}}
289 } # usage()
291 sub msg {
292 # Print a status message to stderr based on verbosity level {{{
293 my ($verbose_level, $Txt) = @_;
295 if ($Opt{'verbose'} >= $verbose_level) {
296 print(STDERR "$progname: $Txt\n");
298 return;
299 # }}}
300 } # msg()
302 __END__
304 # Plain Old Documentation (POD) {{{
306 =pod
308 =head1 NAME
310 run-tests.pl
312 =head1 SYNOPSIS
314 roundgpx.t [options] [file [files [...]]]
316 =head1 DESCRIPTION
318 Contains tests for the roundgpx(1) program.
320 =head1 OPTIONS
322 =over 4
324 =item B<-a>, B<--all>
326 Run all tests, also TODOs.
328 =item B<-h>, B<--help>
330 Print a brief help summary.
332 =item B<-t>, B<--todo>
334 Run only the TODO tests.
336 =item B<-v>, B<--verbose>
338 Increase level of verbosity. Can be repeated.
340 =item B<--version>
342 Print version information.
344 =item B<--debug>
346 Print debugging messages.
348 =back
350 =head1 AUTHOR
352 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
354 =head1 COPYRIGHT
356 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
357 This is free software; see the file F<COPYING> for legalese stuff.
359 =head1 LICENCE
361 This program is free software: you can redistribute it and/or modify it
362 under the terms of the GNU General Public License as published by the
363 Free Software Foundation, either version 3 of the License, or (at your
364 option) any later version.
366 This program is distributed in the hope that it will be useful, but
367 WITHOUT ANY WARRANTY; without even the implied warranty of
368 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
369 See the GNU General Public License for more details.
371 You should have received a copy of the GNU General Public License along
372 with this program.
373 If not, see L<http://www.gnu.org/licenses/>.
375 =head1 SEE ALSO
377 =cut
379 # }}}
381 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :