3 #=======================================================================
5 # File ID: e64cce20-5619-11e5-a28a-000df06acc56
7 # Test suite for ga-sumsize(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-sumsize";
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 testcmd
("$CMD </dev/null", # {{{
129 "\nga-sumsize: Total size of keys: 0 (0)\n",
132 'Read empty input from stdin',
136 testcmd
("$CMD /dev/null", # {{{
137 "\nga-sumsize: Total size of keys: 0 (0)\n",
140 'Read directly from /dev/null',
144 testcmd
("$CMD ga-sumsize-files/1.txt", # {{{
146 unused . (checking for unused data...) (checking master...)
147 Some annexed data is no longer used by any files:
149 1 SHA256-s487883366--2125edd12f347e19dc9d5c2c2f4cee14b44f9cbba1ea46ff8af54ae020c58563
150 2 SHA256-s484307143--049e14e3af3bf9aece17ddab008b3cb9be6ab0fb42c91e6ad383364d26b3ffa7
151 3 SHA256-s490478481--12453004cbf74f56adf115f9da32d2b783c9c967469668dbf0f88b85efc856b8
152 4 SHA256-s485358886--bf6c061f378e04d6f45a95e13412aabc4c420a714cfebe7ab70034b72605bc47
153 (To see where data was previously used, try: git log --stat -S'KEY')
155 To remove unwanted data: git-annex dropunused NUMBER
159 ga-sumsize: Total size of keys: 1948027876 (2.0G)
167 testcmd
("$CMD <ga-sumsize-files/1.txt", # {{{
169 unused . (checking for unused data...) (checking master...)
170 Some annexed data is no longer used by any files:
172 1 SHA256-s487883366--2125edd12f347e19dc9d5c2c2f4cee14b44f9cbba1ea46ff8af54ae020c58563
173 2 SHA256-s484307143--049e14e3af3bf9aece17ddab008b3cb9be6ab0fb42c91e6ad383364d26b3ffa7
174 3 SHA256-s490478481--12453004cbf74f56adf115f9da32d2b783c9c967469668dbf0f88b85efc856b8
175 4 SHA256-s485358886--bf6c061f378e04d6f45a95e13412aabc4c420a714cfebe7ab70034b72605bc47
176 (To see where data was previously used, try: git log --stat -S'KEY')
178 To remove unwanted data: git-annex dropunused NUMBER
182 ga-sumsize: Total size of keys: 1948027876 (2.0G)
186 'Read from 1.txt via stdin',
190 testcmd
("$CMD --display ga-sumsize-files/1.txt", # {{{
192 0 unused . (checking for unused data...) (checking master...)
193 0 Some annexed data is no longer used by any files:
195 487883366 1 SHA256-s487883366--2125edd12f347e19dc9d5c2c2f4cee14b44f9cbba1ea46ff8af54ae020c58563
196 972190509 2 SHA256-s484307143--049e14e3af3bf9aece17ddab008b3cb9be6ab0fb42c91e6ad383364d26b3ffa7
197 1462668990 3 SHA256-s490478481--12453004cbf74f56adf115f9da32d2b783c9c967469668dbf0f88b85efc856b8
198 1948027876 4 SHA256-s485358886--bf6c061f378e04d6f45a95e13412aabc4c420a714cfebe7ab70034b72605bc47
199 1948027876 (To see where data was previously used, try: git log --stat -S'KEY')
201 1948027876 To remove unwanted data: git-annex dropunused NUMBER
205 ga-sumsize: Total size of keys: 1948027876 (2.0G)
209 'Test --display option',
213 testcmd
("$CMD -d ga-sumsize-files/1.txt", # {{{
215 0 unused . (checking for unused data...) (checking master...)
216 0 Some annexed data is no longer used by any files:
218 487883366 1 SHA256-s487883366--2125edd12f347e19dc9d5c2c2f4cee14b44f9cbba1ea46ff8af54ae020c58563
219 972190509 2 SHA256-s484307143--049e14e3af3bf9aece17ddab008b3cb9be6ab0fb42c91e6ad383364d26b3ffa7
220 1462668990 3 SHA256-s490478481--12453004cbf74f56adf115f9da32d2b783c9c967469668dbf0f88b85efc856b8
221 1948027876 4 SHA256-s485358886--bf6c061f378e04d6f45a95e13412aabc4c420a714cfebe7ab70034b72605bc47
222 1948027876 (To see where data was previously used, try: git log --stat -S'KEY')
224 1948027876 To remove unwanted data: git-annex dropunused NUMBER
228 ga-sumsize: Total size of keys: 1948027876 (2.0G)
237 if (`git-annex version 2>/dev/null` !~ /^git-annex version/) {
238 diag
("git-annex is not installed here, skipping tests");
242 ok
(chdir("ga-sumsize-files"), "chdir ga-sumsize-files");
243 testcmd
("tar xzf ga-sumsize-repo.tar.gz", # {{{
247 "Untar ga-sumsize-repo.tar.gz",
251 ok
(chdir("ga-sumsize-repo"), "chdir ga-sumsize-repo");
252 likecmd
("ga unused", # {{{
255 'SHA256-s1000--541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53\n' .
257 'SHA256-s123--409a7f83ac6b31dc8c77e3ec18038f209bd2f545e0f4177c2e2381aa4e067b49\n' .
259 'SHA256-s123--409a7f83ac6b31dc8c77e3ec18038f209bd2f545e0f4177c2e2381aa4e067b49\n' .
261 'SHA256-s1000--541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53\n' .
264 'ga-sumsize: Total size of keys: 1123 \(1\.2k\)\n' .
272 ok
(chdir(".."), "chdir ..");
273 testcmd
("chmod -R +w \"ga-sumsize-repo\"", # {{{
277 "chmod -R +w ga-sumsize-repo"
281 testcmd
("rm -rf \"ga-sumsize-repo\"", # {{{
285 "rm -rf ga-sumsize-repo",
293 if ($Opt{'all'} || $Opt{'todo'}) {
294 diag
('Running TODO tests...'); # {{{
299 # Insert TODO tests here.
305 diag
('Testing finished.');
312 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
313 defined($descriptions{$Desc}) &&
314 BAIL_OUT
("testcmd(): '$Desc' description is used twice");
315 $descriptions{$Desc} = 1;
317 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
318 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
319 my $TMP_STDERR = "$CMDB-stderr.tmp";
322 if (defined($Exp_stderr)) {
323 $stderr_cmd = " 2>$TMP_STDERR";
325 $retval &= is
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
327 if (defined($Exp_stderr)) {
328 $retval &= is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
331 diag
("Warning: stderr not defined for '$Txt'");
333 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
341 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
342 defined($descriptions{$Desc}) &&
343 BAIL_OUT
("likecmd(): '$Desc' description is used twice");
344 $descriptions{$Desc} = 1;
346 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
347 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
348 my $TMP_STDERR = "$CMDB-stderr.tmp";
351 if (defined($Exp_stderr)) {
352 $stderr_cmd = " 2>$TMP_STDERR";
354 $retval &= like
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
356 if (defined($Exp_stderr)) {
357 $retval &= like
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
360 diag
("Warning: stderr not defined for '$Txt'");
362 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
369 # Return file content as a string {{{
373 open(my $fp, '<', $File) or return undef;
382 # Print program version {{{
383 print("$progname $VERSION\n");
389 # Send the help message to stdout {{{
392 if ($Opt{'verbose'}) {
398 Usage: $progname [options]
400 Contains tests for the $CMDB(1) program.
405 Run all tests, also TODOs.
409 Be more quiet. Can be repeated to increase silence.
411 Run only the TODO tests.
413 Increase level of verbosity. Can be repeated.
415 Print version information.
423 # Print a status message to stderr based on verbosity level {{{
424 my ($verbose_level, $Txt) = @_;
426 $verbose_level > $Opt{'verbose'} && return;
427 print(STDERR
"$progname: $Txt\n");
434 # This program is free software; you can redistribute it and/or modify
435 # it under the terms of the GNU General Public License as published by
436 # the Free Software Foundation; either version 2 of the License, or (at
437 # your option) any later version.
439 # This program is distributed in the hope that it will be useful, but
440 # WITHOUT ANY WARRANTY; without even the implied warranty of
441 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
442 # See the GNU General Public License for more details.
444 # You should have received a copy of the GNU General Public License
445 # along with this program.
446 # If not, see L<http://www.gnu.org/licenses/>.
448 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :