Skip to content

Commit ca4739e

Browse files
committed
Fix string formatting issues with annotations
There were issues when the error message contained the string "{}"
1 parent 3c59ee8 commit ca4739e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/main/java/io/github/misode/packtest/LoadDiagnostics.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
public class LoadDiagnostics {
99
private static final List<Diagnostic> DIAGNOSTICS = new ArrayList<>();
1010

11-
public static void error(Logger logger, String resource, String id, String message) {
12-
DIAGNOSTICS.add(new Diagnostic(resource, id, message));
13-
String annotation = "";
11+
public static void error(Logger logger, String type, String id, String message) {
12+
DIAGNOSTICS.add(new Diagnostic(type, id, message));
1413
if (PackTest.isAnnotationsEnabled()) {
15-
annotation = "\n::error title=Failed to load " + resource + " " + id + "::" + message;
14+
logger.info(PackTest.wrapError("Failed to load {} {}") + "\n::error title=Failed to load {} {}::{}", type, id, type, id, message);
15+
} else {
16+
logger.info(PackTest.wrapError("Failed to load {} {} - {}"), type, id, message);
1617
}
17-
logger.info(PackTest.wrapError("Failed to load {} {}" + (PackTest.isAnnotationsEnabled() ? "" : " - {}")) + annotation, resource, id, message);
1818
}
1919

2020
public static List<Diagnostic> loadErrors() {

src/main/java/io/github/misode/packtest/mixin/LogTestReporterMixin.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@ public class LogTestReporterMixin {
2929
@Inject(method = "onTestFailed", at = @At(value = "HEAD"), cancellable = true)
3030
private void onTestFailed(GameTestInfo info, CallbackInfo ci) {
3131
if (PackTest.isAutoEnabled()) {
32+
String testName = info.getTestName();
3233
String lineNumber = info.getError() instanceof LineNumberException err
3334
? " on line " + err.getLineNumber()
3435
: "";
36+
String message = Util.describeError(info.getError());
3537
if (info.isRequired()) {
36-
String annotation = "";
3738
if (PackTest.isAnnotationsEnabled()) {
38-
annotation = "\n::error title=Test " + info.getTestName() + " failed" + lineNumber + "!::" + Util.describeError(info.getError());
39+
LOGGER.error(PackTest.wrapError("{} failed{}!") + "\n::error title=Test {} failed{}!::{}", testName, lineNumber, testName, lineNumber, message);
40+
} else {
41+
LOGGER.error(PackTest.wrapError("{} failed{}! {}"), testName, lineNumber, message);
3942
}
40-
LOGGER.error(PackTest.wrapError("{} failed{}!" + (PackTest.isAnnotationsEnabled() ? "" : " {}")) + annotation, info.getTestName(), lineNumber, Util.describeError(info.getError()));
4143
} else {
42-
LOGGER.warn(PackTest.wrapWarning("(optional) {} failed{}! {}"), info.getTestName(), lineNumber, Util.describeError(info.getError()));
44+
LOGGER.warn(PackTest.wrapWarning("(optional) {} failed{}! {}"), testName, lineNumber, message);
4345
}
4446
ci.cancel();
4547
}

0 commit comments

Comments
 (0)