[FIR] Add contracts tests and place them in a separate directory

This commit is contained in:
Arsen Nagdalian
2020-07-20 17:38:08 +03:00
parent 86e07cd626
commit b8b60864fd
12 changed files with 367 additions and 20 deletions
@@ -60,11 +60,6 @@ public class LightTree2FirConverterTestCaseGenerated extends AbstractLightTree2F
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/constructorOfAnonymousObject.kt");
}
@TestMetadata("contractDescription.kt")
public void testContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contractDescription.kt");
}
@TestMetadata("derivedClass.kt")
public void testDerivedClass() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/derivedClass.kt");
@@ -164,6 +159,65 @@ public class LightTree2FirConverterTestCaseGenerated extends AbstractLightTree2F
public void testWhere() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/where.kt");
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Contracts extends AbstractLightTree2FirConverterTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInContracts() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NewSyntax extends AbstractLightTree2FirConverterTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInNewSyntax() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("functionWithBothOldAndNewSyntaxContractDescription.kt")
public void testFunctionWithBothOldAndNewSyntaxContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/functionWithBothOldAndNewSyntaxContractDescription.kt");
}
@TestMetadata("propertyAccessorsContractDescription.kt")
public void testPropertyAccessorsContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/propertyAccessorsContractDescription.kt");
}
@TestMetadata("simpleFunctionsContractDescription.kt")
public void testSimpleFunctionsContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/simpleFunctionsContractDescription.kt");
}
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class OldSyntax extends AbstractLightTree2FirConverterTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInOldSyntax() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("contractDescription.kt")
public void testContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax/contractDescription.kt");
}
}
}
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions")
@@ -0,0 +1,6 @@
fun test1(s: String?) contract [returnsNotNull()] {
contract {
returns() implies (s != null)
}
test1()
}
@@ -0,0 +1,12 @@
FILE: functionWithBothOldAndNewSyntaxContractDescription.kt
public? final? fun test1(s: String?): R|kotlin/Unit|
[Contract description] <
returnsNotNull#()
>
{
contract#(<L> = contract@fun <implicit>.<anonymous>(): <implicit> {
returns#().implies#(!=(s#, Null(null)))
}
)
test1#()
}
@@ -0,0 +1,25 @@
// new contracts syntax for property accessors
class MyClass {
var myInt: Int = 0
get() contract [returnsNotNull()] = 1
set(value) {
field = value * 10
}
}
class AnotherClass(multiplier: Int) {
var anotherInt: Int = 0
get() contract [returnsNotNull()] = 1
set(value) contract [returns()] {
field = value * multiplier
}
}
class SomeClass(multiplier: Int?) {
var someInt: Int = 0
get() contract [returnsNotNull()] = 1
set(value) contract [returns() implies (value != null)] {
value ?: throw NullArgumentException()
field = value
}
}
@@ -0,0 +1,64 @@
FILE: propertyAccessorsContractDescription.kt
public? final? class MyClass : R|kotlin/Any| {
public? constructor(): R|MyClass| {
super<R|kotlin/Any|>()
}
public? final? var myInt: Int = IntegerLiteral(0)
public? get(): Int
[Contract description] <
returnsNotNull#()
>
{
^ IntegerLiteral(1)
}
public? set(value: Int): R|kotlin/Unit| {
field# = value#.times#(IntegerLiteral(10))
}
}
public? final? class AnotherClass : R|kotlin/Any| {
public? constructor(multiplier: Int): R|AnotherClass| {
super<R|kotlin/Any|>()
}
public? final? var anotherInt: Int = IntegerLiteral(0)
public? get(): Int
[Contract description] <
returnsNotNull#()
>
{
^ IntegerLiteral(1)
}
public? set(value: Int): R|kotlin/Unit|
[Contract description] <
returns#()
>
{
field# = value#.times#(multiplier#)
}
}
public? final? class SomeClass : R|kotlin/Any| {
public? constructor(multiplier: Int?): R|SomeClass| {
super<R|kotlin/Any|>()
}
public? final? var someInt: Int = IntegerLiteral(0)
public? get(): Int
[Contract description] <
returnsNotNull#()
>
{
^ IntegerLiteral(1)
}
public? set(value: Int): R|kotlin/Unit|
[Contract description] <
returns#().implies#(!=(value#, Null(null)))
>
{
value# ?: throw NullArgumentException#()
field# = value#
}
}
@@ -0,0 +1,8 @@
// new contracts syntax for simple functions
fun test1(s: MyClass?) contract [returns() implies (s != null), returns() implies (s is MySubClass)] {
test_1()
}
fun test2() contract [returnsNotNull()] {
test2()
}
@@ -0,0 +1,16 @@
FILE: simpleFunctionsContractDescription.kt
public? final? fun test1(s: MyClass?): R|kotlin/Unit|
[Contract description] <
returns#().implies#(!=(s#, Null(null))),
returns#().implies#((s# is MySubClass))
>
{
test_1#()
}
public? final? fun test2(): R|kotlin/Unit|
[Contract description] <
returnsNotNull#()
>
{
test2#()
}
@@ -60,11 +60,6 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/constructorOfAnonymousObject.kt");
}
@TestMetadata("contractDescription.kt")
public void testContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contractDescription.kt");
}
@TestMetadata("derivedClass.kt")
public void testDerivedClass() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/derivedClass.kt");
@@ -164,6 +159,65 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
public void testWhere() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/where.kt");
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Contracts extends AbstractRawFirBuilderTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doRawFirTest, this, testDataFilePath);
}
public void testAllFilesPresentInContracts() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NewSyntax extends AbstractRawFirBuilderTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doRawFirTest, this, testDataFilePath);
}
public void testAllFilesPresentInNewSyntax() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("functionWithBothOldAndNewSyntaxContractDescription.kt")
public void testFunctionWithBothOldAndNewSyntaxContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/functionWithBothOldAndNewSyntaxContractDescription.kt");
}
@TestMetadata("propertyAccessorsContractDescription.kt")
public void testPropertyAccessorsContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/propertyAccessorsContractDescription.kt");
}
@TestMetadata("simpleFunctionsContractDescription.kt")
public void testSimpleFunctionsContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/simpleFunctionsContractDescription.kt");
}
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class OldSyntax extends AbstractRawFirBuilderTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doRawFirTest, this, testDataFilePath);
}
public void testAllFilesPresentInOldSyntax() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("contractDescription.kt")
public void testContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax/contractDescription.kt");
}
}
}
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions")
@@ -60,11 +60,6 @@ public class FirVisualizerForRawFirDataGenerated extends AbstractFirVisualizer {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/constructorOfAnonymousObject.kt");
}
@TestMetadata("contractDescription.kt")
public void testContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contractDescription.kt");
}
@TestMetadata("derivedClass.kt")
public void testDerivedClass() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/derivedClass.kt");
@@ -164,6 +159,65 @@ public class FirVisualizerForRawFirDataGenerated extends AbstractFirVisualizer {
public void testWhere() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/where.kt");
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Contracts extends AbstractFirVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doFirBuilderDataTest, this, testDataFilePath);
}
public void testAllFilesPresentInContracts() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NewSyntax extends AbstractFirVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doFirBuilderDataTest, this, testDataFilePath);
}
public void testAllFilesPresentInNewSyntax() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("functionWithBothOldAndNewSyntaxContractDescription.kt")
public void testFunctionWithBothOldAndNewSyntaxContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/functionWithBothOldAndNewSyntaxContractDescription.kt");
}
@TestMetadata("propertyAccessorsContractDescription.kt")
public void testPropertyAccessorsContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/propertyAccessorsContractDescription.kt");
}
@TestMetadata("simpleFunctionsContractDescription.kt")
public void testSimpleFunctionsContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/simpleFunctionsContractDescription.kt");
}
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class OldSyntax extends AbstractFirVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doFirBuilderDataTest, this, testDataFilePath);
}
public void testAllFilesPresentInOldSyntax() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("contractDescription.kt")
public void testContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax/contractDescription.kt");
}
}
}
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions")
@@ -60,11 +60,6 @@ public class PsiVisualizerForRawFirDataGenerated extends AbstractPsiVisualizer {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/constructorOfAnonymousObject.kt");
}
@TestMetadata("contractDescription.kt")
public void testContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contractDescription.kt");
}
@TestMetadata("derivedClass.kt")
public void testDerivedClass() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/derivedClass.kt");
@@ -164,6 +159,65 @@ public class PsiVisualizerForRawFirDataGenerated extends AbstractPsiVisualizer {
public void testWhere() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/where.kt");
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Contracts extends AbstractPsiVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doFirBuilderDataTest, this, testDataFilePath);
}
public void testAllFilesPresentInContracts() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NewSyntax extends AbstractPsiVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doFirBuilderDataTest, this, testDataFilePath);
}
public void testAllFilesPresentInNewSyntax() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("functionWithBothOldAndNewSyntaxContractDescription.kt")
public void testFunctionWithBothOldAndNewSyntaxContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/functionWithBothOldAndNewSyntaxContractDescription.kt");
}
@TestMetadata("propertyAccessorsContractDescription.kt")
public void testPropertyAccessorsContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/propertyAccessorsContractDescription.kt");
}
@TestMetadata("simpleFunctionsContractDescription.kt")
public void testSimpleFunctionsContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax/simpleFunctionsContractDescription.kt");
}
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class OldSyntax extends AbstractPsiVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doFirBuilderDataTest, this, testDataFilePath);
}
public void testAllFilesPresentInOldSyntax() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("contractDescription.kt")
public void testContractDescription() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax/contractDescription.kt");
}
}
}
}
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions")