Lib/std/c/src/: Add UNUSED, compile unused code
[sunny256-utils.git] / tests / ga-fsck-size.t
bloba5eb82b7b007760bc324ea3f2f9ab8ac5784faee
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 qw{no_plan};
20 # use_ok() goes here
23 use Getopt::Long;
25 local $| = 1;
27 our $CMD_BASENAME = "ga-fsck-size";
28 our $CMD = "../$CMD_BASENAME";
30 our %Opt = (
32 'all' => 0,
33 'help' => 0,
34 'quiet' => 0,
35 'todo' => 0,
36 'verbose' => 0,
37 'version' => 0,
41 our $progname = $0;
42 $progname =~ s/^.*\/(.*?)$/$1/;
43 our $VERSION = '0.0.0';
45 my %descriptions = ();
47 Getopt::Long::Configure('bundling');
48 GetOptions(
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'}) {
62 print_version();
63 exit(0);
66 exit(main());
68 sub main {
69 # {{{
70 my $Retval = 0;
72 diag(sprintf('========== Executing %s v%s ==========',
73 $progname, $VERSION));
75 if ($Opt{'todo'} && !$Opt{'all'}) {
76 goto todo_section;
79 =pod
81 testcmd("$CMD command", # {{{
82 <<'END',
83 [expected stdout]
84 END
85 '',
87 'description',
90 # }}}
92 =cut
94 diag('Testing -h (--help) option...');
95 likecmd("$CMD -h", # {{{
96 '/ Show this help/i',
97 '/^$/',
99 'Option -h prints help screen',
102 # }}}
103 diag('Testing -v (--verbose) option...');
104 likecmd("$CMD -hv", # {{{
105 '/^\n\S+ \d+\.\d+\.\d+/s',
106 '/^$/',
108 'Option -v with -h returns version number and help screen',
111 # }}}
112 diag('Testing --version option...');
113 likecmd("$CMD --version", # {{{
114 '/^\S+ \d+\.\d+\.\d+/',
115 '/^$/',
117 'Option --version returns version number',
120 # }}}
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", # {{{
129 <<END,
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
154 fsck WORM.txt 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"
165 # }}}
166 likecmd("git annex fsck --numcopies=2 2>&1 | ../../$CMD", # {{{
168 '/^' .
169 'fsck MD5.txt \(checksum...\)' .
170 '.+' .
171 'Only 1 of 2 trustworthy copies exist of MD5\.txt \(4(\.0)? bytes\)\n' .
172 'failed\n' .
173 '.+' .
174 'Only 1 of 2 trustworthy copies exist of SHA256\.txt \(7(\.0)? bytes\)\n' .
175 'failed\n' .
176 '.+' .
177 'git-annex: fsck: 25 failed\n' .
178 '\n' .
179 'Total size of files that need more copies: 199\n' .
180 'Total space needed to get enough copies : 199\n' .
181 '$/s'
183 '/^$/',
185 "Copies missing when numcopies=2",
188 # }}}
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');
197 todo_section:
200 if ($Opt{'all'} || $Opt{'todo'}) {
201 diag('Running TODO tests...'); # {{{
203 TODO: {
205 local $TODO = '';
206 # Insert TODO tests here.
209 # TODO tests }}}
212 diag('Testing finished.');
213 return $Retval;
214 # }}}
215 } # main()
217 sub testcmd {
218 # {{{
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;
223 my $stderr_cmd = '';
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";
227 my $retval = 1;
229 if (defined($Exp_stderr)) {
230 $stderr_cmd = " 2>$TMP_STDERR";
232 $retval &= is(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
233 my $ret_val = $?;
234 if (defined($Exp_stderr)) {
235 $retval &= is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
236 unlink($TMP_STDERR);
237 } else {
238 diag("Warning: stderr not defined for '$Txt'");
240 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
242 return $retval;
243 # }}}
244 } # testcmd()
246 sub likecmd {
247 # {{{
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;
252 my $stderr_cmd = '';
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";
256 my $retval = 1;
258 if (defined($Exp_stderr)) {
259 $stderr_cmd = " 2>$TMP_STDERR";
261 $retval &= like(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
262 my $ret_val = $?;
263 if (defined($Exp_stderr)) {
264 $retval &= like(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
265 unlink($TMP_STDERR);
266 } else {
267 diag("Warning: stderr not defined for '$Txt'");
269 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
271 return $retval;
272 # }}}
273 } # likecmd()
275 sub file_data {
276 # Return file content as a string {{{
277 my $File = shift;
278 my $Txt;
280 open(my $fp, '<', $File) or return undef;
281 local $/ = undef;
282 $Txt = <$fp>;
283 close($fp);
284 return $Txt;
285 # }}}
286 } # file_data()
288 sub print_version {
289 # Print program version {{{
290 print("$progname $VERSION\n");
291 return;
292 # }}}
293 } # print_version()
295 sub usage {
296 # Send the help message to stdout {{{
297 my $Retval = shift;
299 if ($Opt{'verbose'}) {
300 print("\n");
301 print_version();
303 print(<<"END");
305 Usage: $progname [options]
307 Contains tests for the $CMD_BASENAME(1) program.
309 Options:
311 -a, --all
312 Run all tests, also TODOs.
313 -h, --help
314 Show this help.
315 -q, --quiet
316 Be more quiet. Can be repeated to increase silence.
317 -t, --todo
318 Run only the TODO tests.
319 -v, --verbose
320 Increase level of verbosity. Can be repeated.
321 --version
322 Print version information.
325 exit($Retval);
326 # }}}
327 } # usage()
329 sub msg {
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");
335 return;
336 # }}}
337 } # msg()
339 __END__
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 :