Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove getTestName from IRTests.java so tests do not rely on method name #1485

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jkhaliqi
Copy link
Contributor

@jkhaliqi jkhaliqi commented Mar 6, 2025

Cleaned up ECJJava15IRTest.java by refactoring the tests to be parameterized to not rely on method name for running the tests. Also removed the getTestName from IRTests so the tests do not rely on that method to get the name of the test it should run. With this we pass in the name and tests can now be parameterized as well instead of relying on naming tests differently

Copy link

github-actions bot commented Mar 6, 2025

Test Results

  827 files  ±  0    827 suites  ±0   4h 29m 15s ⏱️ - 22m 14s
  866 tests +101    849 ✅ +101   17 💤 ±0  0 ❌ ±0 
5 239 runs  ±  0  5 118 ✅ ±  0  121 💤 ±0  0 ❌ ±0 

Results for commit 520e80e. ± Comparison against base commit 90350c7.

This pull request removes 59 and adds 160 tests. Note that renamed tests count towards both.
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testAnnotations()
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testAnonGeneNullarySimple()
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testAnonymousGenerics()
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testBasicsGenerics()
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testCocovariant()
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testCustomGenericsAndFields()
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testEnumSwitch()
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testExplicitBoxingTest()
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testGenericArrays()
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ testGenericMemberClasses()
…
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [10] java15IRTestName=GenericMemberClasses
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [11] java15IRTestName=GenericSuperSink
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [12] java15IRTestName=MoreOverriddenGenerics
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [13] java15IRTestName=NotSoSimpleEnums
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [14] java15IRTestName=OverridesOnePointFour
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [15] java15IRTestName=SimpleEnums
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [16] java15IRTestName=SimpleEnums2
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [17] java15IRTestName=TypeInferencePrimAndStringOp
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [18] java15IRTestName=Varargs
com.ibm.wala.cast.java.test.ECJJava15IRTest ‑ [19] java15IRTestName=VarargsCovariant
…

♻️ This comment has been updated with latest results.

@jkhaliqi
Copy link
Contributor Author

jkhaliqi commented Mar 6, 2025

@msridhar @juliandolby Hey whenever you get a chance could I get review on this, thank you!

@msridhar
Copy link
Member

msridhar commented Mar 6, 2025

@jkhaliqi I love it! Do you have time to take this further? This is the key function that pulls out the name of the currently-running test:

protected String getTestName() {
StackTraceElement stack[] = new Throwable().getStackTrace();
for (int i = 0; i <= stack.length; i++) {
if (stack[i].getMethodName().startsWith("test")) {
return stack[i].getMethodName();
}
}
throw new Error("test method not found");
}

I'd love it if we could push this cleanup further so that the function above could just be deleted and everywhere we rely on it we instead use parameterized tests. I think it would involve a few more changes similar to what you've already done and (hopefully!) deleting a bunch of code. What do you think?

@jkhaliqi
Copy link
Contributor Author

jkhaliqi commented Mar 6, 2025

Hey sounds good, and thank you! I'll give that a try and see how far I get

Comment on lines 46 to 66
"VarargsOverriding",
"EnumSwitch",
"OverridesOnePointFour",
"VarargsCovariant",
"SimpleEnums",
"GenericSuperSink",
"AnonGeneNullarySimple",
"AnonymousGenerics",
"NotSoSimpleEnums",
"Varargs",
"GenericArrays",
"Annotations",
"Cocovariant",
"ExplicitBoxingTest",
"Wildcards",
"BasicsGenerics",
"CustomGenericsAndFields",
"TypeInferencePrimAndStringOp",
"SimpleEnums2",
"GenericMemberClasses",
"MoreOverriddenGenerics");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the order of these items does not matter, then please sort them alphabetically. That will make this list easier to scan when adding new items, easier to avoid adding duplicates, etc..

@jkhaliqi jkhaliqi force-pushed the parameterize-IR branch 5 times, most recently from d1483aa to ffbd13b Compare March 7, 2025 00:58
@msridhar
Copy link
Member

msridhar commented Mar 7, 2025

@jkhaliqi is this ready for review?

@jkhaliqi
Copy link
Contributor Author

jkhaliqi commented Mar 7, 2025

@msridhar Yup, I believe this is ready for review, whenever you get a chance, thank you!

@jkhaliqi jkhaliqi changed the title refactored ECJJava15IRTests to be parameterized refactor: remove getTestName from IRTests.java so tests do noot rely on method name Mar 7, 2025
@jkhaliqi jkhaliqi changed the title refactor: remove getTestName from IRTests.java so tests do noot rely on method name refactor: remove getTestName from IRTests.java so tests do not rely on method name Mar 7, 2025
@jkhaliqi
Copy link
Contributor Author

jkhaliqi commented Mar 7, 2025

I just changed the JavaIRTests to be alphabetical as well for parametrized tests, but all should be good now!

Copy link
Member

@msridhar msridhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! A couple of comments particularly on JavaIRTests

true,
null);
}
static List<? extends IRAssertion> caForInterfaceTest1 =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This naming scheme caForXXX is confusing. What does ca mean? Can we use something more descriptive?

Copy link
Contributor Author

@jkhaliqi jkhaliqi Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't exactly sure what ca also meant I got this variable name from the fourth parameter inside of runTests. But i'm assuming it has something to do with the callGraph and just changed it to be callAssertionsForXXX. Let me know if theres a better name.

}

@Test
public void testArrayLiteral2() throws IllegalArgumentException, CancelException, IOException {
public void testTwoClasses() throws IllegalArgumentException, CancelException, IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the remaining tests still here and not just run via the parameterized tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the remaining tests call runTests and store its output in a variable and then do other stuff with it so I just left those alone.

@msridhar
Copy link
Member

@jkhaliqi can you just add commits to your branch from now on instead of force pushing? That will make it easier to see what is changing. I will squash the commits before merging.

@jkhaliqi
Copy link
Contributor Author

@msridhar Sounds good, sorry about that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants