Skip to content

Commit

Permalink
Split the basic jvm test to avoid timing out.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corbin Smith committed Mar 6, 2020
1 parent f25caba commit f0ff3ab
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 96 deletions.
11 changes: 10 additions & 1 deletion src/test/kotlin/io/bazel/kotlin/builder/tasks/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ load("//src/test/kotlin/io/bazel/kotlin:defs.bzl", "kt_rules_test")
kt_rules_test(
name = "JdepsParserTest",
srcs = ["jvm/JdepsParserTest.java"],
size = "medium",
deps = [
"//src/main/kotlin/io/bazel/kotlin/builder/tasks",
]
)

kt_rules_test(
name = "KotlinBuilderJavabiTest",
srcs = ["jvm/KotlinBuilderJvmJavaTest.java"],
)

kt_rules_test(
name = "KotlinBuilderJvmAbiTest",
srcs = ["jvm/KotlinBuilderJvmAbiTest.java"],
)

kt_rules_test(
name = "KotlinBuilderJvmBasicTest",
srcs = ["jvm/KotlinBuilderJvmBasicTest.java"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2020 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.bazel.kotlin.builder.tasks.jvm;

import io.bazel.kotlin.builder.Deps;
import io.bazel.kotlin.builder.KotlinJvmTestBuilder;
import java.util.function.Consumer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class KotlinBuilderJvmAbiTest {
private static final KotlinJvmTestBuilder ctx = new KotlinJvmTestBuilder();

private static final Consumer<KotlinJvmTestBuilder.TaskBuilder> SETUP_NORMALIZATION_TEST_SOURCES =
ctx -> {
ctx.addSource("AClass.kt", "package something;\n" + "class AClass{}");
ctx.addSource("BClass.kt", "package something;\n" + "class BClass{}");
ctx.outputJar().outputSrcJar();
};

@Test
public void testGeneratesAbiOnly() {
Deps.Dep d = ctx.runCompileTask(
c -> {
c.addSource("AClass.kt", "package something;" + "class AClass{}");
c.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{}");
c.outputAbiJar();
});
ctx.runCompileTask(
c -> {
c.addDirectDependencies(d);
c.addSource("Dependent.kt",
"package dep;",
"import something.AClass",
"class Dependent{}");
c.outputJar().outputSrcJar().outputJdeps();
});
}

@Test
public void testGeneratesAbiJarSource() {
ctx.runCompileTask(
c -> {
c.addSource("AClass.kt", "package something;" + "class AClass{}");
c.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{}");
// declaring outputJdeps also asserts existance after compile.
c.outputJar();
c.outputSrcJar();
c.outputJdeps();
c.outputAbiJar();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,50 +61,6 @@ public void testSimpleMixedModeCompile() {
DirectoryType.CLASSES, "something/AClass.class", "something/AnotherClass.class");
}

@Test
public void testGeneratesJDeps() {
ctx.runCompileTask(
c -> {
c.addSource("AClass.kt", "package something;" + "class AClass{}");
c.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{}");
// declaring outputJdeps also asserts existence after compile.
c.outputJar().outputSrcJar().outputJdeps();
});
}

@Test
public void testGeneratesAbiOnly() {
Deps.Dep d = ctx.runCompileTask(
c -> {
c.addSource("AClass.kt", "package something;" + "class AClass{}");
c.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{}");
c.outputAbiJar();
});
ctx.runCompileTask(
c -> {
c.addDirectDependencies(d);
c.addSource("Dependent.kt",
"package dep;",
"import something.AClass",
"class Dependent{}");
c.outputJar().outputSrcJar().outputJdeps();
});
}

@Test
public void testGeneratesAbiJarSource() {
ctx.runCompileTask(
c -> {
c.addSource("AClass.kt", "package something;" + "class AClass{}");
c.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{}");
// declaring outputJdeps also asserts existance after compile.
c.outputJar();
c.outputSrcJar();
c.outputJdeps();
c.outputAbiJar();
});
}

@Test
public void testKotlinErrorRendering() {
ctx.runFailingCompileTaskAndValidateOutput(
Expand All @@ -117,57 +73,6 @@ public void testKotlinErrorRendering() {
lines -> assertThat(lines.get(0)).startsWith(ctx.toPlatform("sources/AClass")));
}

@Test
public void testMixedBiReferences() {
ctx.runCompileTask(
ctx -> {
ctx.addSource(
"AClass.java",
"package a;",
"",
"import b.BClass;",
"",
"public class AClass {",
" static BClass b = new BClass();",
"}");
ctx.addSource(
"BClass.kt",
"package b",
"",
"import a.AClass",
"",
"class BClass() {",
" val a = AClass()",
"}");
ctx.outputSrcJar()
.outputJar();
});
ctx.assertFilesExist(DirectoryType.CLASSES, "a/AClass.class", "b/BClass.class");
}

@Test
public void testCompileSingleJavaFile() {
ctx.runCompileTask(
(ctx) -> {
ctx.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{}");
ctx.outputSrcJar()
.outputJar();
});
}

@Test
public void testJavaErrorRendering() {
ctx.runFailingCompileTaskAndValidateOutput(
() ->
ctx.runCompileTask(
c -> {
c.addSource("AClass.kt", "package something;" + "class AClass{}");
c.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{");
c.outputJar().outputSrcJar();
}),
lines -> assertThat(lines.get(0)).startsWith(ctx.toPlatform("sources/AnotherClass")));
}

@Test
public void testCompiledJarIsNormalized() {
Deps.Dep previous = ctx.runCompileTask(SETUP_NORMALIZATION_TEST_SOURCES);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2020 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.bazel.kotlin.builder.tasks.jvm;

import io.bazel.kotlin.builder.DirectoryType;
import io.bazel.kotlin.builder.KotlinJvmTestBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import static com.google.common.truth.Truth.assertThat;

@RunWith(JUnit4.class)
public class KotlinBuilderJvmJavaTest {
private static final KotlinJvmTestBuilder ctx = new KotlinJvmTestBuilder();

@Test
public void testSimpleMixedModeCompile() {
ctx.runCompileTask(
c -> {
c.addSource(
"AClass.kt",
"package something;" + "class AClass{}"
);
c.addSource(
"AnotherClass.java",
"package something;",
"",
"class AnotherClass{}"
);
c.outputJar().outputSrcJar();
});
ctx.assertFilesExist(
DirectoryType.CLASSES, "something/AClass.class", "something/AnotherClass.class");
}

@Test
public void testGeneratesJDeps() {
ctx.runCompileTask(
c -> {
c.addSource("AClass.kt", "package something;" + "class AClass{}");
c.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{}");
// declaring outputJdeps also asserts existence after compile.
c.outputJar().outputSrcJar().outputJdeps();
});
}

@Test
public void testMixedBiReferences() {
ctx.runCompileTask(
ctx -> {
ctx.addSource(
"AClass.java",
"package a;",
"",
"import b.BClass;",
"",
"public class AClass {",
" static BClass b = new BClass();",
"}");
ctx.addSource(
"BClass.kt",
"package b",
"",
"import a.AClass",
"",
"class BClass() {",
" val a = AClass()",
"}");
ctx.outputSrcJar()
.outputJar();
});
ctx.assertFilesExist(DirectoryType.CLASSES, "a/AClass.class", "b/BClass.class");
}

@Test
public void testCompileSingleJavaFile() {
ctx.runCompileTask(
(ctx) -> {
ctx.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{}");
ctx.outputSrcJar()
.outputJar();
});
}

@Test
public void testJavaErrorRendering() {
ctx.runFailingCompileTaskAndValidateOutput(
() ->
ctx.runCompileTask(
c -> {
c.addSource("AClass.kt", "package something;" + "class AClass{}");
c.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{");
c.outputJar().outputSrcJar();
}),
lines -> assertThat(lines.get(0)).startsWith(ctx.toPlatform("sources/AnotherClass")));
}
}

0 comments on commit f0ff3ab

Please sign in to comment.