-
Notifications
You must be signed in to change notification settings - Fork 3
/
42-cli.rakutest
169 lines (148 loc) · 4.74 KB
/
42-cli.rakutest
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
use Test;
use lib 'lib';
use lib 't/lib';
need App::Racoco::Cli;
use Fixture;
use App::Racoco::Paths;
use App::Racoco::X;
use TestResources;
use TestHelper;
plan 17;
constant &APP_MAIN = &App::Racoco::Cli::MAIN;
my ($sources, $lib);
sub setup($lib-name = 'lib') {
plan $*plan;
TestResources::prepare($*subtest);
$sources = TestResources::exam-directory;
$lib = $sources.add($lib-name);
}
sub do-main(&bloc) {
Fixture::silently({ indir($sources, &bloc) });
}
'01-lib-not-exists'.&test(:1plan, {
setup();
do-main({
throws-like { APP_MAIN(lib => 'not-exists') }, App::Racoco::X::WrongLibPath,
'MAIN with wrong lib ok', message => /'not-exists'/;
});
});
'02-wrong-raku-bin-dir'.&test(:2plan, {
setup();
do-main({
throws-like { APP_MAIN(raku-bin-dir => 'not-exists') },
App::Racoco::X::WrongRakuBinDirPath,
'MAIN with wrong raku bin dir ok', message => /'not-exists'/;
throws-like { APP_MAIN(raku-bin-dir => 'lib') },
App::Racoco::X::WrongRakuBinDirPath,
'MAIN with empty raku bin dir ok', message => /'lib'/;
});
});
'03-lib-with-no-precomp-lives-ok'.&test(:1plan, {
setup();
do-main({
lives-ok { APP_MAIN(lib => 'no-precomp', :silent) }, 'lives with no precomp';
});
});
'04-simple-run'.&test(:2plan, {
setup();
my $captured = do-main({
APP_MAIN(:silent);
});
is $captured.out.text.trim, 'Coverage: 75%', 'simple run ok';
nok coverage-log-path(:$lib).e, 'coverage.log deleted';
});
'05-with-raku-bin-dir'.&test(:1plan, {
setup();
my $captured = do-main({
APP_MAIN(lib => 'lib', raku-bin-dir => $*EXECUTABLE.parent.Str, :silent);
});
is $captured.out.text.trim, 'Coverage: 75%', 'pass lib and raku-bin-dir';
});
'06-pass-exec'.&test(:1plan, {
setup();
my $captured = do-main({
APP_MAIN(exec => 'echo "foo"', :silent);
});
is $captured.out.text.trim, 'Coverage: 0%', 'pass exec';
});
'07-no-exec-and-no-report-fail'.&test(:1plan, {
setup();
do-main({
throws-like { APP_MAIN(:!exec) }, App::Racoco::X::CannotReadReport,
'no report, exception', message => /'lib'/;
});
});
'08-append'.&test(:2plan, {
setup();
my $captured = do-main({
APP_MAIN(:silent);
APP_MAIN(:append, exec => 'prove6 xt', :silent);
});
is $captured.out.text.lines.join, "Coverage: 20%Coverage: 60%", 'pass append';
nok coverage-log-path(:$lib).e, 'coverage.log deleted';
});
'09-two-precomp-ok'.&test(:1plan, {
setup();
do-main({ lives-ok { APP_MAIN(:silent) }, 'works with two precomp' });
});
'10-custom-reporter'.&test(:1plan, {
setup();
my $captured = do-main({ APP_MAIN(:silent, reporter => 'custom-one') });
is $captured.out.text.trim.lines.join('|'), 'Coverage: 75%|CustomOne: 75%',
'custom-one reporter';
});
'11-two-custom-reporters'.&test(:1plan, {
setup();
my $captured = do-main({ APP_MAIN(:silent, reporter => 'custom-one,two') });
is $captured.out.text.trim.lines.join('|'), 'Coverage: 75%|CustomOne: 75%|Done',
'two custom reporters';
});
'12-not-exists-reporter'.&test(:2plan, {
setup();
my $captured = do-main({ APP_MAIN(:silent, reporter => 'not-exists,two') });
is $captured.err.text.trim, 'Cannot use App::Racoco::Report::ReporterNotExists package as reporter.',
'second reporter works';
is $captured.out.text.trim.lines.join('|'), 'Coverage: 75%|Done',
'not-exist-reporter';
});
'13-pass-html'.&test(:3plan, {
setup();
my $captured = do-main({
APP_MAIN(:reporter<html>, :silent);
});
ok report-html-path(:$lib).e, 'ok html';
ok $captured.out.text.contains(report-html-path(:$lib)), 'pass html';
ok report-html-data-path(:$lib).dir()[0].slurp ~~ /'color-blind'/, 'no color-blind';
});
'14-pass-html-color-blind'.&test(:3plan, {
setup();
my $captured = do-main({
APP_MAIN(:reporter<html-color-blind>, :silent);
});
ok report-html-path(:$lib).e, 'ok html';
ok $captured.out.text.contains(report-html-path(:$lib)), 'pass html';
nok report-html-data-path(:$lib).dir()[0].slurp ~~ /'color-blind'/, 'color-blind';
});
'15-with-command-line-properties'.&test(:1plan, {
setup();
my $captured = do-main({ APP_MAIN(:silent, reporter => 'custom-three', properties => 'command-line:pass') });
is $captured.out.text.trim.lines.join('|'), 'Coverage: 75%|CustomThree: pass',
'properties from command-line';
});
'16-with-config-file-properties'.&test(:1plan, {
setup();
my $captured = do-main({ APP_MAIN(:silent) });
is $captured.out.text.trim.lines.join('|'), 'Coverage: 75%|CustomThree: pass',
'properties from config';
});
'17-module-with-no-precompilation'.&test(:2plan, {
setup();
my $captured = do-main({
APP_MAIN(:silent);
});
is $captured.err.text.trim, '', 'no error';
is $captured.out.text.trim.lines.join(' '), 'Module.rakumod cannot be precompiled. ' ~
'Coverage results may be inaccurate. Coverage: 75%', 'warn and inaccurate';
say 'sbsdfsf';
});
done-testing