split dagger example test as it can fail on independently and reorganize a bit
diff --git a/.bazelrc b/.bazelrc
index 1fb0c7a..b3686d8 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -1 +1,2 @@
build --strategy=KotlinCompile=worker
+build --test_output=errors
diff --git a/tests/integrationtests/BUILD b/tests/integrationtests/BUILD
index e985ee0..0d16629 100644
--- a/tests/integrationtests/BUILD
+++ b/tests/integrationtests/BUILD
@@ -16,8 +16,6 @@
test_suite(
name = "integrationtests",
tests=[
- "//tests/integrationtests/jvm:basic_tests",
- "//tests/integrationtests/jvm:annoation_processing_tests",
- "//tests/integrationtests/jvm/basic:test_friends_tests"
+ "//tests/integrationtests/jvm"
]
)
\ No newline at end of file
diff --git a/tests/integrationtests/jvm/BUILD b/tests/integrationtests/jvm/BUILD
index 2a56567..67d50f6 100644
--- a/tests/integrationtests/jvm/BUILD
+++ b/tests/integrationtests/jvm/BUILD
@@ -22,8 +22,24 @@
)
kt_it_assertion_test(
- name = "annoation_processing_tests",
+ name = "kapt_tests",
cases = "//tests/integrationtests/jvm/kapt:cases",
- test_class="io.bazel.kotlin.testing.jvm.JvmAnnotationProcessingFunctionalTests",
+ test_class="io.bazel.kotlin.testing.jvm.KaptTests",
data = [ "//examples/dagger:coffee_app"]
)
+
+kt_it_assertion_test(
+ name = "example_tests",
+ test_class="io.bazel.kotlin.testing.jvm.JvmExampleTests",
+ data = [ "//examples/dagger:coffee_app"]
+)
+
+test_suite(
+ name = "jvm",
+ tests = [
+ ":basic_tests",
+ ":kapt_tests",
+ ":example_tests",
+ "//tests/integrationtests/jvm/basic:friends_tests"
+ ]
+)
diff --git a/tests/integrationtests/jvm/JvmExampleTests.kt b/tests/integrationtests/jvm/JvmExampleTests.kt
new file mode 100644
index 0000000..2129824
--- /dev/null
+++ b/tests/integrationtests/jvm/JvmExampleTests.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2018 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.testing.jvm
+
+import io.bazel.kotlin.testing.BasicAssertionTestCase
+import org.junit.Test
+
+/**
+ * These tests verify properties of the example.
+ */
+class JvmExampleTests: BasicAssertionTestCase() {
+ @Test
+ fun daggerExampleIsRunnable() {
+ assertExecutableRunfileSucceeds("//examples/dagger/coffee_app",
+ description = "the dagger coffee_app should execute succesfully")
+ }
+}
\ No newline at end of file
diff --git a/tests/integrationtests/jvm/JvmAnnotationProcessingFunctionalTests.kt b/tests/integrationtests/jvm/KaptTests.kt
similarity index 92%
rename from tests/integrationtests/jvm/JvmAnnotationProcessingFunctionalTests.kt
rename to tests/integrationtests/jvm/KaptTests.kt
index 1b3fbfe..2e817c7 100644
--- a/tests/integrationtests/jvm/JvmAnnotationProcessingFunctionalTests.kt
+++ b/tests/integrationtests/jvm/KaptTests.kt
@@ -18,7 +18,7 @@
import io.bazel.kotlin.testing.AssertionTestCase
import org.junit.Test
-class JvmAnnotationProcessingFunctionalTests : AssertionTestCase("tests/integrationtests/jvm/kapt") {
+class KaptTests : AssertionTestCase("tests/integrationtests/jvm/kapt") {
@Test
fun testKotlinOnlyAnnotationProcessing() {
jarTestCase("ap_kotlin.jar", description = "annotation processing should work") {
@@ -78,9 +78,4 @@
)
}
}
-
- @Test
- fun daggerExampleIsRunnable() {
- assertExecutableRunfileSucceeds("//examples/dagger/coffee_app", description = "the dagger coffee_app should execute succesfully")
- }
}
\ No newline at end of file
diff --git a/tests/integrationtests/jvm/basic/BUILD b/tests/integrationtests/jvm/basic/BUILD
index 29baf44..16950c4 100644
--- a/tests/integrationtests/jvm/basic/BUILD
+++ b/tests/integrationtests/jvm/basic/BUILD
@@ -105,7 +105,7 @@
# This test should be explicetly executed as module name mangling handling could regress otherwise.
kt_jvm_test(
- name = "test_friends_tests",
+ name = "friends_tests",
srcs = ["test_friends/TestFriendsTest.kt"],
test_class = "test.TestFriendsTest",
deps = [
diff --git a/tests/rules/AssertionTestCase.kt b/tests/rules/AssertionTestCase.kt
index a701762..0e44ea7 100644
--- a/tests/rules/AssertionTestCase.kt
+++ b/tests/rules/AssertionTestCase.kt
@@ -22,10 +22,10 @@
import java.util.jar.JarFile
import kotlin.test.fail
-class TestCaseFailedException(description: String? = null, ex: Throwable):
- AssertionError(""""$description" failed, error: ${ex.message}""", ex)
+class TestCaseFailedException(description: String? = null, ex: Throwable) :
+ AssertionError(""""$description" failed, error: ${ex.message}""", ex)
-abstract class AssertionTestCase(root: String) {
+abstract class AssertionTestCase(root: String) : BasicAssertionTestCase() {
private val testRunfileRoot: Path = Paths.get(root).also {
it.toFile().also {
assert(it.exists()) { "runfile directory $root does not exist" }
@@ -34,46 +34,65 @@
}
private inline fun runTestCase(description: String? = null, op: () -> Unit) =
- try { op() }
- catch(t: Throwable) {
- when(t) {
- is AssertionError -> throw TestCaseFailedException(description, t)
- is Exception -> throw TestCaseFailedException(description, t)
- else -> throw t
- }
+ try {
+ op()
+ } catch (t: Throwable) {
+ when (t) {
+ is AssertionError -> throw TestCaseFailedException(description, t)
+ is Exception -> throw TestCaseFailedException(description, t)
+ else -> throw t
}
+ }
private fun testCaseJar(jarName: String) = testRunfileRoot.resolve(jarName).toFile().let {
check(it.exists()) { "jar $jarName did not exist in test case root $testRunfileRoot" }
JarFile(it)
}
- private fun jarTestCase(name: String, op: JarFile.() -> Unit) { testCaseJar(name).also { op(it) } }
- protected fun jarTestCase(name: String, description: String? = null, op: JarFile.() -> Unit) { runTestCase(description, { jarTestCase(name, op) }) }
+ private fun jarTestCase(name: String, op: JarFile.() -> Unit) {
+ testCaseJar(name).also { op(it) }
+ }
+
+ protected fun jarTestCase(name: String, description: String? = null, op: JarFile.() -> Unit) {
+ runTestCase(description, { jarTestCase(name, op) })
+ }
protected fun JarFile.assertContainsEntries(vararg entries: String) {
- entries.forEach { if(this.getJarEntry(it) == null) { fail("jar ${this.name} did not contain entry $it") } }
- }
-
- protected fun JarFile.assertDoesNotContainEntries(vararg entries: String) {
- entries.forEach { if(this.getJarEntry(it) != null) { fail("jar ${this.name} contained entry $it") } }
- }
-
- private fun String.resolveDirectory(): File =
- if (startsWith("/"))
- trimStart('/').split("/").let { File(it.take(it.size - 1).joinToString(File.separator)) }
- else
- testRunfileRoot.toFile()
-
- protected fun assertExecutableRunfileSucceeds(executable: String, description: String? = null) {
- ProcessBuilder().command("bash", "-c", Paths.get(executable).fileName.toString())
- .also { it.directory(executable.resolveDirectory()) }
- .start().let {
- it.waitFor(5, TimeUnit.SECONDS)
- assert(it.exitValue() == 0) {
- throw TestCaseFailedException(description, RuntimeException("non-zero return code: ${it.exitValue()}"))
+ entries.forEach {
+ if (this.getJarEntry(it) == null) {
+ fail("jar ${this.name} did not contain entry $it")
}
}
}
+
+ protected fun JarFile.assertDoesNotContainEntries(vararg entries: String) {
+ entries.forEach {
+ if (this.getJarEntry(it) != null) {
+ fail("jar ${this.name} contained entry $it")
+ }
+ }
+ }
+
+ override fun String.resolveDirectory(): File =
+ if (startsWith("/"))
+ trimStart('/').split("/").let { File(it.take(it.size - 1).joinToString(File.separator)) }
+ else
+ testRunfileRoot.toFile()
+}
+
+abstract class BasicAssertionTestCase {
+ protected fun assertExecutableRunfileSucceeds(executable: String, description: String? = null) {
+ ProcessBuilder().command("bash", "-c", Paths.get(executable).fileName.toString())
+ .also { it.directory(executable.resolveDirectory()) }
+ .start().let {
+ it.waitFor(5, TimeUnit.SECONDS)
+ assert(it.exitValue() == 0) {
+ throw TestCaseFailedException(description, RuntimeException("non-zero return code: ${it.exitValue()}"))
+ }
+ }
+ }
+
+ protected open fun String.resolveDirectory(): File =
+ trimStart('/').split("/").let { File(it.take(it.size - 1).joinToString(File.separator)) }
}
\ No newline at end of file
diff --git a/tests/rules/defs.bzl b/tests/rules/defs.bzl
index 9a92d32..95be157 100644
--- a/tests/rules/defs.bzl
+++ b/tests/rules/defs.bzl
@@ -19,13 +19,15 @@
"//third_party/jvm/junit:junit"
]
-def kt_it_assertion_test(name, cases, test_class, data = [], deps=[]):
+def kt_it_assertion_test(name, test_class, cases=None, data = [], deps=[]):
parts=test_class.split(".")
+ if cases:
+ data = data + [cases]
kt_jvm_test(
name=name,
srcs=["%s.kt" % parts[len(parts)-1]],
deps = _TEST_COMMON_DEPS + deps,
test_class=test_class,
- data=[cases] + data,
+ data=data,
visibility=["//visibility:private"]
)
\ No newline at end of file