Skip to content

Commit 86bf942

Browse files
author
Benedikt Artelt
committed
Add test files for adapters
1 parent eb78f5a commit 86bf942

40 files changed

+465
-13
lines changed

spec/lib/junit_adapter_spec.rb

Lines changed: 246 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,262 @@
55
RSpec.describe JunitAdapter do
66
let(:adapter) { described_class.new }
77

8+
89
describe '#parse_output' do
9-
context 'with failed tests' do
10+
11+
context 'CorrectSolution' do
12+
#Initialize data for Testcase 2.1
13+
let(:count) { 42 }
14+
let(:stdout) { "OK (#{count} tests)" }
15+
16+
#Testcase 2.1
17+
it 'returns the correct numbers' do
18+
expect(adapter.parse_output(stdout:)).to eq(count:, passed: count)
19+
end
20+
end
21+
22+
context 'with assertionerrors' do
23+
#Initialize data for Testcase 2.2
1024
let(:count) { 42 }
1125
let(:failed) { 25 }
1226
let(:stdout) { "FAILURES!!!\nTests run: #{count}, Failures: #{failed}" }
27+
let(:stderr) {""}
28+
let(:error_matches) { [] }
29+
1330

31+
#Testcase 2.2
1432
it 'returns the correct numbers' do
15-
expect(adapter.parse_output(stdout:)).to eq(count:, failed:)
33+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
1634
end
1735
end
36+
37+
#From here on compilation errors only (count = failed = 0)
38+
context 'unclosed string literal' do
1839

19-
context 'without failed tests' do
20-
let(:count) { 42 }
21-
let(:stdout) { "OK (#{count} tests)" }
40+
let(:count) {0}
41+
let(:failed) {0}
42+
let(:stdout) {""}
2243

