/
lizard_spec.rb
271 lines (235 loc) 路 9.21 KB
/
lizard_spec.rb
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
describe Fastlane::Actions::LizardAction do
describe 'Lizard' do
let(:output_file) { "lizard.result.json" }
let(:folder) { "assets" }
let(:language) { "java" }
let(:multiple_languages) { " java, swift,objectivec" }
let(:expected_multiple_language_options) { "-l java -l swift -l objectivec" }
let(:ccn) { 10 }
let(:length) { 800 }
let(:working_threads) { 3 }
let(:custom_executable) { "../spec/fixtures/lizard.py" }
let(:outdated_executable) { "../spec/fixtures/outdated_lizard.py" }
let(:newer_executable) { "../spec/fixtures/newer_lizard.py" }
let(:wrong_executable) { "../spec/fixtures" }
context "executable" do
it "fails with invalid sourcemap path" do
sourcemap_path = File.absolute_path '../no/such/lizard.py'
expect do
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '#{sourcemap_path}'
)
end").runner.execute(:test)
end.to raise_error("The custom executable at '#{sourcemap_path}' does not exist.")
end
end
context "required version" do
it "should not raise if executable version is same as required" do
expect(FastlaneCore::UI).to_not(receive(:user_error!))
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '#{custom_executable}'
)
end").runner.execute(:test)
end
it "should not raise if executable version is newer than required" do
expect(FastlaneCore::UI).to_not(receive(:user_error!))
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '#{newer_executable}'
)
end").runner.execute(:test)
end
it "should raise if executable is wrong" do
expect(FastlaneCore::UI).to receive(:user_error!).with(/You need to point to the executable to lizard.py file\!/).and_call_original
expect do
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '#{wrong_executable}'
)
end").runner.execute(:test)
end.to raise_error(/You need to point to the executable to lizard.py file\!/)
end
it "should raise if executable version is less than required" do
expect(FastlaneCore::UI).to receive(:user_error!).with(/Your lizard version .* is outdated, please upgrade to at least version .* and start your lane again\!/).and_call_original
expect do
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '#{outdated_executable}'
)
end").runner.execute(:test)
end.to raise_error(/Your lizard version .* is outdated, please upgrade to at least version .* and start your lane again\!/)
end
end
context "default use case" do
it "default language as swift" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard
end").runner.execute(:test)
expect(result).to eq("lizard -l swift")
end
end
context "when specify custom executable" do
it "uses custom executable" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '#{custom_executable}'
)
end").runner.execute(:test)
expect(result).to eq("python #{custom_executable} -l swift")
end
it "should raise if custom executable does not exist" do
expect do
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: 'no/such/file/lizard.py'
)
end").runner.execute(:test)
end.to raise_error("The custom executable at 'no/such/file/lizard.py' does not exist.")
end
end
context "when specify export_type as XML" do
it "prints out XML as stdout" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
export_type: 'xml'
)
end").runner.execute(:test)
expect(result).to eq("lizard -l swift --xml")
end
end
context "when specify export_type as HTML" do
it "prints out HTML as stdout" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
export_type: 'html'
)
end").runner.execute(:test)
expect(result).to eq("lizard -l swift --html")
end
end
context "when specify export_type as CSV" do
it "prints out CSV as stdout" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
export_type: 'csv'
)
end").runner.execute(:test)
expect(result).to eq("lizard -l swift --csv")
end
end
context "when specify folder to scan" do
it "states the source folder" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
source_folder: '#{folder}'
)
end").runner.execute(:test)
expect(result).to eq("lizard -l swift #{folder}")
end
end
context "when specify language to scan" do
it "overrides swift default language" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
language: '#{language}'
)
end").runner.execute(:test)
expect(result).to eq("lizard -l #{language}")
end
end
context "when specify multiple languages to scan" do
it "states all specified languages" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
language: '#{multiple_languages}'
)
end").runner.execute(:test)
expect(result).to eq("lizard #{expected_multiple_language_options}")
end
end
context "when specify code complexity number" do
it "overrides default 15" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
ccn: #{ccn}
)
end").runner.execute(:test)
expect(result).to eq("lizard -l swift -C #{ccn}")
end
end
context "when specify maximum function length warning" do
it "overrides default 1000" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
length: #{length}
)
end").runner.execute(:test)
expect(result).to eq("lizard -l swift -L #{length}")
end
end
context "when specify number of working threads" do
it "overrides default single thread" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
working_threads: #{working_threads}
)
end").runner.execute(:test)
expect(result).to eq("lizard -l swift -t #{working_threads}")
end
end
context "the `ignore_exit_status` option" do
context "by default" do
it 'should raise if lizard completes with a non-zero exit status' do
allow(FastlaneCore::UI).to receive(:important)
expect(FastlaneCore::UI).to receive(:important).with(/If you want fastlane to continue anyway/)
# This is simulating the exception raised if the return code is non-zero
expect(Fastlane::Actions).to receive(:sh).and_raise("fake error")
expect(FastlaneCore::UI).to receive(:user_error!).with(/Lizard finished with errors/).and_call_original
expect do
Fastlane::FastFile.new.parse("lane :test do
lizard
end").runner.execute(:test)
end.to raise_error(/Lizard finished with errors/)
end
end
context "when enabled" do
it 'should not raise if lizard completes with a non-zero exit status' do
allow(FastlaneCore::UI).to receive(:important)
expect(FastlaneCore::UI).to receive(:important).with(/fastlane will continue/)
# This is simulating the exception raised if the return code is non-zero
expect(Fastlane::Actions).to receive(:sh).and_raise("fake error")
expect(FastlaneCore::UI).to_not(receive(:user_error!))
Fastlane::FastFile.new.parse("lane :test do
lizard(ignore_exit_status: true)
end").runner.execute(:test)
end
end
context "when disabled" do
it 'should raise if lizard completes with a non-zero exit status' do
allow(FastlaneCore::UI).to receive(:important)
expect(FastlaneCore::UI).to receive(:important).with(/If you want fastlane to continue anyway/)
# This is simulating the exception raised if the return code is non-zero
expect(Fastlane::Actions).to receive(:sh).and_raise("fake error")
expect(FastlaneCore::UI).to receive(:user_error!).with(/Lizard finished with errors/).and_call_original
expect do
Fastlane::FastFile.new.parse("lane :test do
lizard(ignore_exit_status: false)
end").runner.execute(:test)
end.to raise_error(/Lizard finished with errors/)
end
end
end
context "when specify report_file options" do
it "adds redirect file to command" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
report_file: '#{output_file}'
)
end").runner.execute(:test)
expect(result).to eq("lizard -l swift > #{output_file}")
end
end
end
end