@@ -47,6 +47,7 @@ public class RunTests extends UserRequest<Object> {
4747 private final Optional <String > testName ;
4848 private final int timeoutSeconds ;
4949 private final Optional <String > testFilter ;
50+ private final boolean compactOutput ;
5051
5152 private final List <ImFunction > successTests = Lists .newArrayList ();
5253 private final List <TestFailure > failTests = Lists .newArrayList ();
@@ -98,12 +99,17 @@ public RunTests(Optional<String> filename, int line, int column, Optional<String
9899 }
99100
100101 public RunTests (Optional <String > filename , int line , int column , Optional <String > testName , int timeoutSeconds , Optional <String > testFilter ) {
102+ this (filename , line , column , testName , timeoutSeconds , testFilter , false );
103+ }
104+
105+ public RunTests (Optional <String > filename , int line , int column , Optional <String > testName , int timeoutSeconds , Optional <String > testFilter , boolean compactOutput ) {
101106 this .filename = filename .map (WFile ::create );
102107 this .line = line ;
103108 this .column = column ;
104109 this .testName = testName ;
105110 this .timeoutSeconds = timeoutSeconds ;
106111 this .testFilter = testFilter ;
112+ this .compactOutput = compactOutput ;
107113 }
108114
109115
@@ -175,7 +181,7 @@ public TestResult runTests(ImTranslator translator, ImProg imProg, Optional<Func
175181
176182 if (gui .getErrorCount () > 0 ) {
177183 for (CompileError compileError : gui .getErrorList ()) {
178- println (compileError .toString ());
184+ println (compactOutput ? compileError . toCompactString () : compileError .toString ());
179185 }
180186 println ("There were some problem while running compiletime expressions and functions." );
181187 return new TestResult (0 , 1 );
@@ -196,7 +202,7 @@ public TestResult runTests(ImTranslator translator, ImProg imProg, Optional<Func
196202 }
197203 if (matched .isEmpty ()) {
198204 println ("No tests match filter '" + testFilter .get () + "'." );
199- } else {
205+ } else if (! compactOutput ) {
200206 println ("Filter '" + testFilter .get () + "' matched " + matched .size () + " test(s):" );
201207 for (String name : matched ) {
202208 println (" " + name );
@@ -228,7 +234,9 @@ public TestResult runTests(ImTranslator translator, ImProg imProg, Optional<Func
228234 WPos source = f .attrTrace ().attrSource ();
229235 String file = new File (source .getFile ()).toPath ().normalize ().toString ();
230236 String message = "Running " + file + ":" + source .getLine () + " - " + f .getName () + ".." ;
231- println (message );
237+ if (!compactOutput ) {
238+ println (message );
239+ }
232240 WLogger .info (message );
233241
234242 try {
@@ -253,59 +261,95 @@ public TestResult runTests(ImTranslator translator, ImProg imProg, Optional<Func
253261
254262 if (gui .getErrorCount () > 0 ) {
255263 StringBuilder sb = new StringBuilder ();
264+ int appendedErrors = 0 ;
256265 for (CompileError error : gui .getErrorList ()) {
257- sb .append (error ).append ("\n " );
258- println (error .getMessage ());
266+ if (compactOutput ) {
267+ if (appendedErrors >= 3 ) {
268+ continue ;
269+ }
270+ if (sb .length () > 0 ) {
271+ sb .append ("; " );
272+ }
273+ sb .append (error .toCompactString ());
274+ appendedErrors ++;
275+ } else {
276+ sb .append (error ).append ("\n " );
277+ }
278+ if (!compactOutput ) {
279+ println (error .getMessage ());
280+ }
281+ }
282+ if (compactOutput && gui .getErrorCount () > appendedErrors ) {
283+ sb .append ("; +" ).append (gui .getErrorCount () - appendedErrors ).append (" more" );
259284 }
260285 gui .clearErrors ();
261286 TestFailure failure = new TestFailure (f , interpreter .getStackFrames (), sb .toString ());
262287 failTests .add (failure );
263288 } else {
264289 successTests .add (f );
265- println ("\t OK!" );
290+ if (!compactOutput ) {
291+ println ("\t OK!" );
292+ }
266293 }
267294 } catch (TestSuccessException e ) {
268295 successTests .add (f );
269- println ("\t OK!" );
296+ if (!compactOutput ) {
297+ println ("\t OK!" );
298+ }
270299 } catch (TestFailException e ) {
271300 TestFailure failure = new TestFailure (f , interpreter .getStackFrames (), e .getMessage ());
272301 failTests .add (failure );
273- println ("\t FAILED assertion:" );
274- println ("\t " + failure .getMessageWithStackFrame ());
302+ if (!compactOutput ) {
303+ println ("\t FAILED assertion:" );
304+ println ("\t " + failure .getMessageWithStackFrame ());
305+ }
275306 } catch (TestTimeOutException e ) {
276307 failTests .add (new TestFailure (f , interpreter .getStackFrames (), e .getMessage ()));
277- println ("\t FAILED - TIMEOUT (This test did not complete in " + timeoutSeconds + " seconds, it might contain an endless loop)" );
278- println (interpreter .getStackFrames ().toString ());
308+ if (!compactOutput ) {
309+ println ("\t FAILED - TIMEOUT (This test did not complete in " + timeoutSeconds + " seconds, it might contain an endless loop)" );
310+ println (interpreter .getStackFrames ().toString ());
311+ }
279312 } catch (InterpreterException e ) {
280313 TestFailure failure = new TestFailure (f , interpreter .getStackFrames (), e .getMessage ());
281314 failTests .add (failure );
282- println ("\t " + failure .getMessageWithStackFrame ());
315+ if (!compactOutput ) {
316+ println ("\t " + failure .getMessageWithStackFrame ());
317+ }
283318 } catch (Throwable e ) {
284319 failTests .add (new TestFailure (f , interpreter .getStackFrames (), e .toString ()));
285- println ("\t FAILED with exception: " + e .getClass () + " " + e .getLocalizedMessage ());
286- println (interpreter .getStackFrames ().toString ());
287- println ("Here are some compiler internals, that might help Wurst developers to debug this issue:" );
288- StringWriter sw = new StringWriter ();
289- PrintWriter pw = new PrintWriter (sw );
290- e .printStackTrace (pw );
291- String sStackTrace = sw .toString ();
292- println ("\t " + e .getLocalizedMessage ());
293- println ("\t " + sStackTrace );
320+ if (!compactOutput ) {
321+ println ("\t FAILED with exception: " + e .getClass () + " " + e .getLocalizedMessage ());
322+ println (interpreter .getStackFrames ().toString ());
323+ println ("Here are some compiler internals, that might help Wurst developers to debug this issue:" );
324+ StringWriter sw = new StringWriter ();
325+ PrintWriter pw = new PrintWriter (sw );
326+ e .printStackTrace (pw );
327+ String sStackTrace = sw .toString ();
328+ println ("\t " + e .getLocalizedMessage ());
329+ println ("\t " + sStackTrace );
330+ }
294331 }
295332 }
296333 }
297334 } // Scheduler is automatically shut down here
298335
299- println ("Tests succeeded: " + successTests .size () + "/" + (successTests .size () + failTests .size ()));
300- if (failTests .size () == 0 ) {
301- println (">> All tests have passed successfully!" );
336+ if (compactOutput ) {
337+ println ("Tests: " + successTests .size () + "/" + (successTests .size () + failTests .size ()) + " passed" );
338+ for (TestFailure failure : failTests ) {
339+ println ("FAILED " + qualifiedTestName (failure .getFunction ()));
340+ }
302341 } else {
303- println (">> " + failTests .size () + " Tests have failed!" );
342+ println ("Tests succeeded: " + successTests .size () + "/" + (successTests .size () + failTests .size ()));
343+ if (failTests .size () == 0 ) {
344+ println (">> All tests have passed successfully!" );
345+ } else {
346+ println (">> " + failTests .size () + " Tests have failed!" );
347+ }
304348 }
305349 if (gui .getErrorCount () > 0 ) {
306350 println ("There were some errors reported while running the tests." );
307351 for (CompileError error : gui .getErrorList ()) {
308- println (error .toString ());
352+ println (compactOutput ? error . toCompactString () : error .toString ());
309353 }
310354 }
311355
@@ -319,21 +363,28 @@ private void redirectInterpreterOutput(ProgramState globalState) {
319363
320364 @ Override
321365 public void write (int b ) throws IOException {
322- if (b > 0 ) {
366+ if (! compactOutput && b > 0 ) {
323367 println ("" + (char ) b );
324368 }
325369 }
326370
327371 @ Override
328372 public void write (byte [] b , int off , int len ) throws IOException {
329- println (new String (b , off , len ));
373+ if (!compactOutput ) {
374+ println (new String (b , off , len ));
375+ }
330376 }
331377
332378
333379 };
334380 globalState .setOutStream (new PrintStream (os ));
335381 }
336382
383+ private String qualifiedTestName (ImFunction f ) {
384+ String packageName = f .attrTrace ().attrNearestPackage ().tryGetNameDef ().getName ();
385+ return packageName + "." + f .getName ();
386+ }
387+
337388 protected void println (String message ) {
338389 print (message );
339390 print (System .lineSeparator ());
0 commit comments