Skip to content

Commit 5646976

Browse files
Bill Zhangfacebook-github-bot
Bill Zhang
authored andcommitted
Adding test cases to check if non-annotated parameters get removed in the RemoveUnusedArgs pass
Summary: Added test cases for the change in D75252795 to ensure that the code works as intended. I added an interface into `RemovedUnusedArgsTest.java` called `AnnotatedParameterInterface`, which contains one method with an annotated parameter, and another method with no annotated parameters. The annotation is custom, and defined as `CustomAnnotation`. The test PostVerify tests, named `DontRemoveAnnotatedParameter` and `RemoveNonAnnotatedParameter` will check if the pass does not remove the method that has annotated parameters, and the other one checks if it does remove the one without annotated parameters. Reviewed By: wsanville Differential Revision: D75257372 fbshipit-source-id: f67701ffb9b9fbc00f1b66e7a92a5c2d2884a25f
1 parent dc5aee9 commit 5646976

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

test/instr/RemoveUnusedArgsTest.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,4 +1105,36 @@ TEST_F(PostVerify, RemoveAbstractUnusedArg) {
11051105
check_callsite_regs(use_foo, 1, 1);
11061106
}
11071107

1108+
TEST_F(PostVerify, DontRemoveAnnotatedParameter) {
1109+
auto annotated_parameter_class = find_class_named(
1110+
classes, "Lcom/facebook/redex/test/instr/AnnotatedParameterInterface;");
1111+
ASSERT_NE(nullptr, annotated_parameter_class);
1112+
1113+
auto annotated_parameter_method = find_vmethod(
1114+
*annotated_parameter_class, "annotated_parameter_method_1", "(I)V");
1115+
ASSERT_NE(nullptr, annotated_parameter_method);
1116+
}
1117+
1118+
TEST_F(PostVerify, RemoveNonAnnotatedParameterSingleParameterMethod) {
1119+
auto annotated_parameter_class = find_class_named(
1120+
classes, "Lcom/facebook/redex/test/instr/AnnotatedParameterInterface;");
1121+
ASSERT_NE(nullptr, annotated_parameter_class);
1122+
1123+
auto annotated_parameter_method = find_vmethod(
1124+
*annotated_parameter_class, "annotated_parameter_method_2", "(I)V");
1125+
1126+
ASSERT_EQ(nullptr, annotated_parameter_method);
1127+
}
1128+
1129+
TEST_F(PostVerify, DontRemoveNonAnnotatedParameterMultiParameterMethod) {
1130+
auto annotated_parameter_class = find_class_named(
1131+
classes, "Lcom/facebook/redex/test/instr/AnnotatedParameterInterface;");
1132+
ASSERT_NE(nullptr, annotated_parameter_class);
1133+
1134+
auto annotated_parameter_method = find_vmethod(
1135+
*annotated_parameter_class, "annotated_parameter_method_3", "(II)V");
1136+
1137+
ASSERT_NE(nullptr, annotated_parameter_method);
1138+
}
1139+
11081140
} // namespace

test/instr/RemoveUnusedArgsTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
package com.facebook.redex.test.instr;
99

10+
import java.lang.annotation.ElementType;
11+
import java.lang.annotation.Retention;
12+
import java.lang.annotation.Target;
13+
import java.lang.annotation.RetentionPolicy;
14+
1015
import javax.security.auth.x500.X500Principal;
1116

1217
class Foo {
@@ -434,3 +439,17 @@ public void reorderable2(Object x, double y, int z) {
434439
public void reorderable2(Object x, int y, double z) {
435440
}
436441
}
442+
443+
@Retention(RetentionPolicy.RUNTIME)
444+
@Target(ElementType.PARAMETER)
445+
@interface CustomAnnotation {
446+
String value() default "";
447+
}
448+
449+
interface AnnotatedParameterInterface {
450+
public void annotated_parameter_method_1(@CustomAnnotation("annotation 1") int x);
451+
452+
public void annotated_parameter_method_2(int x);
453+
454+
public void annotated_parameter_method_3(int x, @CustomAnnotation("annotation 2") int y);
455+
}

0 commit comments

Comments
 (0)