55RSpec . 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!!!\n Tests 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
0 commit comments