File Coverage

tests/registry-1
Criterion Covered Total %
statement 16 65 24.6
branch 1 10 10.0
condition 0 12 0.0
subroutine 5 5 100.0
pod n/a
total 22 92 23.9


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             # The script tests Arch::Registry with local archives.
4              
5 1     1   882 use Data::Dumper;
  1         11556  
  1         69  
6 1     1   827 use FindBin;
  1         1021  
  1         53  
7 1     1   678 use lib "$FindBin::Bin/../perllib";
  1         648  
  1         7  
8              
9 1     1   1285 use Test::More;
  1         19748  
  1         11  
10 1     1   1009 use Arch::Util qw(is_tla_functional);
  1         3  
  1         2861  
11              
12 1 50       7 plan skip_all => "No functional arch backend" unless is_tla_functional;
13 0         0 plan tests => 20;
14              
15 0         0 use_ok("Arch::Registry");
16 0         0 use_ok("Arch::Util", "run_tla");
17 0         0 use_ok("Arch::Backend", "is_baz");
18 0         0 use_ok("Arch::TempFiles");
19              
20 0         0 my $tmp = Arch::TempFiles->new;
21 0         0 my $dir = $tmp->dir;
22 0 0 0     0 die "Internal: Arch::TempFiles::dir didn't create dir\n" unless $dir && -d $dir;
23              
24 0 0       0 chdir($dir) or die "Internal: can't chdir $dir\n";
25 0         0 $ENV{HOME} = $dir;
26              
27 0         0 my $registry = Arch::Registry->new;
28 0   0     0 ok(ref($registry) && $registry->isa('Arch::Registry'), "create registry object");
29              
30 0         0 my $archives = $registry->registered_archives;
31 0   0     0 ok(ref($archives) eq 'HASH' && !%$archives, "no registered test archives");
32              
33 0         0 my $archive1 = 'person@domain.com--test';
34 0         0 my $archive2 = 'something@unreal--test';
35 0         0 my $archive3 = 'un@existing--test';
36              
37             #mkdir("$dir/$archive1", 0777) or die "Can't mkdir $dir/$archive1: $!";
38 0         0 run_tla("make-archive $archive1 $dir/$archive1");
39 0         0 is($?, 0, "make-archive $archive1");
40 0         0 my $success = $registry->register_archive("$dir/$archive1", $archive1);
41 0         0 ok($success, "register-archive $archive1");
42 0         0 $success = $registry->register_archive("$dir/$archive1");
43 0         0 ok($success, "register-archive $archive1 with location only");
44              
45 0         0 my $is_baz = is_baz();
46 0 0       0 my $num_archives = $is_baz? 1: 2;
47              
48 0         0 open OLDERR, ">&STDERR";
49 0         0 close STDERR; *OLDERR = *OLDERR;
  0         0  
50 0         0 $success = $registry->register_archive($dir, $archive2);
51 0         0 ok($success ^ $is_baz, "register-archive $archive2");
52              
53 0         0 $success = $registry->register_archive("$dir/$archive3");
54 0         0 open STDERR, ">&OLDERR";
55 0         0 ok(!$success, "register-archive with unexisting location");
56              
57 0         0 my %archives = $registry->registered_archives;
58 0   0     0 is(%archives && keys %archives, $num_archives, "check the number of archives");
59 0         0 ok($archives{$archive1}, "- including $archive1");
60 0         0 is($archives{$archive1}, "$dir/$archive1", "- - and its location");
61 0 0       0 SKIP: {
62 0         0 skip("baz has changed register-archive", 2) if $is_baz;
63 0         0 ok($archives{$archive2}, "- including $archive2");
64 0         0 is($archives{$archive2}, "$dir", "- - and its location");
65             }
66              
67 0         0 $success = $registry->unregister_archive($archive1);
68 0         0 ok($success, "unregister-archive $archive1");
69 0         0 $success = $registry->unregister_archive($archive2);
70 0         0 ok($success, "unregister-archive $archive2");
71 0         0 $success = $registry->unregister_archive($archive3);
72 0         0 ok($success, "unregister-archive $archive3");
73              
74 0         0 %archives = $registry->registered_archives;
75 0         0 ok(!%archives, "no registered test archives again");
76