create-ly: band: Create .ly files for all instruments
[sunny256-utils.git] / tests / ga-fsck-size.t
blobe5da643a3391794ad23cdc5ced3b2593dcbd70cf
1 #!/usr/bin/env perl
3 #=======================================================================
4 # ga-fsck-size.t
5 # File ID: 4ac10522-2719-11e5-85fa-000df06acc56
7 # Test suite for ga-fsck-size(1).
9 # Character set: UTF-8
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 #=======================================================================
15 use strict;
16 use warnings;
18 BEGIN {
19 use Test::More;
20 if (eval { require Number::Bytes::Human; }) {
21 plan "no_plan";
22 } else {
23 plan "skip_all" => "Number::Bytes::Human is not installed,"
24 . " skipping tests";
26 # use_ok() goes here
29 use Getopt::Long;
31 local $| = 1;
33 our $CMDB = "ga-fsck-size";
34 our $CMD = "../$CMDB";
36 our %Opt = (
38 'all' => 0,
39 'help' => 0,
40 'quiet' => 0,
41 'todo' => 0,
42 'verbose' => 0,
43 'version' => 0,
47 our $progname = $0;
48 $progname =~ s/^.*\/(.*?)$/$1/;
49 our $VERSION = '0.0.0';
51 my %descriptions = ();
53 Getopt::Long::Configure('bundling');
54 GetOptions(
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'}) {
68 print_version();
69 exit(0);
72 exit(main());
74 sub main {
75 # {{{
76 my $Retval = 0;
78 diag(sprintf('========== Executing %s v%s ==========',
79 $progname, $VERSION));
81 if ($Opt{'todo'} && !$Opt{'all'}) {
82 goto todo_section;
85 =pod
87 testcmd("$CMD command", # {{{
88 <<'END',
89 [expected stdout]
90 END
91 '',
93 'description',
96 # }}}
98 =cut
100 diag('Testing -h (--help) option...');
101 likecmd("$CMD -h", # {{{
102 '/ Show this help/i',
103 '/^$/',
105 'Option -h prints help screen',
108 # }}}
109 diag('Testing -v (--verbose) option...');
110 likecmd("$CMD -hv", # {{{
111 '/^\n\S+ \d+\.\d+\.\d+/s',
112 '/^$/',
114 'Option -v with -h returns version number and help screen',
117 # }}}
118 diag('Testing --version option...');
119 likecmd("$CMD --version", # {{{
120 '/^\S+ \d+\.\d+\.\d+/',
121 '/^$/',
123 'Option --version returns version number',
126 # }}}
128 if (`git-annex version 2>/dev/null` !~ /^git-annex version/) {
129 diag("git-annex is not installed here, skipping tests");
130 return 0;
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", # {{{
140 <<END,
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
165 fsck WORM.txt 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"
176 # }}}
177 likecmd("git annex fsck --numcopies=2 2>&1 | ../../$CMD", # {{{
179 '/^' .
180 'fsck MD5.txt \(checksum...\)' .
181 '.+' .
182 'Only 1 of 2 trustworthy copies exist of MD5\.txt \(4(\.0)? bytes\)\n' .
183 'failed\n' .
184 '.+' .
185 'Only 1 of 2 trustworthy copies exist of SHA256\.txt \(7(\.0)? bytes\)\n' .
186 'failed\n' .
187 '.+' .
188 'git-annex: fsck: 25 failed\n' .
189 '\n' .
190 'Total size of files that need more copies: 199\n' .
191 'Total space needed to get enough copies : 199\n' .
192 '$/s'
194 '/^$/',
196 "Copies missing when numcopies=2",
199 # }}}
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');
208 todo_section:
211 if ($Opt{'all'} || $Opt{'todo'}) {
212 diag('Running TODO tests...'); # {{{
214 TODO: {
216 local $TODO = '';
217 # Insert TODO tests here.
220 # TODO tests }}}
223 diag('Testing finished.');
224 return $Retval;
225 # }}}
226 } # main()
228 sub testcmd {
229 # {{{
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;
234 my $stderr_cmd = '';
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";
238 my $retval = 1;
240 if (defined($Exp_stderr)) {
241 $stderr_cmd = " 2>$TMP_STDERR";
243 $retval &= is(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
244 my $ret_val = $?;
245 if (defined($Exp_stderr)) {
246 $retval &= is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
247 unlink($TMP_STDERR);
248 } else {
249 diag("Warning: stderr not defined for '$Txt'");
251 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
253 return $retval;
254 # }}}
255 } # testcmd()
257 sub likecmd {
258 # {{{
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;
263 my $stderr_cmd = '';
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";
267 my $retval = 1;
269 if (defined($Exp_stderr)) {
270 $stderr_cmd = " 2>$TMP_STDERR";
272 $retval &= like(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
273 my $ret_val = $?;
274 if (defined($Exp_stderr)) {
275 $retval &= like(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
276 unlink($TMP_STDERR);
277 } else {
278 diag("Warning: stderr not defined for '$Txt'");
280 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
282 return $retval;
283 # }}}
284 } # likecmd()
286 sub file_data {
287 # Return file content as a string {{{
288 my $File = shift;
289 my $Txt;
291 open(my $fp, '<', $File) or return undef;
292 local $/ = undef;
293 $Txt = <$fp>;
294 close($fp);
295 return $Txt;
296 # }}}
297 } # file_data()
299 sub print_version {
300 # Print program version {{{
301 print("$progname $VERSION\n");
302 return;
303 # }}}
304 } # print_version()
306 sub usage {
307 # Send the help message to stdout {{{
308 my $Retval = shift;
310 if ($Opt{'verbose'}) {
311 print("\n");
312 print_version();
314 print(<<"END");
316 Usage: $progname [options]
318 Contains tests for the $CMDB(1) program.
320 Options:
322 -a, --all
323 Run all tests, also TODOs.
324 -h, --help
325 Show this help.
326 -q, --quiet
327 Be more quiet. Can be repeated to increase silence.
328 -t, --todo
329 Run only the TODO tests.
330 -v, --verbose
331 Increase level of verbosity. Can be repeated.
332 --version
333 Print version information.
336 exit($Retval);
337 # }}}
338 } # usage()
340 sub msg {
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");
346 return;
347 # }}}
348 } # msg()
350 __END__
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 :