Sort out blackBox*() methods
- get rid of blackBox(), extract tests into files - delete single-file usages of blackBoxMultiFile() - inline some other blackBox methods - suppress exception in blackBoxWithJava()
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
class A() {
|
||||||
|
class object {
|
||||||
|
val value = 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() = if (A.value == 10) "OK" else "Fail ${A.value}"
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fun f(x: Long, zzz: Long = 1): Long
|
||||||
|
{
|
||||||
|
return if (x <= 1) zzz
|
||||||
|
else f(x-1, x*zzz)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String
|
||||||
|
{
|
||||||
|
val six: Long = 6;
|
||||||
|
if (f(six) != 720.toLong()) return "Fail"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
fun box() = if ((1 ?: 0) == 1) "OK" else "fail"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun box(): String {
|
||||||
|
if (3.compareTo(2) != 1) return "Fail #1"
|
||||||
|
if (5.toByte().compareTo(10.toLong()) >= 0) return "Fail #2"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -248,9 +248,7 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testClassObjFields() {
|
public void testClassObjFields() {
|
||||||
loadText("class A() { class object { val value = 10 } }\n" +
|
blackBoxFile("classes/classObjectField.kt");
|
||||||
"fun box() = if(A.value == 10) \"OK\" else \"fail\"");
|
|
||||||
blackBox();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPrivateOuterProperty() {
|
public void testPrivateOuterProperty() {
|
||||||
@@ -434,15 +432,15 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt2395() {
|
public void testKt2395() {
|
||||||
blackBoxMultiFile("regressions/kt2395.kt");
|
blackBoxFile("regressions/kt2395.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt2566() {
|
public void testKt2566() {
|
||||||
blackBoxMultiFile("regressions/kt2566.kt");
|
blackBoxFile("regressions/kt2566.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt2566_2() {
|
public void testKt2566_2() {
|
||||||
blackBoxMultiFile("regressions/kt2566_2.kt");
|
blackBoxFile("regressions/kt2566_2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt2477() {
|
public void testKt2477() {
|
||||||
@@ -450,11 +448,11 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt2485() {
|
public void testKt2485() {
|
||||||
blackBoxMultiFile("regressions/kt2485.kt");
|
blackBoxFile("regressions/kt2485.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt2482() {
|
public void testKt2482() {
|
||||||
blackBoxMultiFile("regressions/kt2482.kt");
|
blackBoxFile("regressions/kt2482.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt2288() {
|
public void testKt2288() {
|
||||||
|
|||||||
@@ -158,24 +158,19 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
blackBoxFile(filename, false);
|
blackBoxFile(filename, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blackBoxFile(String filename, boolean classPathInTheSameClassLoader) {
|
private void blackBoxFile(String filename, boolean classPathInTheSameClassLoader) {
|
||||||
loadFile(filename);
|
loadFile(filename);
|
||||||
blackBox(classPathInTheSameClassLoader);
|
blackBox(classPathInTheSameClassLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blackBoxFileByFullPath(String filename) {
|
protected void blackBoxFileByFullPath(String filename) {
|
||||||
loadFileByFullPath(filename);
|
loadFileByFullPath(filename);
|
||||||
blackBox();
|
blackBox(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blackBoxMultiFile(String... filenames) {
|
protected void blackBoxMultiFile(String... filenames) {
|
||||||
loadFiles(filenames);
|
loadFiles(filenames);
|
||||||
blackBox();
|
blackBox(false);
|
||||||
}
|
|
||||||
|
|
||||||
protected void blackBoxMultiFile(boolean classPathInTheSameClassLoader, String... filenames) {
|
|
||||||
loadFiles(filenames);
|
|
||||||
blackBox(classPathInTheSameClassLoader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -217,11 +212,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blackBox() {
|
private void blackBox(boolean classPathInTheSameClassLoader) {
|
||||||
blackBox(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void blackBox(boolean classPathInTheSameClassLoader) {
|
|
||||||
GenerationState state = generateClassesInFileGetState();
|
GenerationState state = generateClassesInFileGetState();
|
||||||
|
|
||||||
GeneratedClassLoader loader = createClassLoader(state.getFactory(), classPathInTheSameClassLoader);
|
GeneratedClassLoader loader = createClassLoader(state.getFactory(), classPathInTheSameClassLoader);
|
||||||
@@ -280,15 +271,15 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blackBoxFileWithJavaByFullPath(@NotNull String ktFile) throws Exception {
|
protected void blackBoxFileWithJavaByFullPath(@NotNull String ktFile) {
|
||||||
blackBoxFileWithJava(ktFile.substring("compiler/testData/codegen/".length()), false);
|
blackBoxFileWithJava(ktFile.substring("compiler/testData/codegen/".length()), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blackBoxFileWithJava(@NotNull String ktFile) throws Exception {
|
protected void blackBoxFileWithJava(@NotNull String ktFile) {
|
||||||
blackBoxFileWithJava(ktFile, false);
|
blackBoxFileWithJava(ktFile, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blackBoxFileWithJava(@NotNull String ktFile, boolean classPathInTheSameClassLoader) throws Exception {
|
protected void blackBoxFileWithJava(@NotNull String ktFile, boolean classPathInTheSameClassLoader) {
|
||||||
File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
|
File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
|
||||||
|
|
||||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||||
@@ -297,19 +288,24 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
blackBoxFile(ktFile, classPathInTheSameClassLoader);
|
blackBoxFile(ktFile, classPathInTheSameClassLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected File compileJava(@NotNull String filename) throws IOException {
|
protected File compileJava(@NotNull String filename) {
|
||||||
File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes");
|
try {
|
||||||
JetTestUtils.mkdirs(javaClassesTempDirectory);
|
File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes");
|
||||||
String classPath = "out/production/runtime" + File.pathSeparator + JetTestUtils.getAnnotationsJar().getPath();
|
JetTestUtils.mkdirs(javaClassesTempDirectory);
|
||||||
List<String> options = Arrays.asList(
|
String classPath = "out/production/runtime" + File.pathSeparator + JetTestUtils.getAnnotationsJar().getPath();
|
||||||
"-classpath", classPath,
|
List<String> options = Arrays.asList(
|
||||||
"-d", javaClassesTempDirectory.getPath()
|
"-classpath", classPath,
|
||||||
);
|
"-d", javaClassesTempDirectory.getPath()
|
||||||
|
);
|
||||||
|
|
||||||
File javaFile = new File("compiler/testData/codegen/" + filename);
|
File javaFile = new File("compiler/testData/codegen/" + filename);
|
||||||
JetTestUtils.compileJavaFiles(Collections.singleton(javaFile), options);
|
JetTestUtils.compileJavaFiles(Collections.singleton(javaFile), options);
|
||||||
|
|
||||||
return javaClassesTempDirectory;
|
return javaClassesTempDirectory;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw ExceptionUtils.rethrow(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GeneratedClassLoader createClassLoader(ClassFileFactory codegens) {
|
protected GeneratedClassLoader createClassLoader(ClassFileFactory codegens) {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
|
|
||||||
setUpEnvironment(generateAssertions, false, javaClassesTempDirectory);
|
setUpEnvironment(generateAssertions, false, javaClassesTempDirectory);
|
||||||
|
|
||||||
blackBoxMultiFile(false, "notNullAssertions/AssertionChecker.kt", ktFile);
|
blackBoxMultiFile("notNullAssertions/AssertionChecker.kt", ktFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGenerateAssertions() throws Exception {
|
public void testGenerateAssertions() throws Exception {
|
||||||
|
|||||||
@@ -300,9 +300,8 @@ public class PrimitiveTypesTest extends CodegenTestCase {
|
|||||||
blackBoxFile("regressions/kt518.kt");
|
blackBoxFile("regressions/kt518.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt711 () throws Exception {
|
public void testKt711() {
|
||||||
loadText("fun box() = if ((1 ?: 0) == 1) \"OK\" else \"fail\"");
|
blackBoxFile("primitiveTypes/kt711.kt");
|
||||||
blackBox();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSureNonnull () throws Exception {
|
public void testSureNonnull () throws Exception {
|
||||||
@@ -325,25 +324,12 @@ public class PrimitiveTypesTest extends CodegenTestCase {
|
|||||||
assertTrue(generateToText().contains("IFNULL"));
|
assertTrue(generateToText().contains("IFNULL"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt737() throws Exception {
|
public void testKt737() {
|
||||||
loadText("fun box() = if(3.compareTo(2) != 1) \"fail\" else if(5.toByte().compareTo(10.toLong()) >= 0) \"fail\" else \"OK\"");
|
blackBoxFile("primitiveTypes/kt737.kt");
|
||||||
blackBox();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt665() throws Exception {
|
public void testKt665() {
|
||||||
loadText("fun f(x: Long, zzz: Long = 1): Long\n" +
|
blackBoxFile("primitiveTypes/kt665.kt");
|
||||||
"{\n" +
|
|
||||||
" return if (x <= 1) zzz\n" +
|
|
||||||
" else f(x-1, x*zzz)\n" +
|
|
||||||
"}\n" +
|
|
||||||
"\n" +
|
|
||||||
"fun box() : String\n" +
|
|
||||||
"{\n" +
|
|
||||||
" val six: Long = 6;\n" +
|
|
||||||
" System.out?.println(f(six))\n" +
|
|
||||||
" return \"OK\"" +
|
|
||||||
"}");
|
|
||||||
blackBox();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt752 () {
|
public void testKt752 () {
|
||||||
|
|||||||
@@ -93,10 +93,8 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
blackBoxFile("regressions/kt274.kt");
|
blackBoxFile("regressions/kt274.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
//from ClassGenTest
|
public void testKt344 () {
|
||||||
public void testKt344 () throws Exception {
|
blackBoxFile("regressions/kt344.kt");
|
||||||
loadFile("regressions/kt344.kt");
|
|
||||||
blackBox();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//from ExtensionFunctionsTest
|
//from ExtensionFunctionsTest
|
||||||
|
|||||||
Reference in New Issue
Block a user