23-
it 'returns the correct numbers' do
24-
expect(adapter.parse_output(stdout:)).to eq(count:, passed: count)
44+
#Initialize data for Testcase 2.3
45+
let(:stderr) { File.read("spec/testcasedatajava/UnclosedStringLiteralTest.txt")}
46+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 6** occured **unclosed string literal** at String s=\"test; "]}
47+
#["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 6** occured **unclosed string literal** at String s=\"test; "]
48+
49+
#Testcase 2.3
50+
it 'unclosed string literal' do
51+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
52+
end
53+
end
54+
55+
context 'illegal start of expression' do
56+
let(:count) {0}
57+
let(:failed) {0}
58+
let(:stdout) {""}
59+
60+
#Initialize data for Testcase 2.4
61+
let(:stderr) { File.read("spec/testcasedatajava/IllegalStartOfExpressionTest.txt")}
62+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 10** occured **illegal start of expression** at private int i=0; "]}
63+
64+
#Testcase 2.4
65+
it 'illegal start of expression' do
66+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
67+
end
68+
end
69+
70+
context 'variable might not have been initialized' do
71+
let(:count) {0}
72+
let(:failed) {0}
73+
let(:stdout) {""}
74+
75+
#Initialize data for Testcase 2.5
76+
let(:stderr) { File.read("spec/testcasedatajava/VariableMightNotHaveBeenInitializedTest.txt")}
77+
let(:error_matches) { ["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 11** occured **variable i might not have been initialized** at i=i+1; "]}
78+
79+
#Testcase 2.5
80+
it 'variable .. might not have been initialized' do
81+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
82+
end
83+
end
84+
85+
context 'not a statement' do
86+
let(:count) {0}
87+
let(:failed) {0}
88+
let(:stdout) {""}
89+
90+
#Initialize data for Testcase 2.6
91+
let(:stderr) { File.read("spec/testcasedatajava/NotAStatementTest.txt")}
92+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 12** occured **not a statement** at \"test\"; "]}
93+
94+
#Testcase 2.6
95+
it 'not a statement' do
96+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
97+
end
98+
end
99+
100+
context 'unexpected type' do
101+
let(:count) {0}
102+
let(:failed) {0}
103+
let(:stdout) {""}
104+
105+
#Initialize data for Testcase 2.7
106+
let(:stderr) { File.read("spec/testcasedatajava/UnexpectedTypeTest.txt")}
107+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 11** occured **unexpected type** at if(1=0){ "]}
108+
109+
#Testcase 2.7
110+
it 'unexpected type' do
111+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
112+
end
113+
end
114+
115+
context 'something expected' do
116+
let(:count) {0}
117+
let(:failed) {0}
118+
let(:stdout) {""}
119+
120+
#Initialize data for Testcase 2.8
121+
let(:stderr) { File.read("spec/testcasedatajava/SomethingExpectedTest.txt")}
122+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 12** occured **';' expected** at return 1/power(base,-exponent) "]}
123+
124+
#Testcase 2.8
125+
it '... expected' do
126+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
127+
end
128+
end
129+
130+
context 'bad operand types' do
131+
let(:count) {0}
132+
let(:failed) {0}
133+
let(:stdout) {""}
134+
135+
#Initialize data for Testcase 2.9
136+
let(:stderr) { File.read("spec/testcasedatajava/BadOperandTypesTest.txt")}
137+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 12** occured **bad operand types for binary operator '+'** at System.out.println(a+b); "]}
138+
139+
#Testcase 2.9
140+
it 'bad operand types ...' do
141+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
142+
end
143+
end
144+
145+
context 'incompatible types' do
146+
let(:count) {0}
147+
let(:failed) {0}
148+
let(:stdout) {""}
149+
150+
#Initialize data for Testcase 2.10
151+
let(:stderr) { File.read("spec/testcasedatajava/IncompatibleTypesTest.txt")}
152+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 12** occured **incompatible types: String cannot be converted to int** at power(a,s); "]}
153+
154+
#Testcase 2.10
155+
it 'incompatible types: ...' do
156+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
157+
end
158+
end
159+
160+
context 'missing return' do
161+
let(:count) {0}
162+
let(:failed) {0}
163+
let(:stdout) {""}
164+
165+
#Initialize data for Testcase 2.11
166+
let(:stderr) { File.read("spec/testcasedatajava/MissingReturnTest.txt")}
167+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 19** occured **missing return statement** at } "]}
168+
169+
#Testcase 2.11
170+
it 'missing return ..' do
171+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
172+
end
173+
end
174+
175+
context 'invalid method declaration' do
176+
let(:count) {0}
177+
let(:failed) {0}
178+
let(:stdout) {""}
179+
180+
#Initialize data for Testcase 2.12
181+
let(:stderr) { File.read("spec/testcasedatajava/InvalidMethodDeclarationTest.txt")}
182+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 19** occured **invalid method declaration; return type required** at public static add(int a,int b){ "]}
183+
184+
#Testcase 2.12
185+
it 'invalid method declaration ...' do
186+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
187+
end
188+
end
189+
190+
context 'unreachable statement' do
191+
let(:count) {0}
192+
let(:failed) {0}
193+
let(:stdout) {""}
194+
195+
#Initialize data for Testcase 2.13
196+
let(:stderr) { File.read("spec/testcasedatajava/UnreachableStatementTest.txt")}
197+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 12** occured **unreachable statement** at System.out.println(\"test\"); "]}
198+
199+
#Testcase 2.13
200+
it 'unreachable statement' do
201+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
202+
end
203+
end
204+
205+
context 'cannot be referenced from a static context' do
206+
let(:count) {0}
207+
let(:failed) {0}
208+
let(:stdout) {""}
209+
210+
#Initialize data for Testcase 2.14
211+
let(:stderr) { File.read("spec/testcasedatajava/CannotBeReferencedFromAStaticContextTest.txt")}
212+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 6** occured **non-static variable field cannot be referenced from a static context** at field = parm; "]}
213+
214+
#Testcase 2.14
215+
it '... cannot be referenced from a static context' do
216+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
217+
end
218+
end
219+
220+
context 'reached end of file while parsing' do
221+
let(:count) {0}
222+
let(:failed) {0}
223+
let(:stdout) {""}
224+
225+
#Initialize data for Testcase 2.15
226+
let(:stderr) { File.read("spec/testcasedatajava/ReachedEndOfFileWhileParsingTest.txt")}
227+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 22** occured **reached end of file while parsing** at } "]}
228+
229+
#Testcase 2.15
230+
it 'reached end of file while parsing' do
231+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
232+
end
233+
end
234+
235+
context 'cannot be applied to' do
236+
let(:count) {0}
237+
let(:failed) {0}
238+
let(:stdout) {""}
239+
240+
#Initialize data for Testcase 2.16
241+
let(:stderr) { File.read("spec/testcasedatajava/CannotBeAppliedToTest.txt")}
242+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 12** occured **method power in class RecursiveMath cannot be applied to given types;** at return 1/power();\n required: int,int\n found: no arguments "]}
243+
244+
#Testcase 2.16
245+
it '... cannot be applied to ...' do
246+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
247+
end
248+
end
249+
250+
context 'cannot find symbol' do
251+
let(:count) {0}
252+
let(:failed) {0}
253+
let(:stdout) {""}
254+
255+
#Initialize data for Testcase 2.17
256+
let(:stderr) { File.read("spec/testcasedatajava/CannotFindSymbolTest.txt")}
257+
let(:error_matches) {["<span style=\"color:red\">**Compilation Error**</span> in **file** ./org/example/RecursiveMath **line 11** occured **cannot find symbol** at System.out.println(i);\n symbol: variable i\n location: class RecursiveMath "]}
258+
259+
#Testcase 2.17
260+
it 'cannot find symbol...' do
261+
expect(adapter.parse_output(stdout: stdout, stderr: stderr)).to eq(count:, failed:, error_messages: error_matches)
25262
end
26263
end
27264
end
28-
end
265+
266+
end

