Skip to content

Commit 71c3ec7

Browse files
committed
Stop adding $ as "terminators" when filtering tests for JUnit 5
While `$` may be useful in other JUnit versions to determine where a "class boundary" ends, as the plugin is using `,` for enumeration in that case (i.e. `mypackage.myClass1#myMethod1,myMethod2$|...`), it is not needed when the enumeration is between `()` as in JUnit5 (i.e. `mypackage.myClass1#(myMethod1|myMethod2)|...`).
1 parent b7edbea commit 71c3ec7

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

java/src/com/google/idea/blaze/java/run/producers/BlazeJUnitTestFilterFlags.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,11 @@ static String testFilterForClassAndMethods(
211211
return output.toString();
212212
}
213213
output.append('#').append(methodNamePattern);
214-
// JUnit 4 and 5 test filters are regexes, and must be terminated to avoid matching
215-
// unintended classes/methods. JUnit 3 test filters do not need or support this syntax.
216-
if (jUnitVersion == JUnitVersion.JUNIT_3) {
217-
return output.toString();
214+
// JUnit 4 test filters are regexes and must be terminated to avoid matching unintended
215+
// classes/methods.
216+
if (jUnitVersion == JUnitVersion.JUNIT_4) {
217+
output.append('$');
218218
}
219-
output.append('$');
220219
return output.toString();
221220
}
222221

java/tests/integrationtests/com/google/idea/blaze/java/run/producers/BlazeJUnitTestFilterFlagsIntegrationTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ public void testParameterizedMethods() {
8080
Location<?> location2 =
8181
new PsiMemberParameterizedLocation(getProject(), method2, javaClass, "[3]");
8282

83+
String junit4Dollar = (jUnitVersionUnderTest == JUnitVersion.JUNIT_4 ? "$" : "");
8384
assertThat(
8485
BlazeJUnitTestFilterFlags.testFilterForClassesAndMethods(
8586
ImmutableMap.of(javaClass, ImmutableList.of(location1, location2))))
86-
.isEqualTo("com.google.test.TestClass#(testMethod1\\[param\\]|testMethod2\\[3\\])$");
87+
.isEqualTo("com.google.test.TestClass#(testMethod1\\[param\\]|testMethod2\\[3\\])" + junit4Dollar);
8788
}
8889

8990
@Test
@@ -127,6 +128,7 @@ public void testMultipleClassesWithParameterizedMethods() {
127128
PsiClass javaClass2 = ((PsiClassOwner) javaFile2).getClasses()[0];
128129
PsiMethod class2Method = javaClass2.findMethodsByName("testMethod", false)[0];
129130

131+
String junit4Dollar = (jUnitVersionUnderTest == JUnitVersion.JUNIT_4 ? "$" : "");
130132
assertThat(
131133
BlazeJUnitTestFilterFlags.testFilterForClassesAndMethods(
132134
ImmutableMap.of(
@@ -137,8 +139,8 @@ public void testMultipleClassesWithParameterizedMethods() {
137139
.isEqualTo(
138140
Joiner.on('|')
139141
.join(
140-
"com.google.test.OtherTestClass#testMethod$",
141-
"com.google.test.TestClass#(testMethod1\\[param\\]|testMethod2\\[3\\])$"
142+
"com.google.test.OtherTestClass#testMethod" + junit4Dollar,
143+
"com.google.test.TestClass#(testMethod1\\[param\\]|testMethod2\\[3\\])" + junit4Dollar
142144
));
143145
}
144146
}

java/tests/integrationtests/com/google/idea/blaze/java/run/producers/BlazeJavaAbstractTestCaseConfigurationProducerTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,9 @@ public void testConfigurationCreatedFromMethodInAbstractClass() throws Throwable
264264

265265
assertThat(blazeConfig.getTargets())
266266
.containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:TestClass"));
267+
String junit4Dollar = (jUnitVersionUnderTest == JUnitVersion.JUNIT_4 ? "$" : "");
267268
assertThat(getTestFilterContents(blazeConfig))
268-
.isEqualTo(BlazeFlags.TEST_FILTER + "=com.google.test.TestClass#testMethod$");
269+
.isEqualTo(BlazeFlags.TEST_FILTER + "=com.google.test.TestClass#testMethod" + junit4Dollar);
269270
}
270271

271272
@Test

java/tests/integrationtests/com/google/idea/blaze/java/run/producers/BlazeJavaTestMethodConfigurationProducerTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.idea.blaze.base.model.primitives.Label;
2424
import com.google.idea.blaze.base.model.primitives.TargetExpression;
2525
import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
26+
import com.google.idea.blaze.java.run.producers.BlazeJUnitTestFilterFlags.JUnitVersion;
2627
import com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer;
2728
import com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState;
2829
import com.google.idea.blaze.java.utils.BlazeJUnitRunConfigurationProducerTestCase;
@@ -62,8 +63,9 @@ public void testProducedFromPsiMethod() throws Throwable {
6263
(BlazeCommandRunConfiguration) fromContext.getConfiguration();
6364
assertThat(config.getTargets())
6465
.containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:TestClass"));
66+
String junit4Dollar = (jUnitVersionUnderTest == JUnitVersion.JUNIT_4 ? "$" : "");
6567
assertThat(getTestFilterContents(config))
66-
.isEqualTo("--test_filter=com.google.test.TestClass#testMethod1$");
68+
.isEqualTo("--test_filter=com.google.test.TestClass#testMethod1" + junit4Dollar);
6769
assertThat(config.getName()).isEqualTo("Bazel test TestClass.testMethod1");
6870
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
6971

java/tests/unittests/com/google/idea/blaze/java/run/producers/BlazeJUnitTestFilterFlagsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testJUnit5ClassAndSingleMethod() {
9393
JUnitVersion.JUNIT_5,
9494
ImmutableList.of("testMethod1"),
9595
null))
96-
.isEqualTo("com.google.idea.ClassName#testMethod1$");
96+
.isEqualTo("com.google.idea.ClassName#testMethod1");
9797
}
9898

9999
@Test
@@ -126,7 +126,7 @@ public void testJUnit5ClassAndMultipleMethods() {
126126
JUnitVersion.JUNIT_5,
127127
ImmutableList.of("testMethod1", "testMethod2"),
128128
null))
129-
.isEqualTo("com.google.idea.ClassName#(testMethod1|testMethod2)$");
129+
.isEqualTo("com.google.idea.ClassName#(testMethod1|testMethod2)");
130130
}
131131

132132
@Test

0 commit comments

Comments
 (0)