-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that demonstrates the unsoundness that can occur if Lombok and t…
…he Checker Framework are run together
- Loading branch information
Showing
4 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...er/src/test/java/org/checkerframework/checker/test/junit/CalledMethodsNoDelombokTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.checkerframework.checker.test.junit; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.checkerframework.framework.test.CheckerFrameworkPerDirectoryTest; | ||
import org.checkerframework.framework.test.TestConfiguration; | ||
import org.checkerframework.framework.test.TestConfigurationBuilder; | ||
import org.checkerframework.framework.test.TestUtilities; | ||
import org.checkerframework.framework.test.TypecheckExecutor; | ||
import org.checkerframework.framework.test.TypecheckResult; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
/** | ||
* This test suite exists to demonstrate and keep a record of the unsoundness that occurs when | ||
* Lombok and the Checker Framework are run in the same invocation of javac. | ||
*/ | ||
public class CalledMethodsNoDelombokTest extends CheckerFrameworkPerDirectoryTest { | ||
|
||
private static final ImmutableList<String> ANNOTATION_PROCS = | ||
ImmutableList.of( | ||
"lombok.launch.AnnotationProcessorHider$AnnotationProcessor", | ||
"lombok.launch.AnnotationProcessorHider$ClaimingProcessor", | ||
org.checkerframework.checker.calledmethods.CalledMethodsChecker.class.getName()); | ||
|
||
public CalledMethodsNoDelombokTest(List<File> testFiles) { | ||
super( | ||
testFiles, | ||
org.checkerframework.checker.calledmethods.CalledMethodsChecker.class, | ||
"lombok", | ||
"-Anomsgtext", | ||
"-nowarn"); | ||
} | ||
|
||
@Parameters | ||
public static String[] getTestDirs() { | ||
return new String[] {"calledmethods-nodelombok"}; | ||
} | ||
|
||
/** | ||
* copy-pasted code from {@link CheckerFrameworkPerDirectoryTest#run()}, except that we change the | ||
* annotation processors to {@link #ANNOTATION_PROCS} | ||
*/ | ||
@Override | ||
public void run() { | ||
boolean shouldEmitDebugInfo = TestUtilities.getShouldEmitDebugInfo(); | ||
List<String> customizedOptions = customizeOptions(Collections.unmodifiableList(checkerOptions)); | ||
TestConfiguration config = | ||
TestConfigurationBuilder.buildDefaultConfiguration( | ||
testDir, | ||
testFiles, | ||
classpathExtra, | ||
ANNOTATION_PROCS, | ||
customizedOptions, | ||
shouldEmitDebugInfo); | ||
TypecheckResult testResult = new TypecheckExecutor().runTest(config); | ||
TypecheckResult adjustedTestResult = adjustTypecheckResult(testResult); | ||
TestUtilities.assertTestDidNotFail(adjustedTestResult); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
checker/src/test/java/org/checkerframework/checker/test/junit/NullnessNoDelombokTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.checkerframework.checker.test.junit; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.checkerframework.framework.test.CheckerFrameworkPerDirectoryTest; | ||
import org.checkerframework.framework.test.TestConfiguration; | ||
import org.checkerframework.framework.test.TestConfigurationBuilder; | ||
import org.checkerframework.framework.test.TestUtilities; | ||
import org.checkerframework.framework.test.TypecheckExecutor; | ||
import org.checkerframework.framework.test.TypecheckResult; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
/** | ||
* This test suite exists to demonstrate and keep a record of the unsoundness that occurs when | ||
* Lombok and the Checker Framework are run in the same invocation of javac. | ||
*/ | ||
public class NullnessNoDelombokTest extends CheckerFrameworkPerDirectoryTest { | ||
|
||
private static final ImmutableList<String> ANNOTATION_PROCS = | ||
ImmutableList.of( | ||
"lombok.launch.AnnotationProcessorHider$AnnotationProcessor", | ||
"lombok.launch.AnnotationProcessorHider$ClaimingProcessor", | ||
org.checkerframework.checker.nullness.NullnessChecker.class.getName()); | ||
|
||
public NullnessNoDelombokTest(List<File> testFiles) { | ||
super( | ||
testFiles, | ||
org.checkerframework.checker.nullness.NullnessChecker.class, | ||
"nullness-nodelombok", | ||
"-Anomsgtext", | ||
"-nowarn"); | ||
} | ||
|
||
@Parameters | ||
public static String[] getTestDirs() { | ||
return new String[] {"nullness-nodelombok"}; | ||
} | ||
|
||
/** | ||
* copy-pasted code from {@link CheckerFrameworkPerDirectoryTest#run()}, except that we change the | ||
* annotation processors to {@link #ANNOTATION_PROCS} | ||
*/ | ||
@Override | ||
public void run() { | ||
boolean shouldEmitDebugInfo = TestUtilities.getShouldEmitDebugInfo(); | ||
List<String> customizedOptions = customizeOptions(Collections.unmodifiableList(checkerOptions)); | ||
TestConfiguration config = | ||
TestConfigurationBuilder.buildDefaultConfiguration( | ||
testDir, | ||
testFiles, | ||
classpathExtra, | ||
ANNOTATION_PROCS, | ||
customizedOptions, | ||
shouldEmitDebugInfo); | ||
TypecheckResult testResult = new TypecheckExecutor().runTest(config); | ||
TypecheckResult adjustedTestResult = adjustTypecheckResult(testResult); | ||
TestUtilities.assertTestDidNotFail(adjustedTestResult); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
checker/tests/calledmethods-nodelombok/UnsoundnessTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// An example of an unsoundness that occurs when running the Called Methods Checker | ||
// on Lombok'd code without running delombok first. | ||
|
||
@lombok.Builder | ||
class UnsoundnessTest { | ||
@lombok.NonNull Object foo; | ||
@lombok.NonNull Object bar; | ||
|
||
static void test() { | ||
// An error should be issued here, but the code has not been delombok'd. | ||
// If the CF and Lombok are ever able to work in the same invocation of javac | ||
// (i.e. without delomboking first), then this error should be changed back to an | ||
// expected error by re-adding the leading "::". | ||
// error: (finalizer.invocation) | ||
builder().build(); | ||
} | ||
|
||
static void test2() { | ||
builder().foo(null).bar(null).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// An example of an unsoundness that occurs when running the Nullness Checker | ||
// on Lombok'd code without running delombok first. | ||
|
||
@lombok.Builder | ||
class UnsoundnessTest { | ||
@lombok.NonNull Object foo; | ||
@lombok.NonNull Object bar; | ||
|
||
static void test() { | ||
// An error should be issued here, but the code has not been delombok'd. | ||
// If the CF and Lombok are ever able to work in the same invocation of javac | ||
// (i.e. without delomboking first), then this error should be changed back to an | ||
// expected error by re-adding the leading "::". | ||
// error: (assignment) | ||
builder().foo(null).build(); | ||
} | ||
} |