spec/lib/py_unit_adapter_spec.rb

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,51 @@
44

55
RSpec.describe PyUnitAdapter do
66
let(:adapter) { described_class.new }
7-
let(:count) { 42 }
8-
let(:failed) { 25 }
9-
let(:stderr) { "Ran #{count} tests in 0.1s\n\nFAILED (failures=#{failed})" }
107

118
describe '#parse_output' do
12-
it 'returns the correct numbers' do
13-
expect(adapter.parse_output(stderr:)).to eq(count:, failed:)
9+
10+
#Initialize data for Testcase 1.1
11+
let(:count) {2}
12+
let(:failed) {0}
13+
let(:error_matches) {[]}
14+
let(:stderr) { File.read("spec/testcasedata/CorrectSolution.txt")}
15+
16+
#Testcase 1.1
17+
it 'CorrectSolution' do
18+
expect(adapter.parse_output(stderr:)).to eq(count:, failed:, error_messages: error_matches)
19+
end
20+
21+
#Initialize data for Testcase 1.2
22+
let(:count) {2}
23+
let(:failed) {1}
24+
let(:error_matches) {["test_odd: 0 is not true"]}
25+
let(:stderr) { File.read("spec/testcasedata/correctnumber.txt")}
26+
27+
#Testcase 1.2
28+
it 'correct count/failed number' do
29+
expect(adapter.parse_output(stderr:)).to eq(count:, failed:, error_messages: error_matches)
30+
end
31+
32+
#count and failed always 0 for following test cases (tests can't be executed)
33+
let(:count) {0}
34+
let(:failed) {0}
35+
#Initialize data for Testcase 1.3
36+
let(:error_matches) {["<span style=\"color:red\">**SyntaxError**</span>: invalid syntax in **file** /workspace/exercise.py **line 1**"]}
37+
let(:stderr) { File.read("spec/testcasedata/SyntaxErrorTest.txt")}
38+
39+
#Testcase 1.3
40+
it 'SyntaxError' do
41+
expect(adapter.parse_output(stderr:)).to eq(count:, failed:, error_messages: error_matches)
42+
end
43+
44+
#Initialize data for Testcase 1.4
45+
let(:error_matches) {["<span style=\"color:red\">**IndentationError**</span>: expected an indented block in **file** /workspace/exercise.py **line 2**"]}
46+
let(:stderr) { File.read("spec/testcasedata/IndentationErrorTest.txt")}
47+
48+
#Testcase 1.4
49+
it 'IndentationError' do
50+
expect(adapter.parse_output(stderr:)).to eq(count:, failed:, error_messages: error_matches)
1451
end
52+
#TabError not tested at the moment because current codeocean version never raises it
1553
end
1654
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test_even (exercise_tests.ExerciseTests) ... ok
2+
test_odd (exercise_tests.ExerciseTests) ... ok
3+
4+
----------------------------------------------------------------------
5+
Ran 2 tests in 0.000s
6+
7+
OK
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Traceback (most recent call last):
2+
File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
3+
"__main__", mod_spec)
4+
File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
5+
exec(code, run_globals)
6+
File "/usr/lib/python3.4/unittest/__main__.py", line 18, in <module>
7+
main(module=None)
8+
File "/usr/lib/python3.4/unittest/main.py", line 92, in __init__
9+
self.parseArgs(argv)
10+
File "/usr/lib/python3.4/unittest/main.py", line 139, in parseArgs
11+
self.createTests()
12+
File "/usr/lib/python3.4/unittest/main.py", line 146, in createTests
13+
self.module)
14+
File "/usr/lib/python3.4/unittest/loader.py", line 157, in loadTestsFromNames
15+
suites = [self.loadTestsFromName(name, module) for name in names]
16+
File "/usr/lib/python3.4/unittest/loader.py", line 157, in <listcomp>
17+
suites = [self.loadTestsFromName(name, module) for name in names]
18+
File "/usr/lib/python3.4/unittest/loader.py", line 116, in loadTestsFromName
19+
module = __import__('.'.join(parts_copy))
20+
File "/workspace/exercise_tests.py", line 1, in <module>
21+
from exercise import *
22+
File "/workspace/exercise.py", line 2
23+
if(x%2)==0:
24+
^
25+
IndentationError: expected an indented block
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["<span style=\"color:red\">**IndentationError**</span>: expected an indented block in **file** /workspace/exercise.py **line 2**"]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Traceback (most recent call last):
2+
File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
3+
"__main__", mod_spec)
4+
File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
5+
exec(code, run_globals)
6+
File "/usr/lib/python3.4/unittest/__main__.py", line 18, in <module>
7+
main(module=None)
8+
File "/usr/lib/python3.4/unittest/main.py", line 92, in __init__
9+
self.parseArgs(argv)
10+
File "/usr/lib/python3.4/unittest/main.py", line 139, in parseArgs
11+
self.createTests()
12+
File "/usr/lib/python3.4/unittest/main.py", line 146, in createTests
13+
self.module)
14+
File "/usr/lib/python3.4/unittest/loader.py", line 157, in loadTestsFromNames
15+
suites = [self.loadTestsFromName(name, module) for name in names]
16+
File "/usr/lib/python3.4/unittest/loader.py", line 157, in <listcomp>
17+
suites = [self.loadTestsFromName(name, module) for name in names]
18+
File "/usr/lib/python3.4/unittest/loader.py", line 116, in loadTestsFromName
19+
module = __import__('.'.join(parts_copy))
20+
File "/workspace/exercise_tests.py", line 1, in <module>
21+
from exercise import *
22+
File "/workspace/exercise.py", line 1
23+
ef even(x):
24+
^
25+
SyntaxError: invalid syntax
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["<span style=\"color:red\">**SyntaxError**</span>: invalid syntax in **file** /workspace/exercise.py **line 1**"]

0 commit comments

Comments
 (0)