Skip to content

Commit c0f90d8

Browse files
Jim Idleericvergnaud
andauthored
Feature/gotestfix (#4168)
* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file Arrrgh! Signed-off-by: Jim.Idle <[email protected]> * present antlr before versioning (#4156) Signed-off-by: Jim.Idle <[email protected]> * fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (#4161) Signed-off-by: Jim.Idle <[email protected]> * fix: Cater for the fact that some test rules use start as a label or rule name As a fix for other cvode gen errors when start, end, or exception are used as label names, they are now translated to have a suffix of `_` at code gen time. However, the runtime tests sometimes use start as a rule name and so we must now cater for this in the tests. Signed-off-by: Jim.Idle <[email protected]> --------- Signed-off-by: Jim.Idle <[email protected]> Co-authored-by: ericvergnaud <[email protected]>
1 parent 1fb3e5b commit c0f90d8

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

runtime-testsuite/test/org/antlr/v4/test/runtime/go/GoRunner.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ protected void initRuntime(RunOptions runOptions) throws Exception {
8585
if (goModFile.exists())
8686
if (!goModFile.delete())
8787
throw new IOException("Can't delete " + goModFile);
88-
Processor.run(new String[] {runtimeToolPath, "mod", "init", "test"}, cachePath, environment);
89-
Processor.run(new String[] {runtimeToolPath, "mod", "edit",
88+
Processor.run(new String[]{runtimeToolPath, "mod", "init", "test"}, cachePath, environment);
89+
Processor.run(new String[]{runtimeToolPath, "mod", "edit",
9090
"-replace=" + GoRuntimeImportPath + "=" + runtimeFilesPath}, cachePath, environment);
9191
cachedGoMod = readFile(cachePath + FileSeparator, "go.mod");
9292
}
@@ -97,7 +97,18 @@ protected String grammarParseRuleToRecognizerName(String startRuleName) {
9797
return null;
9898
}
9999

100-
return startRuleName.substring(0, 1).toUpperCase() + startRuleName.substring(1);
100+
// The rule name start is now translated to Start_ at runtime to avoid clashes with labels.
101+
// Some tests use start as the first rule name, and we must cater for that
102+
//
103+
String rn = startRuleName.substring(0, 1).toUpperCase() + startRuleName.substring(1);
104+
switch (rn) {
105+
case "Start":
106+
case "End":
107+
case "Exception":
108+
rn += "_";
109+
default:
110+
}
111+
return rn;
101112
}
102113

103114
@Override
@@ -126,7 +137,7 @@ protected CompiledState compile(RunOptions runOptions, GeneratedState generatedS
126137
writeFile(tempDirPath, "go.mod", cachedGoMod);
127138
Exception ex = null;
128139
try {
129-
Processor.run(new String[] {getRuntimeToolPath(), "mod", "tidy"}, tempDirPath, environment);
140+
Processor.run(new String[]{getRuntimeToolPath(), "mod", "tidy"}, tempDirPath, environment);
130141
} catch (InterruptedException | IOException e) {
131142
ex = e;
132143
}

0 commit comments

Comments
 (0)