From 7a525fa06f799a9e681581a80ada477b41daaedb Mon Sep 17 00:00:00 2001 From: Adela Vais Date: Sun, 3 Jan 2021 16:05:57 +0200 Subject: [PATCH] d: tests: avoid mixing output from reportSyntaxError and getExpectedTokens Function reportSyntaxError buffers and prints the message at the end. * tests/local.at: Here. --- tests/local.at | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/local.at b/tests/local.at index e0885541..77112b5e 100644 --- a/tests/local.at +++ b/tests/local.at @@ -902,10 +902,13 @@ public string transformToken(]AT_API_PREFIX[Parser.SymbolKind token) public void reportSyntaxError(]AT_API_PREFIX[Parser.Context ctx) { - stderr.write(]AT_LOCATION_IF([[ctx.getLocation(), ": ",]])["syntax error"); + // Buffer and print the message at the end, to avoid being intertwined + // with debug traces from getExpectedTokens. + string msg; + msg ~=]AT_LOCATION_IF([[ ctx.getLocation().toString() ~ ": " ~]])[ "syntax error"; { ]AT_API_PREFIX[Parser.SymbolKind token = ctx.getToken(); - stderr.write(" on token @<:@", transformToken(token), "@:>@"); + msg ~= " on token @<:@" ~ transformToken(token) ~ "@:>@"; } { immutable int argmax = 7; @@ -913,12 +916,13 @@ public void reportSyntaxError(]AT_API_PREFIX[Parser.Context ctx) int n = ctx.getExpectedTokens(arg, argmax); if (0 < n) { - stderr.write(" (expected:"); + msg ~= " (expected:"; for (int i = 0; i < n; ++i) - stderr.write(" @<:@", transformToken(arg[i]), "@:>@"); - stderr.writeln(")"); + msg ~= " @<:@" ~ transformToken(arg[i]) ~ "@:>@"; + msg ~= ")"; } } + stderr.writeln(msg); } ]])[]])