diff --git a/core/src/main/java/ship/build/ConsoleServer.java b/core/src/main/java/ship/build/ConsoleServer.java index a5ec3e3..2e3c702 100644 --- a/core/src/main/java/ship/build/ConsoleServer.java +++ b/core/src/main/java/ship/build/ConsoleServer.java @@ -102,7 +102,11 @@ protected void print(final TestReportNode node) { if (node.isSuccess()) { printer.println(NL_4, node.getName()); } else { - printer.println(NL_5, node.getName()); + Object detail = node.getResultDetail(); + if (detail == null) { + detail = ""; + } + printer.println(NL_5, node.getName(), detail); } node.getChildren().forEach(child -> this.printSuite((TestReportNode) child)); } diff --git a/core/src/main/java/ship/command/TestProject.java b/core/src/main/java/ship/command/TestProject.java index 0707ef3..3b0db04 100644 --- a/core/src/main/java/ship/command/TestProject.java +++ b/core/src/main/java/ship/command/TestProject.java @@ -91,18 +91,17 @@ protected void executeTest(final Builder builder, final String testPath) { testReporter.start(testPath); final TestResult testResult = new LuaRunner().run(executable); final TestReportNode testFile = testReporter.getCurrentTestFile(); - if (!testResult.isSuccess()) { - logger.info("{} failed", testFile.getName()); - testFile.setResult(TestReportNodeResult.Failure); - testFile.setResultDetail(testResult.getError()); - } - - logger.debug("Test {} => {}", testPath, testResult); + logger.debug("Test result for {} => {}", testPath, testResult); if (!testResult.isSuccess()) { final LuaErrorInformation error = testResult.getError(); final int lineNumber = error.getLineNumber(); - logger.debug("Lua Script:\n{}", - executable.toString(lineNumber - 5, lineNumber + 5, singletonList(lineNumber))); + String snippet = executable.toString(lineNumber - 5, lineNumber + 5, + singletonList(lineNumber)); + error.setCodeSnippet(snippet.replaceAll("(?m)^", " ")); + logger.info("Test failure at {}:{}\n{}", + testPath, error.toString(), snippet); + testFile.setResult(TestReportNodeResult.Failure); + testFile.setResultDetail(error); } testReporter.end(); } diff --git a/core/src/main/java/ship/test/LuaErrorInformation.java b/core/src/main/java/ship/test/LuaErrorInformation.java index bc9c15f..b36acca 100644 --- a/core/src/main/java/ship/test/LuaErrorInformation.java +++ b/core/src/main/java/ship/test/LuaErrorInformation.java @@ -5,6 +5,7 @@ package ship.test; import lombok.Getter; +import lombok.Setter; public class LuaErrorInformation { @@ -17,6 +18,10 @@ public class LuaErrorInformation { @Getter protected final int columnNumber; + @Getter + @Setter + protected String codeSnippet; + /** * Constructor with not parsed error message. *

@@ -50,6 +55,10 @@ public LuaErrorInformation(final String message, final int lineNumber, final int @Override public String toString() { - return lineNumber + ":" + columnNumber + " - Message: " + message; + String s = lineNumber + ":" + columnNumber + " - Message: " + message; + if (this.codeSnippet != null) { + s += "\n" + this.codeSnippet; + } + return s; } } diff --git a/core/src/main/resources/message.properties b/core/src/main/resources/message.properties index 1178860..d79985b 100644 --- a/core/src/main/resources/message.properties +++ b/core/src/main/resources/message.properties @@ -4,11 +4,11 @@ ship.build.ConsoleServer.1= SUCCESS ERROR! {0}{1} ship.build.ConsoleServer.3= TEST FAILURE! {0}{1} ship.build.ConsoleServer.4=\ P {0} -ship.build.ConsoleServer.5=\ F {0} +ship.build.ConsoleServer.5=\ F {0} {1} ship.build.ConsoleServer.6=\ * {0}({1} / {2}) ship.build.ConsoleServer.7=\ * {0}({1} / {2}) ship.build.ConsoleServer.8=\ - {0} {1} ms -ship.build.ConsoleServer.9=\ - {0}- {1} +ship.build.ConsoleServer.9=\ - {0} - {1} ship.exception.PackageNotFoundException.0="Package {0} not found: {1}" ship.exception.DirectoryNotEmptyException.0={0} is not empty. You can reset project with -f but It make aergo.json overwritten!!