File Coverage

tests/session-1
Criterion Covered Total %
statement 13 84 15.4
branch 1 16 6.2
condition 0 6 0.0
subroutine 4 5 80.0
pod n/a
total 18 111 16.2


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             # The script tests Arch::Session methods.
4              
5 1     1   841 use FindBin;
  1         1342  
  1         57  
6 1     1   994 use lib "$FindBin::Bin/../perllib";
  1         681  
  1         6  
7              
8 1     1   1329 use Test::More;
  1         21953  
  1         150  
9 1     1   930 use Arch::Util qw(is_tla_functional);
  1         3  
  1         3217  
10              
11 1 50       7 plan skip_all => "No functional arch backend" unless is_tla_functional;
12 0         0 plan tests => 37;
13              
14 0         0 use_ok("Arch::Session");
15 0         0 use_ok("Arch::Util", "run_tla", "save_file");
16 0         0 use_ok("Arch::Backend", "has_archive_setup_cmd");
17 0         0 use_ok("Arch::TempFiles");
18              
19 0         0 my $tmp = Arch::TempFiles->new;
20 0         0 my $dir = $tmp->dir;
21 0 0 0     0 die "Internal: Arch::TempFiles::dir didn't create dir\n" unless $dir && -d $dir;
22              
23 0         0 $ENV{HOME} = $dir;
24              
25             sub run_tla0 (@) {
26 0     0     my $cmd = "'tla " . join(" ", @_) . "'";
27 0           run_tla(@_);
28 0 0         fail($cmd), die "$cmd failed: $?\n" if $?;
29 0           pass($cmd);
30             }
31              
32 0         0 my $archive = 'arch-perl@example.com--test';
33 0         0 my $userid = 'Arch Perl ';
34              
35 0         0 my $dont_setup = !has_archive_setup_cmd();
36 0         0 my $status;
37              
38 0         0 run_tla0("my-id", $userid);
39 0         0 run_tla0("make-archive $archive $dir/$archive");
40 0 0       0 SKIP: {
41 0         0 skip("this arch backend has no archive-setup", 2) if $dont_setup;
42 0         0 run_tla0("archive-setup $archive/cat--brn--0");
43 0         0 run_tla0("archive-setup $archive/cat--brn--1");
44             }
45              
46 0         0 my $dir2 = "$dir/tree_a";
47 0 0       0 mkdir($dir2, 0777) or die "Can't mkdir $dir2: $!";
48 0 0       0 chdir($dir2) or die "Can't chdir $dir2: $!";
49              
50 0         0 my $session = new Arch::Session;
51 0         0 isa_ok($session, 'Arch::Session', "create Arch::Session instanse");
52 0         0 is($session->my_id, $userid, "read my-id");
53 0         0 is($session->my_id("bad_id"), 0, "set bad my-id");
54 0         0 is($session->my_id, $userid, "read my-id again");
55 0         0 is($session->my_id(''), 1, "set good my-id");
56 0         0 is($session->my_id, '', "read my-id one more time");
57              
58 0         0 my $tree = $session->init_tree("$archive/cat--dog--0.1");
59 0   0     0 ok($tree && ref($tree) eq 'Arch::Tree', "create Arch::Tree instanse");
60              
61 0 0       0 mkdir("foo", 0777) or die "Can't mkdir foo: $!";
62 0         0 save_file("foo/bar", "Just foo bar");
63 0         0 $status = $tree->add("foo", "foo/bar");
64 0         0 is($status, 0, "add 2 files");
65 0         0 $status = $tree->import;
66 0         0 is($status, 0, "import");
67              
68 0         0 $session->working_names($archive);
69 0         0 is($session->working_name, $archive, "working_name");
70 0         0 my $categories = $session->categories;
71 0         0 is(ref($categories), 'ARRAY', " categories");
72 0         0 is(@$categories, 1, " check number");
73 0         0 is($categories->[0], 'cat', " check first element");
74              
75 0 0       0 SKIP: {
76 0         0 skip("this arch backend removed empty branches", 8) if $dont_setup;
77 0         0 $session->working_names($archive, 'cat');
78 0         0 is($session->working_name, "$archive/cat", "working_name");
79 0         0 my $branches = $session->branches;
80 0         0 is(ref($branches), 'ARRAY', " branches");
81 0         0 is(@$branches, 2, " check number");
82 0         0 is($branches->[1], 'cat--dog', " check second element");
83              
84 0         0 $session->working_names($archive, 'cat', 'brn');
85 0         0 is($session->working_name, "$archive/cat--brn", "working_name");
86 0         0 my $versions = $session->versions;
87 0         0 is(ref($versions), 'ARRAY', " versions");
88 0         0 is(@$versions, 2, " check number");
89 0         0 is($versions->[1], "cat--brn--1", " check second element");
90             }
91              
92 0         0 $session->working_names($archive, 'cat', 'dog', '0.1');
93 0         0 is($session->working_name, "$archive/cat--dog--0.1", "working_name");
94 0         0 my $revisions = $session->revisions;
95 0         0 is(ref($revisions), 'ARRAY', " revisions");
96 0         0 is(@$revisions, 1, " check number");
97 0         0 is($revisions->[0], "base-0", " check first element");
98              
99 0         0 ok($session->is_archive_registered($archive), "is_archive_registered");
100 0         0 ok(!$session->is_archive_registered('some@thing--test'), "!is_archive_registered");
101              
102 0         0 is_deeply($session->expanded_revisions, [ "$archive/cat--dog--0.1--base-0" ], "expanded_revisions");
103 0         0 is_deeply($session->expanded_versions, [ "$archive/cat--dog--0.1" ], "expanded_versions");
104              
105             # TODO in tests/session-2:
106             # get_revision_descs, expanded_archive_info, get_log, get_changeset