3 #=======================================================================
5 # File ID: 4ac10522-2719-11e5-85fa-000df06acc56
7 # Test suite for ga-fsck-size(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 #=======================================================================
20 if (eval { require Number
::Bytes
::Human
; }) {
23 plan
"skip_all" => "Number::Bytes::Human is not installed,"
33 our $CMDB = "ga-fsck-size";
34 our $CMD = "../$CMDB";
48 $progname =~ s/^.*\/(.*?)$/$1/;
49 our $VERSION = '0.0.0';
51 my %descriptions = ();
53 Getopt
::Long
::Configure
('bundling');
56 'all|a' => \
$Opt{'all'},
57 'help|h' => \
$Opt{'help'},
58 'quiet|q+' => \
$Opt{'quiet'},
59 'todo|t' => \
$Opt{'todo'},
60 'verbose|v+' => \
$Opt{'verbose'},
61 'version' => \
$Opt{'version'},
63 ) || die("$progname: Option error. Use -h for help.\n");
65 $Opt{'verbose'} -= $Opt{'quiet'};
66 $Opt{'help'} && usage
(0);
67 if ($Opt{'version'}) {
78 diag
(sprintf('========== Executing %s v%s ==========',
79 $progname, $VERSION));
81 if ($Opt{'todo'} && !$Opt{'all'}) {
87 testcmd("$CMD command", # {{{
100 diag
('Testing -h (--help) option...');
101 likecmd
("$CMD -h", # {{{
102 '/ Show this help/i',
105 'Option -h prints help screen',
109 diag
('Testing -v (--verbose) option...');
110 likecmd
("$CMD -hv", # {{{
111 '/^\n\S+ \d+\.\d+\.\d+/s',
114 'Option -v with -h returns version number and help screen',
118 diag
('Testing --version option...');
119 likecmd
("$CMD --version", # {{{
120 '/^\S+ \d+\.\d+\.\d+/',
123 'Option --version returns version number',
128 if (`git-annex version 2>/dev/null` !~ /^git-annex version/) {
129 diag
("git-annex is not installed here, skipping tests");
133 diag
("Initialise temprepo...");
134 ok
(chdir('ga-fsck-size-files'), 'chdir ga-fsck-size-files');
135 testcmd
('tar xzf annex-backends.tar.gz', '', '', 0, 'Untar annex-backends.tar.gz');
137 ok
(chdir('annex-backends'), 'chdir annex-backends');
139 testcmd
("git annex fsck 2>&1 | grep -v ^fsck | ../../$CMD", # {{{
141 (recording state in git...)
143 Total size of files that need more copies: 0
144 Total space needed to get enough copies : 0
148 "Filter 'git annex fsck' through $CMD"
152 likecmd
("git annex fsck --numcopies=2 2>&1 | ../../$CMD", # {{{
155 'fsck MD5.txt \(checksum...\)' .
157 'Only 1 of 2 trustworthy copies exist of MD5\.txt \(4(\.0)? bytes\)\n' .
160 'Only 1 of 2 trustworthy copies exist of SHA256\.txt \(7(\.0)? bytes\)\n' .
163 'fsck: 25 failed\n' .
165 'Total size of files that need more copies: 199\n' .
166 'Total space needed to get enough copies : 199\n' .
171 "Copies missing when numcopies=2",
176 ok
(chdir('..'), 'chdir ..');
178 diag
('Clean up temporary files...');
179 testcmd
('chmod -R +w annex-backends', '', '', 0, 'chmod everything under annex-backends/ to +write');
180 testcmd
('rm -rf annex-backends', '', '', 0, 'Delete temp repo');
181 ok
(!-e
'annex-backends', 'annex-backends is gone');
186 if ($Opt{'all'} || $Opt{'todo'}) {
187 diag
('Running TODO tests...'); # {{{
192 # Insert TODO tests here.
198 diag
('Testing finished.');
205 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
206 defined($descriptions{$Desc}) &&
207 BAIL_OUT
("testcmd(): '$Desc' description is used twice");
208 $descriptions{$Desc} = 1;
210 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
211 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
212 my $TMP_STDERR = "$CMDB-stderr.tmp";
215 if (defined($Exp_stderr)) {
216 $stderr_cmd = " 2>$TMP_STDERR";
218 $retval &= is
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
220 if (defined($Exp_stderr)) {
221 $retval &= is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
224 diag
("Warning: stderr not defined for '$Txt'");
226 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
234 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
235 defined($descriptions{$Desc}) &&
236 BAIL_OUT
("likecmd(): '$Desc' description is used twice");
237 $descriptions{$Desc} = 1;
239 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
240 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
241 my $TMP_STDERR = "$CMDB-stderr.tmp";
244 if (defined($Exp_stderr)) {
245 $stderr_cmd = " 2>$TMP_STDERR";
247 $retval &= like
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
249 if (defined($Exp_stderr)) {
250 $retval &= like
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
253 diag
("Warning: stderr not defined for '$Txt'");
255 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
262 # Return file content as a string {{{
266 open(my $fp, '<', $File) or return undef;
275 # Print program version {{{
276 print("$progname $VERSION\n");
282 # Send the help message to stdout {{{
285 if ($Opt{'verbose'}) {
291 Usage: $progname [options]
293 Contains tests for the $CMDB(1) program.
298 Run all tests, also TODOs.
302 Be more quiet. Can be repeated to increase silence.
304 Run only the TODO tests.
306 Increase level of verbosity. Can be repeated.
308 Print version information.
316 # Print a status message to stderr based on verbosity level {{{
317 my ($verbose_level, $Txt) = @_;
319 $verbose_level > $Opt{'verbose'} && return;
320 print(STDERR
"$progname: $Txt\n");
327 # This program is free software; you can redistribute it and/or modify
328 # it under the terms of the GNU General Public License as published by
329 # the Free Software Foundation; either version 2 of the License, or (at
330 # your option) any later version.
332 # This program is distributed in the hope that it will be useful, but
333 # WITHOUT ANY WARRANTY; without even the implied warranty of
334 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
335 # See the GNU General Public License for more details.
337 # You should have received a copy of the GNU General Public License
338 # along with this program.
339 # If not, see L<http://www.gnu.org/licenses/>.
341 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :