From efff1415b29b0756f054c0a602282e55d501c3a6 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 30 Jan 2020 16:20:29 +0000 Subject: [PATCH 1/3] show syntax errors from failing test files --- core/src/main/java/ship/build/ConsoleServer.java | 6 +++++- core/src/main/resources/message.properties | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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/resources/message.properties b/core/src/main/resources/message.properties index 1178860..431a1d9 100644 --- a/core/src/main/resources/message.properties +++ b/core/src/main/resources/message.properties @@ -4,7 +4,7 @@ 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 From bcf147be75b65a44d3db3d292943bc57b6f144cb Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 30 Jan 2020 16:23:37 +0000 Subject: [PATCH 2/3] show code snippets from failing test files --- .../src/main/java/ship/command/TestProject.java | 17 ++++++++--------- .../java/ship/test/LuaErrorInformation.java | 11 ++++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) 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; } } From 89587a480e98ded3fe72506f94bb612913b80ede Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Sun, 2 Feb 2020 19:16:38 +0000 Subject: [PATCH 3/3] Slightly tweak formatting of console failure lines Make it look a bit nicer. --- core/src/main/resources/message.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/message.properties b/core/src/main/resources/message.properties index 431a1d9..d79985b 100644 --- a/core/src/main/resources/message.properties +++ b/core/src/main/resources/message.properties @@ -8,7 +8,7 @@ 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!!