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 #=======================================================================
19 use Test
::More
qw{no_plan
};
27 our $CMD_BASENAME = "ga-fsck-size";
28 our $CMD = "../$CMD_BASENAME";
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',
122 diag
("Initialise temprepo...");
123 ok
(chdir('ga-fsck-size-files'), 'chdir ga-fsck-size-files');
124 testcmd
('tar xzf annex-backends.tar.gz', '', '', 0, 'Untar annex-backends.tar.gz');
126 ok
(chdir('annex-backends'), 'chdir annex-backends');
128 testcmd
("git annex fsck 2>&1 | ../../$CMD", # {{{
130 fsck MD5.txt (checksum...) ok
131 fsck MD5E.txt (checksum...) ok
132 fsck SHA1.txt (checksum...) ok
133 fsck SHA1E.txt (checksum...) ok
134 fsck SHA224.txt (checksum...) ok
135 fsck SHA224E.txt (checksum...) ok
136 fsck SHA256.txt (checksum...) ok
137 fsck SHA256E.txt (checksum...) ok
138 fsck SHA384.txt (checksum...) ok
139 fsck SHA384E.txt (checksum...) ok
140 fsck SHA3_224.txt (checksum...) ok
141 fsck SHA3_224E.txt (checksum...) ok
142 fsck SHA3_256.txt (checksum...) ok
143 fsck SHA3_256E.txt (checksum...) ok
144 fsck SHA3_384.txt (checksum...) ok
145 fsck SHA3_384E.txt (checksum...) ok
146 fsck SHA3_512.txt (checksum...) ok
147 fsck SHA3_512E.txt (checksum...) ok
148 fsck SHA512.txt (checksum...) ok
149 fsck SHA512E.txt (checksum...) ok
150 fsck SKEIN256.txt (checksum...) ok
151 fsck SKEIN256E.txt (checksum...) ok
152 fsck SKEIN512.txt (checksum...) ok
153 fsck SKEIN512E.txt (checksum...) ok
155 (recording state in git...)
157 Total size of files that need more copies: 0
158 Total space needed to get enough copies : 0
162 "Filter 'git annex fsck' through $CMD"
166 likecmd
("git annex fsck --numcopies=2 2>&1 | ../../$CMD", # {{{
169 'fsck MD5.txt \(checksum...\)' .
171 'Only 1 of 2 trustworthy copies exist of MD5\.txt \(4(\.0)? bytes\)\n' .
174 'Only 1 of 2 trustworthy copies exist of SHA256\.txt \(7(\.0)? bytes\)\n' .
177 'git-annex: fsck: 25 failed\n' .
179 'Total size of files that need more copies: 199\n' .
180 'Total space needed to get enough copies : 199\n' .
185 "Copies missing when numcopies=2",
190 ok
(chdir('..'), 'chdir ..');
192 diag
('Clean up temporary files...');
193 testcmd
('chmod -R +w annex-backends', '', '', 0, 'chmod everything under annex-backends/ to +write');
194 testcmd
('rm -rf annex-backends', '', '', 0, 'Delete temp repo');
195 ok
(!-e
'annex-backends', 'annex-backends is gone');
200 if ($Opt{'all'} || $Opt{'todo'}) {
201 diag
('Running TODO tests...'); # {{{
206 # Insert TODO tests here.
212 diag
('Testing finished.');
219 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
220 defined($descriptions{$Desc}) &&
221 BAIL_OUT
("testcmd(): '$Desc' description is used twice");
222 $descriptions{$Desc} = 1;
224 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
225 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
226 my $TMP_STDERR = "$CMD_BASENAME-stderr.tmp";
229 if (defined($Exp_stderr)) {
230 $stderr_cmd = " 2>$TMP_STDERR";
232 $retval &= is
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
234 if (defined($Exp_stderr)) {
235 $retval &= is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
238 diag
("Warning: stderr not defined for '$Txt'");
240 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
248 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
249 defined($descriptions{$Desc}) &&
250 BAIL_OUT
("likecmd(): '$Desc' description is used twice");
251 $descriptions{$Desc} = 1;
253 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
254 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
255 my $TMP_STDERR = "$CMD_BASENAME-stderr.tmp";
258 if (defined($Exp_stderr)) {
259 $stderr_cmd = " 2>$TMP_STDERR";
261 $retval &= like
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
263 if (defined($Exp_stderr)) {
264 $retval &= like
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
267 diag
("Warning: stderr not defined for '$Txt'");
269 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
276 # Return file content as a string {{{
280 open(my $fp, '<', $File) or return undef;
289 # Print program version {{{
290 print("$progname $VERSION\n");
296 # Send the help message to stdout {{{
299 if ($Opt{'verbose'}) {
305 Usage: $progname [options]
307 Contains tests for the $CMD_BASENAME(1) program.
312 Run all tests, also TODOs.
316 Be more quiet. Can be repeated to increase silence.
318 Run only the TODO tests.
320 Increase level of verbosity. Can be repeated.
322 Print version information.
330 # Print a status message to stderr based on verbosity level {{{
331 my ($verbose_level, $Txt) = @_;
333 $verbose_level > $Opt{'verbose'} && return;
334 print(STDERR
"$progname: $Txt\n");
341 # This program is free software; you can redistribute it and/or modify
342 # it under the terms of the GNU General Public License as published by
343 # the Free Software Foundation; either version 2 of the License, or (at
344 # your option) any later version.
346 # This program is distributed in the hope that it will be useful, but
347 # WITHOUT ANY WARRANTY; without even the implied warranty of
348 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
349 # See the GNU General Public License for more details.
351 # You should have received a copy of the GNU General Public License
352 # along with this program.
353 # If not, see L<http://www.gnu.org/licenses/>.
355 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :