Multiplatform test annotations

Actual annotations are provided in kotlin-test-junit on JVM side
and in kotlin-test-js on JS side.

#KT-19696
This commit is contained in:
Ilya Gorbunov
2017-10-10 09:06:02 +03:00
parent 4b1b847f0a
commit f002493218
15 changed files with 146 additions and 9 deletions
@@ -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
}
@@ -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()
@@ -7,6 +7,7 @@ configurePublishing(project)
dependencies {
compile project(':kotlin-stdlib-common')
testCompile project(":kotlin-test:kotlin-test-annotations-common")
}
jar {
@@ -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()
@@ -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)
}
}
@@ -1,7 +1,6 @@
package kotlin.test.tests
import kotlin.test.*
import org.junit.Test
class BasicAssertionsTest {
@Test
+2 -1
View File
@@ -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')
}
@@ -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
+3 -2
View File
@@ -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 {
@@ -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
+2 -1
View File
@@ -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')
}
@@ -1,7 +1,6 @@
package kotlin.test.tests
import kotlin.test.*
import org.junit.*
class BasicAssertionsJVMTest {
@@ -1,7 +1,7 @@
@file:Suppress("DEPRECATION")
package kotlin.test.tests
import org.junit.*
import org.junit.Assert
import java.util.*
import kotlin.test.*
@@ -17,7 +17,6 @@
package kotlin.test.tests
import kotlin.test.*
import org.junit.Test
class TestJVMTest {
+2
View File
@@ -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