From f002493218298cfcf19cba74b3a02aac18276261 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 10 Oct 2017 09:06:02 +0300 Subject: [PATCH] Multiplatform test annotations Actual annotations are provided in kotlin-test-junit on JVM side and in kotlin-test-js on JS side. #KT-19696 --- .../annotations-common/build.gradle | 24 ++++++++++ .../main/kotlin/kotlin.test/Annotations.kt | 37 +++++++++++++++ libraries/kotlin.test/common/build.gradle | 1 + .../common/src/main/kotlin/org/junit/Test.kt | 3 ++ .../kotlin/test/tests/AnnotationsTest.kt | 45 +++++++++++++++++++ .../kotlin/test/tests/BasicAssertionsTest.kt | 1 - libraries/kotlin.test/js/build.gradle | 3 +- .../js/src/main/kotlin/org/junit/junitTest.kt | 2 +- libraries/kotlin.test/junit/build.gradle | 5 ++- .../junit/src/main/kotlin/Annotations.kt | 25 +++++++++++ libraries/kotlin.test/jvm/build.gradle | 3 +- .../src/test/kotlin/BasicAssertionsJVMTest.kt | 1 - .../test/kotlin/CollectionAssertionTest.kt | 2 +- .../jvm/src/test/kotlin/TestJVMTest.kt | 1 - settings.gradle | 2 + 15 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 libraries/kotlin.test/annotations-common/build.gradle create mode 100644 libraries/kotlin.test/annotations-common/src/main/kotlin/kotlin.test/Annotations.kt create mode 100644 libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/AnnotationsTest.kt create mode 100644 libraries/kotlin.test/junit/src/main/kotlin/Annotations.kt diff --git a/libraries/kotlin.test/annotations-common/build.gradle b/libraries/kotlin.test/annotations-common/build.gradle new file mode 100644 index 00000000000..801490e8ffc --- /dev/null +++ b/libraries/kotlin.test/annotations-common/build.gradle @@ -0,0 +1,24 @@ +description = 'Kotlin Test Annotations Common' + +apply plugin: 'kotlin-platform-common' + +configurePublishing(project) + + +dependencies { + compile project(':kotlin-stdlib-common') +} + +jar { + manifestAttributes(manifest, project, 'Test') +} + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.kotlin +} + +artifacts { + archives sourcesJar + archives javadocJar +} \ No newline at end of file diff --git a/libraries/kotlin.test/annotations-common/src/main/kotlin/kotlin.test/Annotations.kt b/libraries/kotlin.test/annotations-common/src/main/kotlin/kotlin.test/Annotations.kt new file mode 100644 index 00000000000..71de4bc8127 --- /dev/null +++ b/libraries/kotlin.test/annotations-common/src/main/kotlin/kotlin.test/Annotations.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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 kotlin.test + +/** + * Marks a function as a test. + */ +public expect annotation class Test() + +/** + * Marks a test or a suite as ignored. + */ +public expect annotation class Ignore() + +/** + * Marks a function to be invoked before each test. + */ +public expect annotation class BeforeTest() + +/** + * Marks a function to be invoked after each test. + */ +public expect annotation class AfterTest() diff --git a/libraries/kotlin.test/common/build.gradle b/libraries/kotlin.test/common/build.gradle index 98a3fac2dd0..5f6150ebcce 100644 --- a/libraries/kotlin.test/common/build.gradle +++ b/libraries/kotlin.test/common/build.gradle @@ -7,6 +7,7 @@ configurePublishing(project) dependencies { compile project(':kotlin-stdlib-common') + testCompile project(":kotlin-test:kotlin-test-annotations-common") } jar { diff --git a/libraries/kotlin.test/common/src/main/kotlin/org/junit/Test.kt b/libraries/kotlin.test/common/src/main/kotlin/org/junit/Test.kt index 191bf07876d..4fca35e7894 100644 --- a/libraries/kotlin.test/common/src/main/kotlin/org/junit/Test.kt +++ b/libraries/kotlin.test/common/src/main/kotlin/org/junit/Test.kt @@ -1,4 +1,7 @@ package org.junit @Suppress("NO_ACTUAL_FOR_EXPECT") +@Deprecated("Use 'Test' from kotlin.test package", + replaceWith = ReplaceWith("kotlin.test.Test", "kotlin.test.Test"), + level = DeprecationLevel.WARNING) expect annotation class Test() diff --git a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/AnnotationsTest.kt b/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/AnnotationsTest.kt new file mode 100644 index 00000000000..60cc1ca9bb1 --- /dev/null +++ b/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/AnnotationsTest.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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 kotlin.test.tests + +import kotlin.test.* + +private var value = 5 + +class AnnotationsTest { + + @BeforeTest fun setup() { + value *= 2 + } + + @AfterTest fun teardown() { + value /= 2 + } + + @Test fun testValue() { + assertEquals(10, value) + } + + @Test fun testValueAgain() { + assertEquals(10, value) + } + + @Ignore @Test fun testValueWrong() { + assertEquals(20, value) + } + +} \ No newline at end of file diff --git a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/BasicAssertionsTest.kt b/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/BasicAssertionsTest.kt index 1199e1c2b82..c4b5b18dd5c 100644 --- a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/BasicAssertionsTest.kt +++ b/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/BasicAssertionsTest.kt @@ -1,7 +1,6 @@ package kotlin.test.tests import kotlin.test.* -import org.junit.Test class BasicAssertionsTest { @Test diff --git a/libraries/kotlin.test/js/build.gradle b/libraries/kotlin.test/js/build.gradle index 652e37356ce..b2304d89ddb 100644 --- a/libraries/kotlin.test/js/build.gradle +++ b/libraries/kotlin.test/js/build.gradle @@ -5,7 +5,8 @@ apply plugin: 'kotlin-platform-js' configurePublishing(project) dependencies { - implement project(':kotlin-test:kotlin-test-common') + expectedBy project(':kotlin-test:kotlin-test-common') + compile project(':kotlin-test:kotlin-test-annotations-common') // TODO: replace with impl-dependency compile project(':kotlin-stdlib-js') } diff --git a/libraries/kotlin.test/js/src/main/kotlin/org/junit/junitTest.kt b/libraries/kotlin.test/js/src/main/kotlin/org/junit/junitTest.kt index 3d35ecd54f4..b832bdd4aba 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/org/junit/junitTest.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/org/junit/junitTest.kt @@ -1,6 +1,6 @@ package org.junit @Deprecated("Use 'Test' from kotlin.test package", - replaceWith = ReplaceWith("Test", "kotlin.test.Test"), + replaceWith = ReplaceWith("kotlin.test.Test", "kotlin.test.Test"), level = DeprecationLevel.WARNING) actual typealias Test = kotlin.test.Test diff --git a/libraries/kotlin.test/junit/build.gradle b/libraries/kotlin.test/junit/build.gradle index 93e62127537..95a3f9b11e0 100644 --- a/libraries/kotlin.test/junit/build.gradle +++ b/libraries/kotlin.test/junit/build.gradle @@ -1,12 +1,13 @@ description = 'Kotlin Test JUnit' -apply plugin: 'kotlin' +apply plugin: 'kotlin-platform-jvm' configureJvm6Project(project) configurePublishing(project) dependencies { + expectedBy project(':kotlin-test:kotlin-test-annotations-common') compile project(':kotlin-test:kotlin-test-jvm') compile('junit:junit:4.12') } @@ -26,7 +27,7 @@ dist { } compileKotlin { - kotlinOptions.freeCompilerArgs = ["-Xallow-kotlin-package", "-module-name", project.name] + kotlinOptions.freeCompilerArgs = ["-Xallow-kotlin-package", "-Xmulti-platform", "-module-name", project.name] } compileTestKotlin { diff --git a/libraries/kotlin.test/junit/src/main/kotlin/Annotations.kt b/libraries/kotlin.test/junit/src/main/kotlin/Annotations.kt new file mode 100644 index 00000000000..ab690a3595e --- /dev/null +++ b/libraries/kotlin.test/junit/src/main/kotlin/Annotations.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + + +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("kotlin.test.annotations") +package kotlin.test + +public actual typealias Test = org.junit.Test +public actual typealias Ignore = org.junit.Ignore +public actual typealias BeforeTest = org.junit.Before +public actual typealias AfterTest = org.junit.After diff --git a/libraries/kotlin.test/jvm/build.gradle b/libraries/kotlin.test/jvm/build.gradle index 6a6f979c3a9..ca372f17431 100644 --- a/libraries/kotlin.test/jvm/build.gradle +++ b/libraries/kotlin.test/jvm/build.gradle @@ -7,8 +7,9 @@ configureJvm6Project(project) configurePublishing(project) dependencies { - implement project(':kotlin-test:kotlin-test-common') + expectedBy project(':kotlin-test:kotlin-test-common') compile project(':kotlin-stdlib') + testCompile project(":kotlin-test:kotlin-test-junit") testCompile('junit:junit:4.12') } diff --git a/libraries/kotlin.test/jvm/src/test/kotlin/BasicAssertionsJVMTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/BasicAssertionsJVMTest.kt index 765a6a59d0c..c6e6dc563e8 100644 --- a/libraries/kotlin.test/jvm/src/test/kotlin/BasicAssertionsJVMTest.kt +++ b/libraries/kotlin.test/jvm/src/test/kotlin/BasicAssertionsJVMTest.kt @@ -1,7 +1,6 @@ package kotlin.test.tests import kotlin.test.* -import org.junit.* class BasicAssertionsJVMTest { diff --git a/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt index a93c5a3d711..4ff1608a8d3 100644 --- a/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt +++ b/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt @@ -1,7 +1,7 @@ @file:Suppress("DEPRECATION") package kotlin.test.tests -import org.junit.* +import org.junit.Assert import java.util.* import kotlin.test.* diff --git a/libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt index c94be43873b..13d185b496b 100644 --- a/libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt +++ b/libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt @@ -17,7 +17,6 @@ package kotlin.test.tests import kotlin.test.* -import org.junit.Test class TestJVMTest { diff --git a/settings.gradle b/settings.gradle index b065bbd608b..ff0fb9272b1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -89,6 +89,7 @@ include ":kotlin-build-common", ":kotlin-script-runtime", ":kotlin-runtime", ":kotlin-test:kotlin-test-common", + ":kotlin-test:kotlin-test-annotations-common", ":kotlin-test:kotlin-test-jvm", ":kotlin-test:kotlin-test-junit", ":kotlin-test:kotlin-test-js", @@ -147,6 +148,7 @@ rootProject.name = "kotlin" project(':kotlin-runtime').projectDir = "$rootDir/libraries/tools/runtime" as File project(':kotlin-script-runtime').projectDir = "$rootDir/libraries/tools/script-runtime" as File project(':kotlin-test:kotlin-test-common').projectDir = "$rootDir/libraries/kotlin.test/common" as File +project(':kotlin-test:kotlin-test-annotations-common').projectDir = "$rootDir/libraries/kotlin.test/annotations-common" as File project(':kotlin-test:kotlin-test-jvm').projectDir = "$rootDir/libraries/kotlin.test/jvm" as File project(':kotlin-test:kotlin-test-junit').projectDir = "$rootDir/libraries/kotlin.test/junit" as File project(':kotlin-test:kotlin-test-js').projectDir = "$rootDir/libraries/kotlin.test/js" as File