Skip to content

Commit ffbd13b

Browse files
committed
refactor: remove the getTestName method in IRTests
1 parent 5668e84 commit ffbd13b

File tree

8 files changed

+338
-384
lines changed

8 files changed

+338
-384
lines changed

cast/java/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies {
1111
api(projects.util)
1212
implementation(projects.shrike)
1313
testFixturesApi(libs.junit.jupiter.api)
14+
testFixturesApi(libs.junit.jupiter.params)
1415
testFixturesApi(projects.core)
1516
testFixturesApi(projects.util)
1617
testFixturesImplementation(projects.cast)

cast/java/ecj/src/test/java/com/ibm/wala/cast/java/test/ECJTestComments.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ protected Iterable<Entrypoint> makeDefaultEntrypoints(IClassHierarchy cha) {
6060
@Test
6161
public void testComments() throws IllegalArgumentException, CancelException, IOException {
6262
Pair<CallGraph, CallGraphBuilder<? super InstanceKey>> result =
63-
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), emptyList, true, null);
63+
runTest(
64+
singleTestSrc("Comments"),
65+
rtJar,
66+
simpleTestEntryPoint("Comments"),
67+
emptyList,
68+
true,
69+
null);
6470
for (CGNode node : result.fst.getNodes(testMethod)) {
6571
if (node.getMethod() instanceof AstMethod) {
6672
AstMethod m = (AstMethod) node.getMethod();

cast/java/src/testFixtures/java/com/ibm/wala/cast/java/test/IRTests.java

+10-34
Original file line numberDiff line numberDiff line change
@@ -340,42 +340,22 @@ public void check(CallGraph cg) {
340340
}
341341
}
342342

343-
protected Collection<String> singleTestSrc() {
344-
return Collections.singletonList(getTestSrcPath() + File.separator + singleJavaInputForTest());
343+
protected Collection<String> singleTestSrc(String testName) {
344+
return Collections.singletonList(getTestSrcPath() + File.separator + testName + ".java");
345345
}
346346

347-
protected Collection<String> singleTestSrc(final String folder) {
347+
protected Collection<String> singleTestSrc(final String folder, String testName) {
348348
return Collections.singletonList(
349-
getTestSrcPath() + File.separator + folder + File.separator + singleJavaInputForTest());
350-
}
351-
352-
protected Collection<String> singlePkgTestSrc(String pkgName) {
353-
return Collections.singletonList(
354-
getTestSrcPath() + File.separator + singleJavaPkgInputForTest(pkgName));
349+
getTestSrcPath() + File.separator + folder + File.separator + testName + ".java");
355350
}
356351

357352
protected Collection<String> singlePkgTestSrc(String pkgName, String testName) {
358353
return Collections.singletonList(
359354
getTestSrcPath() + File.separator + pkgName + File.separator + testName + ".java");
360355
}
361356

362-
protected String getTestName() {
363-
StackTraceElement stack[] = new Throwable().getStackTrace();
364-
for (int i = 0; i <= stack.length; i++) {
365-
if (stack[i].getMethodName().startsWith("test")) {
366-
return stack[i].getMethodName();
367-
}
368-
}
369-
370-
throw new Error("test method not found");
371-
}
372-
373-
protected String[] simpleTestEntryPoint() {
374-
return new String[] {'L' + getTestName().substring(4)};
375-
}
376-
377-
protected String[] simplePkgTestEntryPoint(String pkgName) {
378-
return new String[] {"L" + pkgName + "/" + getTestName().substring(4)};
357+
protected String[] simpleTestEntryPoint(String testName) {
358+
return new String[] {'L' + testName};
379359
}
380360

381361
protected String[] simplePkgTestEntryPoint(String pkgName, String testName) {
@@ -533,15 +513,11 @@ protected String getTestSrcPath() {
533513
return testSrcPath;
534514
}
535515

536-
protected String singleJavaInputForTest() {
537-
return getTestName().substring(4) + ".java";
538-
}
539-
540-
protected String singleInputForTest() {
541-
return getTestName().substring(4);
516+
protected String singleInputForTest(String testName) {
517+
return testName;
542518
}
543519

544-
protected String singleJavaPkgInputForTest(String pkgName) {
545-
return pkgName + File.separator + getTestName().substring(4) + ".java";
520+
protected String singleJavaPkgInputForTest(String pkgName, String testName) {
521+
return pkgName + File.separator + testName + ".java";
546522
}
547523
}

cast/java/src/testFixtures/java/com/ibm/wala/cast/java/test/Issue666Test.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ public Issue666Test(String projectName) {
2222
@Test
2323
public void testPeekErrorCase() throws CancelException, IOException {
2424
Pair<CallGraph, ?> result =
25-
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), emptyList, true, null);
25+
runTest(
26+
singleTestSrc("PeekErrorCase"),
27+
rtJar,
28+
simpleTestEntryPoint("PeekErrorCase"),
29+
emptyList,
30+
true,
31+
null);
2632

2733
assert result != null;
2834

cast/java/src/testFixtures/java/com/ibm/wala/cast/java/test/Issue667Test.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ public Issue667Test(String projectName) {
2424
@Test
2525
public void testDominanceFrontierCase() throws CancelException, IOException {
2626
Pair<CallGraph, ?> result =
27-
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), emptyList, true, null);
27+
runTest(
28+
singleTestSrc("DominanceFrontierCase"),
29+
rtJar,
30+
simpleTestEntryPoint("DominanceFrontierCase"),
31+
emptyList,
32+
true,
33+
null);
2834

2935
MethodReference cm =
3036
MethodReference.findOrCreate(

cast/java/src/testFixtures/java/com/ibm/wala/cast/java/test/JLexTest.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,12 @@ public JLexTest() {
2020
super(null);
2121
}
2222

23-
@Override
2423
protected String singleJavaInputForTest() {
2524
return "JLex";
2625
}
2726

2827
@Test
2928
public void testJLex() throws IllegalArgumentException, CancelException, IOException {
30-
runTest(singleTestSrc(), rtJar, new String[] {"LJLex/Main"}, emptyList, false, null);
31-
}
32-
33-
@Override
34-
protected String singleJavaPkgInputForTest(String pkgName) {
35-
return "";
29+
runTest(singleTestSrc("JLex"), rtJar, new String[] {"LJLex/Main"}, emptyList, false, null);
3630
}
3731
}

0 commit comments

Comments
 (0)