-
Notifications
You must be signed in to change notification settings - Fork 56
/
stubs.t
133 lines (106 loc) · 3.48 KB
/
stubs.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use v6;
use Test;
use Test::Mock;
use Pies;
plan 18;
my $dep = Pies::Project.new(
name => 'dep',
dependencies => <nesteddep>,
);
my $nesteddep = Pies::Project.new(
name => 'nesteddep',
dependencies => [],
);
my $proj = Pies::Project.new(
name => 'dummy',
dependencies => <dep>,
);
class DummyEco does Pies::Ecosystem {
has %.projects;
has %.states;
method add-project(Pies::Project $p) {
%.projects{$p.name} = $p;
%.states{$p.name} = 'absent';
}
method get-project($p as Str) {
return %.projects{$p};
}
method project-set-state(Pies::Project $p, Pies::Project::State $s) {
%.states{$p.name} = $s;
}
method project-get-state(Pies::Project $p) {
return %.states{$p.name};
}
}
class DummyFetcher does Pies::Fetcher {
method fetch(Pies::Project $a) {
Bool::True
}
}
class DummyBuilder does Pies::Builder {
method build(Pies::Project $a) {
Bool::True
}
}
class DummyTester does Pies::Tester {
method test(Pies::Project $a) {
Bool::True
}
}
class DummyInstaller does Pies::Installer {
method install(Pies::Project $a) {
Bool::True
}
}
my $eco = DummyEco.new;
$eco.add-project($proj);
$eco.add-project($dep);
$eco.add-project($nesteddep);
my $f = mocked(DummyFetcher);
my $b = mocked(DummyBuilder);
my $t = mocked(DummyTester);
my $i = mocked(DummyInstaller);
my $p = Pies.new(
ecosystem => $eco,
fetcher => $f,
builder => $b,
tester => $t,
installer => $i,
);
is $p.ecosystem.project-get-state($proj), 'absent',
'state before resolving ok 1';
is $p.ecosystem.project-get-state($dep), 'absent',
'state before resolving ok 2';
is $p.ecosystem.project-get-state($nesteddep), 'absent',
'state before resolving ok 3';
$p.resolve($proj.name);
is $p.ecosystem.project-get-state($proj), 'installed',
'state after resolving ok 1';
is $p.ecosystem.project-get-state($dep), 'installed-dep',
'state after resolving ok 2';
is $p.ecosystem.project-get-state($nesteddep), 'installed-dep',
'state after resolving ok 3';
$p.ecosystem.project-set-state($proj, 'absent');
$p.ecosystem.project-set-state($dep, 'absent');
$p.ecosystem.project-set-state($nesteddep, 'absent');
$p.resolve($proj.name, :nodeps);
is $p.ecosystem.project-get-state($proj), 'installed',
'state after nodeps ok 1';
is $p.ecosystem.project-get-state($dep), 'absent',
'state after nodeps ok 2';
is $p.ecosystem.project-get-state($nesteddep), 'absent',
'state after nodeps ok 3';
# makes sure that Pies actually uses our ecosystem, not modifies its
# own, internal copy
is $eco.project-get-state($proj), 'installed',
'same state in our object';
check-mock($f, *.called('fetch', times => 4));
check-mock($b, *.called('build', times => 4));
check-mock($t, *.called('test', times => 4));
check-mock($i, *.called('install', times => 4));
$p.resolve($proj.name, :notests);
check-mock($f, *.called('fetch', times => 7));
check-mock($b, *.called('build', times => 7));
check-mock($t, *.called('test', times => 4));
check-mock($i, *.called('install', times => 7));
# vim: ft=perl6