gpsfold: Remove $Id$ at EOF.
[gpstools.git] / branches / gpst.gpxfix / tests / addpoints / addpoints.t
blob9d7fe94c3f14d495ddc0f7df2603115ab6480964
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
5 # File ID: ccab1138-f924-11dd-9694-0001805bf4b1
6 # Test suite for addpoints(1).
8 # Character set: UTF-8
9 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 BEGIN {
15 # push(@INC, "$ENV{'HOME'}/bin/STDlibdirDTS");
16 our @version_array;
17 use Test::More qw{no_plan};
18 # use_ok() goes here
21 use strict;
22 use Getopt::Long;
24 $| = 1;
26 our $Debug = 0;
27 our $CMD = "../../addpoints";
29 our %Opt = (
31 'all' => 0,
32 'debug' => 0,
33 'help' => 0,
34 'todo' => 0,
35 'verbose' => 0,
36 'version' => 0,
40 our $progname = $0;
41 $progname =~ s/^.*\/(.*?)$/$1/;
43 my $rcs_id = '$Id$';
44 my $id_date = $rcs_id;
45 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
47 push(@main::version_array, $rcs_id);
49 my @cmdline_array = @ARGV;
51 Getopt::Long::Configure("bundling");
52 GetOptions(
54 "all|a" => \$Opt{'all'},
55 "debug" => \$Opt{'debug'},
56 "help|h" => \$Opt{'help'},
57 "todo|t" => \$Opt{'todo'},
58 "verbose|v+" => \$Opt{'verbose'},
59 "version" => \$Opt{'version'},
61 ) || die("$progname: Option error. Use -h for help.\n");
63 $Opt{'debug'} && ($Debug = 1);
64 $Opt{'help'} && usage(0);
65 if ($Opt{'version'}) {
66 print_version();
67 exit(0);
70 diag(sprintf("========== Executing \"%s%s%s\" ==========",
71 $progname,
72 scalar(@cmdline_array) ? " " : "",
73 join(" ", @cmdline_array)));
75 if ($Opt{'todo'} && !$Opt{'all'}) {
76 goto todo_section;
79 =pod
81 testcmd("$CMD command", # {{{
82 <<END,
83 [expected stdin]
84 END
85 "",
86 "description",
89 # }}}
91 =cut
93 diag("Testing -h (--help) option...");
94 likecmd("$CMD -h", # {{{
95 '/ Show this help\./',
96 '/^$/',
97 "Option -h prints help screen",
100 # }}}
101 ok(`$CMD -h` !~ /\$Id: /s, "\"$CMD -h\" - No Id with only -h");
102 diag("Testing -v (--verbose) option...");
103 likecmd("$CMD -hv", # {{{
104 '/\$Id: .*? \$.* Show this help\./s',
105 '/^$/',
106 "Option --version with -h returns Id string and help screen",
109 # }}}
110 diag("Testing --version option...");
111 likecmd("$CMD --version", # {{{
112 '/\$Id: .*? \$/',
113 '/^$/',
114 "Option --version returns Id string",
117 # }}}
119 todo_section:
122 if ($Opt{'all'} || $Opt{'todo'}) {
123 diag("Running TODO tests..."); # {{{
125 TODO: {
127 local $TODO = "";
128 # Insert TODO tests here.
131 # TODO tests }}}
134 diag("Testing finished.");
136 sub testcmd {
137 # {{{
138 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
139 my $stderr_cmd = "";
140 my $deb_str = $Opt{'debug'} ? " --debug" : "";
141 my $Txt = join("",
142 "\"$Cmd\"",
143 defined($Desc)
144 ? " - $Desc"
145 : ""
147 my $TMP_STDERR = "addpoints-stderr.tmp";
149 if (defined($Exp_stderr) && !length($deb_str)) {
150 $stderr_cmd = " 2>$TMP_STDERR";
152 is(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
153 if (defined($Exp_stderr)) {
154 if (!length($deb_str)) {
155 is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
156 unlink($TMP_STDERR);
158 } else {
159 diag("Warning: stderr not defined for '$Txt'");
161 # }}}
164 sub likecmd {
165 # {{{
166 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
167 my $stderr_cmd = "";
168 my $deb_str = $Opt{'debug'} ? " --debug" : "";
169 my $Txt = join("",
170 "\"$Cmd\"",
171 defined($Desc)
172 ? " - $Desc"
173 : ""
175 my $TMP_STDERR = "addpoints-stderr.tmp";
177 if (defined($Exp_stderr) && !length($deb_str)) {
178 $stderr_cmd = " 2>$TMP_STDERR";
180 like(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
181 if (defined($Exp_stderr)) {
182 if (!length($deb_str)) {
183 like(file_data($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
184 unlink($TMP_STDERR);
186 } else {
187 diag("Warning: stderr not defined for '$Txt'");
189 # }}}
192 sub file_data {
193 # Return file content as a string {{{
194 my $File = shift;
195 my $Txt;
196 if (open(FP, "<", $File)) {
197 $Txt = join("", <FP>);
198 close(FP);
199 return($Txt);
200 } else {
201 return undef;
203 # }}}
206 sub print_version {
207 # Print program version {{{
208 for (@main::version_array) {
209 print("$_\n");
211 # }}}
212 } # print_version()
214 sub usage {
215 # Send the help message to stdout {{{
216 my $Retval = shift;
218 if ($Opt{'verbose'}) {
219 print("\n");
220 print_version();
222 print(<<END);
224 Usage: $progname [options] [file [files [...]]]
226 Contains tests for the addpoints(1) program.
228 Options:
230 -a, --all
231 Run all tests, also TODOs.
232 -h, --help
233 Show this help.
234 -t, --todo
235 Run only the TODO tests.
236 -v, --verbose
237 Increase level of verbosity. Can be repeated.
238 --version
239 Print version information.
240 --debug
241 Print debugging messages.
244 exit($Retval);
245 # }}}
246 } # usage()
248 sub msg {
249 # Print a status message to stderr based on verbosity level {{{
250 my ($verbose_level, $Txt) = @_;
252 if ($Opt{'verbose'} >= $verbose_level) {
253 print(STDERR "$progname: $Txt\n");
255 # }}}
256 } # msg()
258 __END__
260 # Plain Old Documentation (POD) {{{
262 =pod
264 =head1 NAME
266 run-tests.pl
268 =head1 REVISION
270 $Id$
272 =head1 SYNOPSIS
274 addpoints.t [options] [file [files [...]]]
276 =head1 DESCRIPTION
278 Contains tests for the addpoints(1) program.
280 =head1 OPTIONS
282 =over 4
284 =item B<-a>, B<--all>
286 Run all tests, also TODOs.
288 =item B<-h>, B<--help>
290 Print a brief help summary.
292 =item B<-t>, B<--todo>
294 Run only the TODO tests.
296 =item B<-v>, B<--verbose>
298 Increase level of verbosity. Can be repeated.
300 =item B<--version>
302 Print version information.
304 =item B<--debug>
306 Print debugging messages.
308 =back
310 =head1 AUTHOR
312 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
314 =head1 COPYRIGHT
316 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
317 This is free software; see the file F<COPYING> for legalese stuff.
319 =head1 LICENCE
321 This program is free software; you can redistribute it and/or modify it
322 under the terms of the GNU General Public License as published by the
323 Free Software Foundation; either version 2 of the License, or (at your
324 option) any later version.
326 This program is distributed in the hope that it will be useful, but
327 WITHOUT ANY WARRANTY; without even the implied warranty of
328 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
329 See the GNU General Public License for more details.
331 You should have received a copy of the GNU General Public License along
332 with this program; if not, write to the Free Software Foundation, Inc.,
333 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
335 =head1 SEE ALSO
337 =cut
339 # }}}
341 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
342 # End of file $Id$