Separate input and result data in constraint system test

input file: *.constraints
 result file: *.bounds
This commit is contained in:
Svetlana Isakova
2015-06-27 15:38:56 +03:00
parent 07937a27eb
commit 82acce4767
24 changed files with 134 additions and 57 deletions
@@ -0,0 +1,4 @@
VARIABLES T
SUBTYPE T Int
SUPERTYPE T String
@@ -0,0 +1,4 @@
VARIABLES T
SUBTYPE T Int
SUPERTYPE T Int
@@ -0,0 +1,3 @@
VARIABLES T
SUBTYPE List<T> Int
@@ -0,0 +1,3 @@
VARIABLES T
SUBTYPE Any Any
@@ -0,0 +1,4 @@
VARIABLES T
SUBTYPE T Int
SUBTYPE T String weak
@@ -0,0 +1,4 @@
VARIABLES T
SUBTYPE T B
SUPERTYPE T A
@@ -0,0 +1,4 @@
VARIABLES T
SUBTYPE T A
SUBTYPE T B
@@ -0,0 +1,4 @@
VARIABLES T
SUBTYPE T A
SUPERTYPE T C
@@ -0,0 +1,5 @@
VARIABLES T
SUBTYPE T A
SUPERTYPE T B
SUPERTYPE T C
@@ -0,0 +1,4 @@
VARIABLES T
SUPERTYPE T IntegerValueType(1000)
SUBTYPE T Byte
@@ -0,0 +1,4 @@
VARIABLES T
SUPERTYPE T IntegerValueType(1)
SUPERTYPE T IntegerValueType(10000000000)
@@ -0,0 +1,4 @@
VARIABLES T
SUPERTYPE T IntegerValueType(1)
SUBTYPE T Any
@@ -0,0 +1,4 @@
VARIABLES T
SUPERTYPE T IntegerValueType(1)
SUPERTYPE T String
@@ -0,0 +1,4 @@
VARIABLES T
SUPERTYPE T IntegerValueType(1)
SUPERTYPE T IntegerValueType(1000)
@@ -0,0 +1,4 @@
VARIABLES T
SUPERTYPE T IntegerValueType(1)
SUBTYPE T Byte
@@ -0,0 +1,3 @@
VARIABLES T
SUPERTYPE T IntegerValueType(1)
@@ -0,0 +1,4 @@
VARIABLES T
SUPERTYPE T IntegerValueType(1)
SUBTYPE T Short
@@ -0,0 +1,3 @@
VARIABLES T P
SUBTYPE T Int
@@ -0,0 +1,3 @@
VARIABLES T
SUBTYPE Consumer<A> Consumer<T>
@@ -0,0 +1,3 @@
VARIABLES T
SUBTYPE My<T> My<A>
@@ -0,0 +1,3 @@
VARIABLES T
SUBTYPE Producer<A> Producer<T>
@@ -37,7 +37,7 @@ import java.util.regex.Pattern
abstract public class AbstractConstraintSystemTest() : JetLiteFixture() { abstract public class AbstractConstraintSystemTest() : JetLiteFixture() {
private val typePattern = """([\w|<|>|\(|\)]+)""" private val typePattern = """([\w|<|>|\(|\)]+)"""
val constraintPattern = Pattern.compile("""(SUBTYPE|SUPERTYPE)\s+${typePattern}\s+${typePattern}\s+(weak)?""", Pattern.MULTILINE) val constraintPattern = Pattern.compile("""(SUBTYPE|SUPERTYPE)\s+$typePattern\s+$typePattern\s*(weak)?""")
val variablesPattern = Pattern.compile("VARIABLES\\s+(.*)") val variablesPattern = Pattern.compile("VARIABLES\\s+(.*)")
private var _typeResolver: TypeResolver? = null private var _typeResolver: TypeResolver? = null
@@ -78,19 +78,19 @@ abstract public class AbstractConstraintSystemTest() : JetLiteFixture() {
} }
public fun doTest(filePath: String) { public fun doTest(filePath: String) {
val file = File(filePath) val constraintsFile = File(filePath)
val fileText = JetTestUtils.doLoadFile(file)!! val constraintsFileText = JetTestUtils.doLoadFile(constraintsFile)!!
val constraintSystem = ConstraintSystemImpl() val constraintSystem = ConstraintSystemImpl()
val typeParameterDescriptors = LinkedHashMap<TypeParameterDescriptor, Variance>() val typeParameterDescriptors = LinkedHashMap<TypeParameterDescriptor, Variance>()
val variables = parseVariables(fileText) val variables = parseVariables(constraintsFileText)
for (variable in variables) { for (variable in variables) {
typeParameterDescriptors.put(testDeclarations.getParameterDescriptor(variable), Variance.INVARIANT) typeParameterDescriptors.put(testDeclarations.getParameterDescriptor(variable), Variance.INVARIANT)
} }
constraintSystem.registerTypeVariables(typeParameterDescriptors) constraintSystem.registerTypeVariables(typeParameterDescriptors)
val constraints = parseConstraints(fileText) val constraints = parseConstraints(constraintsFileText)
for (constraint in constraints) { for (constraint in constraints) {
val firstType = testDeclarations.getType(constraint.firstType) val firstType = testDeclarations.getType(constraint.firstType)
val secondType = testDeclarations.getType(constraint.secondType) val secondType = testDeclarations.getType(constraint.secondType)
@@ -112,7 +112,8 @@ abstract public class AbstractConstraintSystemTest() : JetLiteFixture() {
result append "${typeParameter.getName()}=${resultType?.let{ DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) }}\n" result append "${typeParameter.getName()}=${resultType?.let{ DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) }}\n"
} }
JetTestUtils.assertEqualsToFile(file, "${getConstraintsText(fileText)}${resultingStatus}\n\n${result}\n") val boundsFile = File(filePath.replace("constraints", "bounds"))
JetTestUtils.assertEqualsToFile(boundsFile, "$constraintsFileText\n\n$resultingStatus\n\n$result\n")
} }
class MyConstraint(val kind: MyConstraintKind, val firstType: String, val secondType: String, val isWeak: Boolean) class MyConstraint(val kind: MyConstraintKind, val firstType: String, val secondType: String, val isWeak: Boolean)
@@ -142,6 +143,4 @@ abstract public class AbstractConstraintSystemTest() : JetLiteFixture() {
} }
return constraints return constraints
} }
private fun getConstraintsText(text: String) = text.substring(0, text.indexOf("type parameter bounds"))
} }
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
public class ConstraintSystemTestGenerated extends AbstractConstraintSystemTest { public class ConstraintSystemTestGenerated extends AbstractConstraintSystemTest {
public void testAllFilesPresentInConstraintSystem() throws Exception { public void testAllFilesPresentInConstraintSystem() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem"), Pattern.compile("^(.+)\\.bounds$"), true); JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem"), Pattern.compile("^(.+)\\.constraints$"), true);
} }
@TestMetadata("compiler/testData/constraintSystem/checkStatus") @TestMetadata("compiler/testData/constraintSystem/checkStatus")
@@ -40,36 +40,36 @@ public class ConstraintSystemTestGenerated extends AbstractConstraintSystemTest
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
public static class CheckStatus extends AbstractConstraintSystemTest { public static class CheckStatus extends AbstractConstraintSystemTest {
public void testAllFilesPresentInCheckStatus() throws Exception { public void testAllFilesPresentInCheckStatus() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/checkStatus"), Pattern.compile("^(.+)\\.bounds$"), true); JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/checkStatus"), Pattern.compile("^(.+)\\.constraints$"), true);
} }
@TestMetadata("conflictingConstraints.bounds") @TestMetadata("conflictingConstraints.constraints")
public void testConflictingConstraints() throws Exception { public void testConflictingConstraints() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/conflictingConstraints.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/conflictingConstraints.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("successful.bounds") @TestMetadata("successful.constraints")
public void testSuccessful() throws Exception { public void testSuccessful() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/successful.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/successful.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("typeConstructorMismatch.bounds") @TestMetadata("typeConstructorMismatch.constraints")
public void testTypeConstructorMismatch() throws Exception { public void testTypeConstructorMismatch() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/typeConstructorMismatch.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/typeConstructorMismatch.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("unknownParameters.bounds") @TestMetadata("unknownParameters.constraints")
public void testUnknownParameters() throws Exception { public void testUnknownParameters() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/unknownParameters.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/unknownParameters.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("violatedUpperBound.bounds") @TestMetadata("violatedUpperBound.constraints")
public void testViolatedUpperBound() throws Exception { public void testViolatedUpperBound() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/violatedUpperBound.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/checkStatus/violatedUpperBound.constraints");
doTest(fileName); doTest(fileName);
} }
} }
@@ -79,30 +79,30 @@ public class ConstraintSystemTestGenerated extends AbstractConstraintSystemTest
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
public static class ComputeValues extends AbstractConstraintSystemTest { public static class ComputeValues extends AbstractConstraintSystemTest {
public void testAllFilesPresentInComputeValues() throws Exception { public void testAllFilesPresentInComputeValues() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/computeValues"), Pattern.compile("^(.+)\\.bounds$"), true); JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/computeValues"), Pattern.compile("^(.+)\\.constraints$"), true);
} }
@TestMetadata("contradiction.bounds") @TestMetadata("contradiction.constraints")
public void testContradiction() throws Exception { public void testContradiction() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/computeValues/contradiction.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/computeValues/contradiction.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("subTypeOfUpperBounds.bounds") @TestMetadata("subTypeOfUpperBounds.constraints")
public void testSubTypeOfUpperBounds() throws Exception { public void testSubTypeOfUpperBounds() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/computeValues/subTypeOfUpperBounds.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/computeValues/subTypeOfUpperBounds.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("superTypeOfLowerBounds1.bounds") @TestMetadata("superTypeOfLowerBounds1.constraints")
public void testSuperTypeOfLowerBounds1() throws Exception { public void testSuperTypeOfLowerBounds1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds1.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds1.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("superTypeOfLowerBounds2.bounds") @TestMetadata("superTypeOfLowerBounds2.constraints")
public void testSuperTypeOfLowerBounds2() throws Exception { public void testSuperTypeOfLowerBounds2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds2.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds2.constraints");
doTest(fileName); doTest(fileName);
} }
} }
@@ -112,54 +112,54 @@ public class ConstraintSystemTestGenerated extends AbstractConstraintSystemTest
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
public static class IntegerValueTypes extends AbstractConstraintSystemTest { public static class IntegerValueTypes extends AbstractConstraintSystemTest {
public void testAllFilesPresentInIntegerValueTypes() throws Exception { public void testAllFilesPresentInIntegerValueTypes() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/integerValueTypes"), Pattern.compile("^(.+)\\.bounds$"), true); JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/integerValueTypes"), Pattern.compile("^(.+)\\.constraints$"), true);
} }
@TestMetadata("byteOverflow.bounds") @TestMetadata("byteOverflow.constraints")
public void testByteOverflow() throws Exception { public void testByteOverflow() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/byteOverflow.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/byteOverflow.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("defaultLong.bounds") @TestMetadata("defaultLong.constraints")
public void testDefaultLong() throws Exception { public void testDefaultLong() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/defaultLong.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/defaultLong.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("numberAndAny.bounds") @TestMetadata("numberAndAny.constraints")
public void testNumberAndAny() throws Exception { public void testNumberAndAny() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/numberAndAny.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/numberAndAny.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("numberAndString.bounds") @TestMetadata("numberAndString.constraints")
public void testNumberAndString() throws Exception { public void testNumberAndString() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/numberAndString.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/numberAndString.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("severalNumbers.bounds") @TestMetadata("severalNumbers.constraints")
public void testSeveralNumbers() throws Exception { public void testSeveralNumbers() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/severalNumbers.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/severalNumbers.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("simpleByte.bounds") @TestMetadata("simpleByte.constraints")
public void testSimpleByte() throws Exception { public void testSimpleByte() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/simpleByte.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/simpleByte.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("simpleInt.bounds") @TestMetadata("simpleInt.constraints")
public void testSimpleInt() throws Exception { public void testSimpleInt() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/simpleInt.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/simpleInt.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("simpleShort.bounds") @TestMetadata("simpleShort.constraints")
public void testSimpleShort() throws Exception { public void testSimpleShort() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/simpleShort.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/integerValueTypes/simpleShort.constraints");
doTest(fileName); doTest(fileName);
} }
} }
@@ -169,12 +169,12 @@ public class ConstraintSystemTestGenerated extends AbstractConstraintSystemTest
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
public static class SeveralVariables extends AbstractConstraintSystemTest { public static class SeveralVariables extends AbstractConstraintSystemTest {
public void testAllFilesPresentInSeveralVariables() throws Exception { public void testAllFilesPresentInSeveralVariables() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/severalVariables"), Pattern.compile("^(.+)\\.bounds$"), true); JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/severalVariables"), Pattern.compile("^(.+)\\.constraints$"), true);
} }
@TestMetadata("simpleDependency.bounds") @TestMetadata("simpleDependency.constraints")
public void testSimpleDependency() throws Exception { public void testSimpleDependency() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/severalVariables/simpleDependency.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/severalVariables/simpleDependency.constraints");
doTest(fileName); doTest(fileName);
} }
} }
@@ -184,24 +184,24 @@ public class ConstraintSystemTestGenerated extends AbstractConstraintSystemTest
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
public static class Variance extends AbstractConstraintSystemTest { public static class Variance extends AbstractConstraintSystemTest {
public void testAllFilesPresentInVariance() throws Exception { public void testAllFilesPresentInVariance() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/variance"), Pattern.compile("^(.+)\\.bounds$"), true); JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/constraintSystem/variance"), Pattern.compile("^(.+)\\.constraints$"), true);
} }
@TestMetadata("consumer.bounds") @TestMetadata("consumer.constraints")
public void testConsumer() throws Exception { public void testConsumer() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/variance/consumer.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/variance/consumer.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("invariant.bounds") @TestMetadata("invariant.constraints")
public void testInvariant() throws Exception { public void testInvariant() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/variance/invariant.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/variance/invariant.constraints");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("producer.bounds") @TestMetadata("producer.constraints")
public void testProducer() throws Exception { public void testProducer() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/variance/producer.bounds"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/variance/producer.constraints");
doTest(fileName); doTest(fileName);
} }
} }
@@ -158,7 +158,7 @@ fun main(args: Array<String>) {
} }
testClass(javaClass<AbstractConstraintSystemTest>()) { testClass(javaClass<AbstractConstraintSystemTest>()) {
model("constraintSystem", extension = "bounds") model("constraintSystem", extension = "constraints")
} }
testClass(javaClass<AbstractJetParsingTest>()) { testClass(javaClass<AbstractJetParsingTest>()) {