Skip to content

Commit 17f9e9d

Browse files
committed
Pass testSourceUri to dynamicTest and to dynamicContainer for convenient navigation to tests data in IntelliJ
Signed-off-by: Ivan Kochurkin <[email protected]>
1 parent 59dccba commit 17f9e9d

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

runtime-testsuite/test/org/antlr/v4/test/runtime/CustomDescriptors.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66

77
package org.antlr.v4.test.runtime;
88

9+
import java.net.URI;
10+
import java.nio.file.Paths;
911
import java.util.*;
1012

1113
public class CustomDescriptors {
1214
public final static HashMap<String, RuntimeTestDescriptor[]> descriptors;
15+
private final static URI uri;
1316

1417
static {
18+
uri = Paths.get(RuntimeTestUtils.runtimeTestsuitePath.toString(),
19+
"test", "org", "antlr", "v4", "test", "runtime", "CustomDescriptors.java").toUri();
20+
1521
descriptors = new HashMap<>();
1622
descriptors.put("LexerExec",
1723
new RuntimeTestDescriptor[]{
@@ -41,7 +47,7 @@ private static RuntimeTestDescriptor getLineSeparatorLfDescriptor() {
4147
"@members {<setOutStream()>}\n" +
4248
"T: ~'\\n'+;\n" +
4349
"SEPARATOR: '\\n';",
44-
null, false, false, null);
50+
null, false, false, null, uri);
4551
}
4652

4753
private static RuntimeTestDescriptor getLineSeparatorCrLfDescriptor() {
@@ -63,7 +69,7 @@ private static RuntimeTestDescriptor getLineSeparatorCrLfDescriptor() {
6369
"@members {<setOutStream()>}\n" +
6470
"T: ~'\\r'+;\n" +
6571
"SEPARATOR: '\\r\\n';",
66-
null, false, false, null);
72+
null, false, false, null, uri);
6773
}
6874

6975
private static RuntimeTestDescriptor getLargeLexerDescriptor() {
@@ -91,7 +97,7 @@ private static RuntimeTestDescriptor getLargeLexerDescriptor() {
9197
"",
9298
grammarName,
9399
grammar.toString(),
94-
null, false, false, null);
100+
null, false, false, null, uri);
95101
}
96102

97103
private static RuntimeTestDescriptor getAtnStatesSizeMoreThan65535Descriptor() {
@@ -142,6 +148,6 @@ private static RuntimeTestDescriptor getAtnStatesSizeMoreThan65535Descriptor() {
142148
grammarName,
143149
grammar.toString(),
144150
null, false, false,
145-
new String[] {"CSharp", "Python2", "Python3", "Go", "PHP", "Swift", "JavaScript", "Dart"});
151+
new String[] {"CSharp", "Python2", "Python3", "Go", "PHP", "Swift", "JavaScript", "Dart"}, uri);
146152
}
147153
}

runtime-testsuite/test/org/antlr/v4/test/runtime/RuntimeTestDescriptor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.antlr.v4.runtime.misc.Pair;
1010

11+
import java.net.URI;
1112
import java.util.Arrays;
1213
import java.util.List;
1314

@@ -52,11 +53,14 @@ public class RuntimeTestDescriptor {
5253

5354
public final String[] skipTargets;
5455

56+
public final URI uri;
57+
5558
public RuntimeTestDescriptor(GrammarType testType, String name, String notes,
5659
String input, String output, String errors,
5760
String startRule,
5861
String grammarName, String grammar, List<Pair<String, String>> slaveGrammars,
59-
boolean showDFA, boolean showDiagnosticErrors, String[] skipTargets) {
62+
boolean showDFA, boolean showDiagnosticErrors, String[] skipTargets,
63+
URI uri) {
6064
this.testType = testType;
6165
this.name = name;
6266
this.notes = notes;
@@ -70,6 +74,7 @@ public RuntimeTestDescriptor(GrammarType testType, String name, String notes,
7074
this.showDFA = showDFA;
7175
this.showDiagnosticErrors = showDiagnosticErrors;
7276
this.skipTargets = skipTargets != null ? skipTargets : new String[0];
77+
this.uri = uri;
7378
}
7479

7580
/** Return true if this test should be ignored for the indicated target */

runtime-testsuite/test/org/antlr/v4/test/runtime/RuntimeTestDescriptorParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.antlr.v4.runtime.misc.Pair;
1010

11+
import java.net.URI;
1112
import java.util.*;
1213

1314
public class RuntimeTestDescriptorParser {
@@ -62,7 +63,7 @@ public class RuntimeTestDescriptorParser {
6263
a : b {<writeln("\"S.a\"")>};
6364
b : B;
6465
*/
65-
public static RuntimeTestDescriptor parse(String name, String text) throws RuntimeException {
66+
public static RuntimeTestDescriptor parse(String name, String text, URI uri) throws RuntimeException {
6667
String currentField = null;
6768
StringBuilder currentValue = new StringBuilder();
6869

@@ -162,7 +163,7 @@ else if ( value.indexOf('\n')>=0 ) {
162163
}
163164
}
164165
return new RuntimeTestDescriptor(testType, name, notes, input, output, errors, startRule, grammarName, grammar,
165-
slaveGrammars, showDFA, showDiagnosticErrors, skipTargets);
166+
slaveGrammars, showDFA, showDiagnosticErrors, skipTargets, uri);
166167
}
167168

168169
/** Get A, B, or C from:

runtime-testsuite/test/org/antlr/v4/test/runtime/RuntimeTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.net.URL;
2222
import java.nio.file.Files;
23+
import java.nio.file.Path;
2324
import java.nio.file.Paths;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;
@@ -71,7 +72,7 @@ public abstract class RuntimeTests {
7172
} catch (IOException e) {
7273
throw new RuntimeException(e);
7374
}
74-
descriptors.add(RuntimeTestDescriptorParser.parse(name, text));
75+
descriptors.add(RuntimeTestDescriptorParser.parse(name, text, descriptorFile.toURI()));
7576
}
7677

7778
testDescriptors.put(groupName, descriptors.toArray(new RuntimeTestDescriptor[0]));
@@ -96,17 +97,19 @@ public List<DynamicNode> runtimeTests() {
9697
ArrayList<DynamicNode> descriptorTests = new ArrayList<>();
9798
RuntimeTestDescriptor[] descriptors = testDescriptors.get(group);
9899
for (RuntimeTestDescriptor descriptor : descriptors) {
99-
descriptorTests.add(dynamicTest(descriptor.name, () -> {
100+
descriptorTests.add(dynamicTest(descriptor.name, descriptor.uri, () -> {
100101
try (RuntimeRunner runner = createRuntimeRunner()) {
101102
String errorMessage = test(descriptor, runner);
102103
if (errorMessage != null) {
103104
runner.setSaveTestDir(true);
104-
fail(descriptor.name + "; " + errorMessage + "\nDirectory: " + runner.getTempDirPath());
105+
fail(descriptor.name + "; " + errorMessage + "\nTest directory: " + runner.getTempDirPath());
105106
}
106107
}
107108
}));
108109
}
109-
result.add(dynamicContainer(group, descriptorTests));
110+
111+
Path descriptorGroupPath = Paths.get(RuntimeTestUtils.resourcePath.toString(), "descriptors", group);
112+
result.add(dynamicContainer(group, descriptorGroupPath.toUri(), Arrays.stream(descriptorTests.toArray(new DynamicNode[0]))));
110113
}
111114

112115
return result;

0 commit comments

Comments
 (0)