forked from masak/proto
/
install-with-test.t
181 lines (157 loc) · 7.12 KB
/
install-with-test.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use v6;
use Test;
use App::Pls;
my %projects =
uninstalled => { :state<tested> },
"won't-install" => { :state<tested> },
untested => { :state<built> },
"won't-test" => { :state<built> },
unbuilt => { :state<fetched> },
"won't-build" => { :state<fetched> },
"won't-test-2" => { :state<fetched> },
unfetched => {},
"won't-fetch" => {},
"won't-build-2" => {},
"won't-test-3" => {},
"has-deps" => { :state<fetched>, :deps<A B> },
A => { :state<installed> },
B => { :state<built>, :deps<C D> },
C => {},
D => { :state<built> },
"circ-deps" => { :state<tested>, :deps<E> },
E => { :state<tested>, :deps<circ-deps> },
"dirdep-fails" => { :state<tested>, :deps<won't-install> }, #'
"indir-fails" => { :state<tested>, :deps<dirdep-fails> },
;
my @actions;
class Mock::Fetcher does App::Pls::Fetcher {
method fetch($project --> Result) {
push @actions, "fetch[$project<name>]";
return failure
if $project<name> eq "won't-fetch";
return success;
}
}
class Mock::Builder does App::Pls::Builder {
method build($project --> Result) {
push @actions, "build[$project<name>]";
return failure
if $project<name> ~~ /^ won\'t\-build/;
return success;
}
}
class Mock::Tester does App::Pls::Tester {
method test($project --> Result) {
push @actions, "test[$project<name>]";
return failure
if $project<name> ~~ /^ won\'t\-test/;
return success;
}
}
class Mock::Installer does App::Pls::Installer {
method install($project --> Result) {
push @actions, "install[$project<name>]";
return failure
if $project<name> eq "won't-install";
return success;
}
}
my $core = App::Pls::Core.new(
:projects(App::Pls::ProjectsState::Hash.new(:%projects)),
:ecosystem(App::Pls::Ecosystem::Hash.new(:%projects)),
:fetcher(Mock::Fetcher.new()),
:builder(Mock::Builder.new()),
:tester(Mock::Tester.new()),
:installer(Mock::Installer.new()),
);
plan 51;
given $core {
# [T] Install a tested project: Succeed.
is .state-of("uninstalled"), 'tested', "State before: 'tested'";
is .install(<uninstalled>), success, "Install of tested project succeeded";
is .state-of("uninstalled"), 'installed', "State after: 'installed'";
# [T] Install a tested project whose install fails: Fail.
is .state-of("won't-install"), 'tested', "State before: 'tested'";
is .install(<won't-install>), failure, "An install that fails"; #'
is .state-of("won't-install"), 'tested', "State after: unchanged";
# [T] Install an untested project: Test, install.
@actions = ();
is .state-of("untested"), 'built', "State before: 'built'";
is .install(<untested>), success, "Test, then install succeeds.";
is ~@actions, 'test[untested] install[untested]', "Correct order";
is .state-of("untested"), 'installed', "State after: 'installed'";
# [T] Install an untested project; testing fails. Fail.
@actions = ();
is .install(<won't-test>), failure, "Testing fails, won't install"; #"
is ~@actions, "test[won't-test]", "Tested, didn't install";
is .state-of("won't-test"), 'built', "State after: unchanged";
# [T] Install an unbuilt project: Build, test, install.
@actions = ();
is .install(<unbuilt>), success, "Build, test, install";
is ~@actions, 'build[unbuilt] test[unbuilt] install[unbuilt]',
"Order is correct";
is .state-of("unbuilt"), 'installed', "State after: 'installed'";
# [T] Install an unbuilt project; build fails. Fail.
@actions = ();
is .install(<won't-build>), failure, "Build fails, won't install"; #"
is ~@actions, "build[won't-build]", "Didn't try to install";
is .state-of("won't-build"), 'fetched', "State after: unchanged";
# [T] Install an unbuilt project; testing fails. Fail.
@actions = ();
is .install(<won't-test-2>), failure, "Testing fails, won't install"; #"
is ~@actions, "build[won't-test-2] test[won't-test-2]",
"Built and tested, but didn't try to install";
is .state-of("won't-test-2"), 'built', "State after: 'built'";
# [T] Install an unfetched project: Fetch, build, test, install.
@actions = ();
is .install(<unfetched>), success, "Fetch, build, test, install";
is ~@actions,
'fetch[unfetched] build[unfetched] test[unfetched] install[unfetched]',
"Correct order";
is .state-of("unfetched"), 'installed', "State after: 'installed'";
# [T] Install an unfetched project; fetch fails. Fail.
@actions = ();
is .install(<won't-fetch>), failure, "Fetching fails, won't install"; #"
is ~@actions, "fetch[won't-fetch]", "Tried to fetch, not build etc";
is .state-of("won't-fetch"), 'absent', "State after: unchanged";
# [T] Install an unfetched project; build fails. Fail.
@actions = ();
is .install(<won't-build-2>), failure, "Build fails, won't install"; #"
is ~@actions, "fetch[won't-build-2] build[won't-build-2]",
"Tried to fetch and build, not test etc";
is .state-of("won't-build-2"), 'fetched', "State after: 'fetched'";
# [T] Install an unfetched project; testing fails. Fail.
@actions = ();
is .install(<won't-test-3>), failure, "Test fails, won't install"; #"
is ~@actions, "fetch[won't-test-3] build[won't-test-3] test[won't-test-3]",
"Tried to fetch, build and test, not install";
is .state-of("won't-test-3"), 'built', "State after: 'built'";
# [T] Install a project with dependencies: Install dependencies too.
@actions = ();
is .install(<has-deps>), success, "Install a project with dependencies";
is ~@actions, 'fetch[C] build[C] build[has-deps] '
~ 'test[C] test[D] test[B] test[has-deps] '
~ 'install[C] install[D] install[B] install[has-deps]',
"fetch, build, test and install (all postorder and by need)";
is .state-of("has-deps"), 'installed',
"State after of has-deps: 'installed'";
for <A B C D> -> $dep {
is .state-of($dep), 'installed', "State after of $dep: 'installed'";
}
# [T] Install a project with circular dependencies: Fail.
@actions = ();
is .install(<circ-deps>), failure, "Circular dependency install: fail";
is ~@actions, '', "Nothing was done";
is .state-of("circ-deps"), 'tested', "State after of circ-deps: unchanged";
is .state-of("E"), 'tested', "State after of E: unchanged";
# [T] Install a project whose direct dependency fails: Fail.
@actions = ();
is .install(<dirdep-fails>), failure, "Direct dependency fails: fail";
is ~@actions, "install[won't-install]", "Still, an install was attempted";
is .state-of("won't-install"), 'tested', "State after: unchanged";
# [T] Install a project whose indirect dependency fails: Fail.
@actions = ();
is .install(<indir-fails>), failure, "Indirect dependency fails: fail";
is ~@actions, "install[won't-install]", "Still, an install was attempted";
is .state-of("won't-install"), 'tested', "State after: unchanged";
}