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 | ../../$CMD", # {{{
141 fsck MD5.txt (checksum...) ok
142 fsck MD5E.txt (checksum...) ok
143 fsck SHA1.txt (checksum...) ok
144 fsck SHA1E.txt (checksum...) ok
145 fsck SHA224.txt (checksum...) ok
146 fsck SHA224E.txt (checksum...) ok
147 fsck SHA256.txt (checksum...) ok
148 fsck SHA256E.txt (checksum...) ok
149 fsck SHA384.txt (checksum...) ok
150 fsck SHA384E.txt (checksum...) ok
151 fsck SHA3_224.txt (checksum...) ok
152 fsck SHA3_224E.txt (checksum...) ok
153 fsck SHA3_256.txt (checksum...) ok
154 fsck SHA3_256E.txt (checksum...) ok
155 fsck SHA3_384.txt (checksum...) ok
156 fsck SHA3_384E.txt (checksum...) ok
157 fsck SHA3_512.txt (checksum...) ok
158 fsck SHA3_512E.txt (checksum...) ok
159 fsck SHA512.txt (checksum...) ok
160 fsck SHA512E.txt (checksum...) ok
161 fsck SKEIN256.txt (checksum...) ok
162 fsck SKEIN256E.txt (checksum...) ok
163 fsck SKEIN512.txt (checksum...) ok
164 fsck SKEIN512E.txt (checksum...) ok
166 (recording state in git...)
168 Total size of files that need more copies: 0
169 Total space needed to get enough copies : 0
173 "Filter 'git annex fsck' through $CMD"
177 likecmd
("git annex fsck --numcopies=2 2>&1 | ../../$CMD", # {{{
180 'fsck MD5.txt \(checksum...\)' .
182 'Only 1 of 2 trustworthy copies exist of MD5\.txt \(4(\.0)? bytes\)\n' .
185 'Only 1 of 2 trustworthy copies exist of SHA256\.txt \(7(\.0)? bytes\)\n' .
188 'git-annex: fsck: 25 failed\n' .
190 'Total size of files that need more copies: 199\n' .
191 'Total space needed to get enough copies : 199\n' .
196 "Copies missing when numcopies=2",
201 ok
(chdir('..'), 'chdir ..');
203 diag
('Clean up temporary files...');
204 testcmd
('chmod -R +w annex-backends', '', '', 0, 'chmod everything under annex-backends/ to +write');
205 testcmd
('rm -rf annex-backends', '', '', 0, 'Delete temp repo');
206 ok
(!-e
'annex-backends', 'annex-backends is gone');
211 if ($Opt{'all'} || $Opt{'todo'}) {
212 diag
('Running TODO tests...'); # {{{
217 # Insert TODO tests here.
223 diag
('Testing finished.');
230 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
231 defined($descriptions{$Desc}) &&
232 BAIL_OUT
("testcmd(): '$Desc' description is used twice");
233 $descriptions{$Desc} = 1;
235 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
236 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
237 my $TMP_STDERR = "$CMDB-stderr.tmp";
240 if (defined($Exp_stderr)) {
241 $stderr_cmd = " 2>$TMP_STDERR";
243 $retval &= is
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
245 if (defined($Exp_stderr)) {
246 $retval &= is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
249 diag
("Warning: stderr not defined for '$Txt'");
251 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
259 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
260 defined($descriptions{$Desc}) &&
261 BAIL_OUT
("likecmd(): '$Desc' description is used twice");
262 $descriptions{$Desc} = 1;
264 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
265 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
266 my $TMP_STDERR = "$CMDB-stderr.tmp";
269 if (defined($Exp_stderr)) {
270 $stderr_cmd = " 2>$TMP_STDERR";
272 $retval &= like
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
274 if (defined($Exp_stderr)) {
275 $retval &= like
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
278 diag
("Warning: stderr not defined for '$Txt'");
280 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
287 # Return file content as a string {{{
291 open(my $fp, '<', $File) or return undef;
300 # Print program version {{{
301 print("$progname $VERSION\n");
307 # Send the help message to stdout {{{
310 if ($Opt{'verbose'}) {
316 Usage: $progname [options]
318 Contains tests for the $CMDB(1) program.
323 Run all tests, also TODOs.
327 Be more quiet. Can be repeated to increase silence.
329 Run only the TODO tests.
331 Increase level of verbosity. Can be repeated.
333 Print version information.
341 # Print a status message to stderr based on verbosity level {{{
342 my ($verbose_level, $Txt) = @_;
344 $verbose_level > $Opt{'verbose'} && return;
345 print(STDERR
"$progname: $Txt\n");
352 # This program is free software; you can redistribute it and/or modify
353 # it under the terms of the GNU General Public License as published by
354 # the Free Software Foundation; either version 2 of the License, or (at
355 # your option) any later version.
357 # This program is distributed in the hope that it will be useful, but
358 # WITHOUT ANY WARRANTY; without even the implied warranty of
359 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
360 # See the GNU General Public License for more details.
362 # You should have received a copy of the GNU General Public License
363 # along with this program.
364 # If not, see L<http://www.gnu.org/licenses/>.
366 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :