3 #=======================================================================
5 # File ID: 506b8efe-2825-11e5-bc20-000df06acc56
7 # Test suite for git-scanrefs(1).
10 # ©opyleft 2015– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
19 use Test
::More
qw{no_plan
};
27 our $CMDB = "git-scanrefs";
28 our $CMD = "../$CMDB";
42 $progname =~ s/^.*\/(.*?)$/$1/;
43 our $VERSION = '0.0.0';
45 my %descriptions = ();
47 Getopt
::Long
::Configure
('bundling');
50 'all|a' => \
$Opt{'all'},
51 'help|h' => \
$Opt{'help'},
52 'quiet|q+' => \
$Opt{'quiet'},
53 'todo|t' => \
$Opt{'todo'},
54 'verbose|v+' => \
$Opt{'verbose'},
55 'version' => \
$Opt{'version'},
57 ) || die("$progname: Option error. Use -h for help.\n");
59 $Opt{'verbose'} -= $Opt{'quiet'};
60 $Opt{'help'} && usage
(0);
61 if ($Opt{'version'}) {
72 diag
(sprintf('========== Executing %s v%s ==========',
73 $progname, $VERSION));
75 if ($Opt{'todo'} && !$Opt{'all'}) {
81 testcmd("$CMD command", # {{{
94 diag
('Testing -h (--help) option...');
95 likecmd
("$CMD -h", # {{{
99 'Option -h prints help screen',
103 diag
('Testing -v (--verbose) option...');
104 likecmd
("$CMD -hv", # {{{
105 '/^\n\S+ \d+\.\d+\.\d+/s',
108 'Option -v with -h returns version number and help screen',
112 diag
('Testing --version option...');
113 likecmd
("$CMD --version", # {{{
114 '/^\S+ \d+\.\d+\.\d+/',
117 'Option --version returns version number',
121 my $stdtxt = 'skdjfv151da78gbhs12345abower aaaabbbb01234 asdf 2345 6789';
122 testcmd
("echo $stdtxt | $CMD -vvv", # {{{
124 151da78d6363d20e9a64e478835985ce378fc54f
126 "git-scanrefs: potential_refs('skdjfv151da78gbhs12345abower aaaabbbb01234 asdf 2345 6789') returns ['151da78', '12345ab', 'aaaabbbb01234']\n",
128 'List potential unchecked refs from line',
132 testcmd
("echo $stdtxt $stdtxt | $CMD", # {{{
134 151da78d6363d20e9a64e478835985ce378fc54f
138 'Don\'t list duplicate info',
142 testcmd
("echo $stdtxt 151da78d6363d20e $stdtxt | $CMD", # {{{
144 151da78d6363d20e9a64e478835985ce378fc54f
148 'Not even when the sha has different length',
156 if ($Opt{'all'} || $Opt{'todo'}) {
157 diag
('Running TODO tests...'); # {{{
162 # Insert TODO tests here.
168 diag
('Testing finished.');
175 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
176 defined($descriptions{$Desc}) &&
177 BAIL_OUT
("testcmd(): '$Desc' description is used twice");
178 $descriptions{$Desc} = 1;
180 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
181 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
182 my $TMP_STDERR = "$CMDB-stderr.tmp";
185 if (defined($Exp_stderr)) {
186 $stderr_cmd = " 2>$TMP_STDERR";
188 $retval &= is
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
190 if (defined($Exp_stderr)) {
191 $retval &= is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
194 diag
("Warning: stderr not defined for '$Txt'");
196 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
204 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
205 defined($descriptions{$Desc}) &&
206 BAIL_OUT
("likecmd(): '$Desc' description is used twice");
207 $descriptions{$Desc} = 1;
209 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
210 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
211 my $TMP_STDERR = "$CMDB-stderr.tmp";
214 if (defined($Exp_stderr)) {
215 $stderr_cmd = " 2>$TMP_STDERR";
217 $retval &= like
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
219 if (defined($Exp_stderr)) {
220 $retval &= like
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
223 diag
("Warning: stderr not defined for '$Txt'");
225 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
232 # Return file content as a string {{{
236 open(my $fp, '<', $File) or return undef;
245 # Print program version {{{
246 print("$progname $VERSION\n");
252 # Send the help message to stdout {{{
255 if ($Opt{'verbose'}) {
261 Usage: $progname [options]
263 Contains tests for the $CMDB(1) program.
268 Run all tests, also TODOs.
272 Be more quiet. Can be repeated to increase silence.
274 Run only the TODO tests.
276 Increase level of verbosity. Can be repeated.
278 Print version information.
286 # Print a status message to stderr based on verbosity level {{{
287 my ($verbose_level, $Txt) = @_;
289 $verbose_level > $Opt{'verbose'} && return;
290 print(STDERR
"$progname: $Txt\n");
297 # This program is free software; you can redistribute it and/or modify
298 # it under the terms of the GNU General Public License as published by
299 # the Free Software Foundation; either version 2 of the License, or (at
300 # your option) any later version.
302 # This program is distributed in the hope that it will be useful, but
303 # WITHOUT ANY WARRANTY; without even the implied warranty of
304 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
305 # See the GNU General Public License for more details.
307 # You should have received a copy of the GNU General Public License
308 # along with this program.
309 # If not, see L<http://www.gnu.org/licenses/>.
311 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :