diff --git a/build.xml b/build.xml index 345763d722a..9dbce5c6d0c 100644 --- a/build.xml +++ b/build.xml @@ -488,7 +488,7 @@ - + @@ -1061,18 +1061,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1080,6 +1096,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java index a3ee57bf325..c3f96002aa4 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java @@ -48,6 +48,9 @@ public interface KotlinPaths { @NotNull File getJsStdLibSrcJarPath(); + @NotNull + File getJsKotlinTestJarPath(); + @NotNull File getAllOpenPluginJarPath(); diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java index 7159b40f4ab..3730b57c3d6 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java @@ -82,6 +82,12 @@ public class KotlinPathsFromHomeDir implements KotlinPaths { return getLibraryFile(PathUtil.JS_LIB_SRC_JAR_NAME); } + @NotNull + @Override + public File getJsKotlinTestJarPath() { + return getLibraryFile(PathUtil.KOTLIN_TEST_JS_JAR); + } + @NotNull @Override public File getAllOpenPluginJarPath() { diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java index 7cba9fc3239..cf04dc523f7 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java +++ b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java @@ -36,6 +36,7 @@ public class PathUtil { public static final String KOTLIN_JAVA_REFLECT_JAR = "kotlin-reflect.jar"; public static final String KOTLIN_JAVA_SCRIPT_RUNTIME_JAR = "kotlin-script-runtime.jar"; public static final String KOTLIN_TEST_JAR = "kotlin-test.jar"; + public static final String KOTLIN_TEST_JS_JAR = "kotlin-test-js.jar"; public static final String KOTLIN_JAVA_RUNTIME_SRC_JAR = "kotlin-runtime-sources.jar"; public static final String KOTLIN_COMPILER_JAR = "kotlin-compiler.jar"; diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/config/LibrarySourcesConfig.java b/js/js.frontend/src/org/jetbrains/kotlin/js/config/LibrarySourcesConfig.java index 9604a7c67a7..5ac64f0bb86 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/config/LibrarySourcesConfig.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/config/LibrarySourcesConfig.java @@ -47,6 +47,9 @@ public class LibrarySourcesConfig extends JsConfig { public static final List JS_STDLIB = Collections.singletonList(getKotlinPathsForDistDirectory().getJsStdLibJarPath().getAbsolutePath()); + public static final List JS_KOTLIN_TEST = + Collections.singletonList(getKotlinPathsForDistDirectory().getJsKotlinTestJarPath().getAbsolutePath()); + public static final Key EXTERNAL_MODULE_NAME = Key.create("externalModule"); public static final String UNKNOWN_EXTERNAL_MODULE_NAME = ""; diff --git a/js/js.libraries/src/deprecated/junit/core.kt b/js/js.libraries/src/deprecated/junit/core.kt deleted file mode 100644 index ddd5e70d85d..00000000000 --- a/js/js.libraries/src/deprecated/junit/core.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.junit - -public annotation class Test(val name: String = "") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt index 9aa490e5d74..9636902a373 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt @@ -256,7 +256,7 @@ abstract class BasicBoxTest( configuration.put(CommonConfigurationKeys.DISABLE_INLINE, module.inliningDisabled) - configuration.put(JSConfigurationKeys.LIBRARY_FILES, LibrarySourcesConfig.JS_STDLIB + dependencies) + configuration.put(JSConfigurationKeys.LIBRARY_FILES, LibrarySourcesConfig.JS_STDLIB + LibrarySourcesConfig.JS_KOTLIN_TEST + dependencies) configuration.put(CommonConfigurationKeys.MODULE_NAME, module.name.removeSuffix(OLD_MODULE_SUFFIX)) configuration.put(JSConfigurationKeys.MODULE_KIND, module.moduleKind) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java index 64223fb6bd8..167571114cd 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java @@ -65,6 +65,7 @@ import java.util.Map; import static org.jetbrains.kotlin.js.test.rhino.RhinoUtils.runRhinoTest; import static org.jetbrains.kotlin.js.test.utils.JsTestUtils.convertFileNameToDotJsFile; import static org.jetbrains.kotlin.test.InTextDirectivesUtils.isDirectiveDefined; +import static org.jetbrains.kotlin.utils.PathUtil.getKotlinPathsForDistDirectory; public abstract class BasicTest extends KotlinTestWithEnvironment { // predictable order of ecma version in tests @@ -319,6 +320,8 @@ public abstract class BasicTest extends KotlinTestWithEnvironment { if (libraries != null) { librariesWithStdlib.addAll(libraries); } + librariesWithStdlib.add(getKotlinPathsForDistDirectory().getJsKotlinTestJarPath().getAbsolutePath()); + configuration.put(JSConfigurationKeys.LIBRARY_FILES, librariesWithStdlib); configuration.put(CommonConfigurationKeys.MODULE_NAME, moduleName); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/rhino/RhinoUtils.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/rhino/RhinoUtils.java index 0fc9da724e0..2c26e364629 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/rhino/RhinoUtils.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/rhino/RhinoUtils.java @@ -153,6 +153,8 @@ public final class RhinoUtils { // System.out.print(problems); //} } + + finishScope(scope); checker.runChecks(context, scope); } finally { @@ -162,7 +164,16 @@ public final class RhinoUtils { @NotNull private static Scriptable getScope(@NotNull EcmaVersion version, @NotNull Context context, @NotNull List jsLibraries) { - return context.newObject(getParentScope(version, context, jsLibraries)); + Scriptable parentScope = getParentScope(version, context, jsLibraries); + Scriptable scope = context.newObject(parentScope); + + scope.put("kotlin-test", scope, parentScope.get("kotlin-test", parentScope)); + + return scope; + } + + private static void finishScope(@NotNull Scriptable scope) { + scope.delete("kotlin-test"); } @NotNull @@ -180,6 +191,8 @@ public final class RhinoUtils { ScriptableObject scope = context.initStandardObjects(); try { runFileWithRhino(DIST_DIR_JS_PATH + "kotlin.js", context, scope); + runFileWithRhino(DIST_DIR_JS_PATH + "../classes/kotlin-test-js/kotlin-test.js", context, scope); + //runFileWithRhino(pathToTestFilesRoot() + "jshint.js", context, scope); for (String jsLibrary : jsLibraries) { runFileWithRhino(jsLibrary, context, scope); diff --git a/js/js.translator/testData/jsTester/jsTester.kt b/js/js.translator/testData/jsTester/jsTester.kt index 0339cd64b0d..d229e01018b 100644 --- a/js/js.translator/testData/jsTester/jsTester.kt +++ b/js/js.translator/testData/jsTester/jsTester.kt @@ -1,7 +1,7 @@ package kotlin.test val init = run { - asserter = JsTestsAsserter() + _asserter = JsTestsAsserter() } public class JsTestsAsserter() : Asserter { diff --git a/libraries/kotlin.test/js/pom.xml b/libraries/kotlin.test/js/pom.xml index b3f463fd8a4..6cb5a379cd0 100644 --- a/libraries/kotlin.test/js/pom.xml +++ b/libraries/kotlin.test/js/pom.xml @@ -11,78 +11,84 @@ kotlin-test-js + + + org.jetbrains.kotlin + kotlin-js-library + + + org.jetbrains.kotlin + kotlin-test-common + ${project.version} + + + src/main/kotlin - src/test/kotlin - maven-dependency-plugin - 2.10 - - - - unpack-dependencies - - generate-test-resources - - test - jar - ${project.basedir}/target/test-js - *.js - *.meta.js - - - - - - - com.github.eirslett - frontend-maven-plugin - - - - install node and npm - - none - - install-node-and-npm - - - - - - - npm install - - none - - npm - - - - install - - - - - javascript tests - - karma - - - none - - ${project.basedir}/src/test/karma/karma.conf.js - - - + org.jetbrains.kotlin + kotlin-maven-plugin - v0.12.7 - 2.14.4 + + + -Xmulti-platform + + umd + true + true + - ${project.basedir}/src/test/karma + + + compile + compile + + js + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.6 + + true + ${project.build.directory}/js + + **/*.js + **/*.js.map + **/*.kjsm + **/*.kotlin_classes + **/*.kotlin_string_table + **/*.kotlin_file_table + + + + + ${user.name} + + JetBrains s.r.o. + ${project.version} + + diff --git a/libraries/kotlin.test/js/src/main/kotlin/AssertionError.kt b/libraries/kotlin.test/js/src/main/kotlin/AssertionError.kt new file mode 100644 index 00000000000..a46535636b0 --- /dev/null +++ b/libraries/kotlin.test/js/src/main/kotlin/AssertionError.kt @@ -0,0 +1,4 @@ +package kotlin.test + +impl fun AssertionError(message: String): Throwable = kotlin.AssertionError(message) +impl fun AssertionError(): Throwable = kotlin.AssertionError() diff --git a/js/js.libraries/src/kotlin.test/testCode.kt b/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt similarity index 77% rename from js/js.libraries/src/kotlin.test/testCode.kt rename to libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt index 8c7fa5ece60..a89e0403d91 100644 --- a/js/js.libraries/src/kotlin.test/testCode.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt @@ -20,7 +20,7 @@ package kotlin.test * Comments out a block of test code until it is implemented while keeping a link to the code * to implement in your unit test output */ -public fun todo(block: () -> Any) { +fun todo(block: () -> Any) { // println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block) println("TODO at " + block) } @@ -28,30 +28,33 @@ public fun todo(block: () -> Any) { /** Asserts that a [block] fails with a specific exception of type [T] being thrown. * Since inline method doesn't allow to trace where it was invoked, it is required to pass a [message] to distinguish this method call from others. */ -@kotlin.internal.InlineOnly inline fun assertFailsWith(message: String? = null, noinline block: () -> Unit): T { val exception = assertFails(message, block) - assertTrue(exception is T, (message?.let { "$it. " } ?: "") + "An exception thrown is not of the expected type: $exception") + val messagePrefix = if (message == null) "" else "$message. " + + assertTrue(exception is T, "${messagePrefix}An exception thrown is not of the expected type: $exception") return exception as T } +var _asserter: Asserter = QUnitAsserter() + /** * Provides the JS implementation of asserter using [QUnit](http://QUnitjs.com/) */ -public var asserter: Asserter = QUnitAsserter() +internal impl fun lookupAsserter(): Asserter = _asserter -public class QUnitAsserter() : Asserter { +class QUnitAsserter : Asserter { - public override fun assertTrue(lazyMessage: () -> String?, actual: Boolean) { + override fun assertTrue(lazyMessage: () -> String?, actual: Boolean) { assertTrue(actual, lazyMessage()) } - public override fun assertTrue(message: String?, actual: Boolean) { + override fun assertTrue(message: String?, actual: Boolean) { QUnit.ok(actual, message) if (!actual) failWithMessage(message) } - public override fun fail(message: String?): Nothing { + override fun fail(message: String?): Nothing { QUnit.ok(false, message) failWithMessage(message) } @@ -62,4 +65,4 @@ public class QUnitAsserter() : Asserter { else throw AssertionError(message) } -} \ No newline at end of file +} diff --git a/libraries/kotlin.test/js/src/main/kotlin/QUnit.kt b/libraries/kotlin.test/js/src/main/kotlin/QUnit.kt new file mode 100644 index 00000000000..56b5978e806 --- /dev/null +++ b/libraries/kotlin.test/js/src/main/kotlin/QUnit.kt @@ -0,0 +1,8 @@ +package QUnit + +/** + * The [QUnit](http://qunitjs.com/) API + */ + +external fun ok(actual: Boolean, message: String?): Unit = noImpl + diff --git a/libraries/kotlin.test/js/src/main/kotlin/annotations.kt b/libraries/kotlin.test/js/src/main/kotlin/annotations.kt new file mode 100644 index 00000000000..e805b24f360 --- /dev/null +++ b/libraries/kotlin.test/js/src/main/kotlin/annotations.kt @@ -0,0 +1,16 @@ +package kotlin.internal + + +/** + * The value of this type parameter should be mentioned in input types (argument types, receiver type or expected type). +// */ +//@Target(AnnotationTarget.TYPE_PARAMETER) +//@Retention(AnnotationRetention.BINARY) +//internal impl annotation class OnlyInputTypes + +/** + * Specifies that this function should not be called directly without inlining + */ +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.BINARY) +internal impl annotation class InlineOnly \ No newline at end of file diff --git a/libraries/kotlin.test/js/src/main/kotlin/junitTest.kt b/libraries/kotlin.test/js/src/main/kotlin/junitTest.kt new file mode 100644 index 00000000000..952dc742f5a --- /dev/null +++ b/libraries/kotlin.test/js/src/main/kotlin/junitTest.kt @@ -0,0 +1,4 @@ +package org.junit + +@Suppress("IMPLEMENTATION_WITHOUT_HEADER") +impl annotation class Test(val name: String = "") diff --git a/libraries/kotlin.test/junit/pom.xml b/libraries/kotlin.test/junit/pom.xml index bb26cfc6213..d85eb69d88b 100644 --- a/libraries/kotlin.test/junit/pom.xml +++ b/libraries/kotlin.test/junit/pom.xml @@ -18,15 +18,9 @@ org.jetbrains.kotlin + kotlin-test ${project.version} - - - - org.jetbrains.kotlin - kotlin-js-library - - @@ -86,12 +80,6 @@ compile - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/main/kotlin.jvm - - @@ -100,12 +88,6 @@ test-compile - - - ${project.basedir}/src/test/kotlin - ${project.basedir}/src/test/kotlin.jvm - - diff --git a/libraries/kotlin.test/jvm/pom.xml b/libraries/kotlin.test/jvm/pom.xml new file mode 100644 index 00000000000..78ed970441b --- /dev/null +++ b/libraries/kotlin.test/jvm/pom.xml @@ -0,0 +1,67 @@ + + + + kotlin-test-parent + org.jetbrains.kotlin + 1.1-SNAPSHOT + + 4.0.0 + + kotlin-test + + + + org.jetbrains.kotlin + kotlin-runtime + + + org.jetbrains.kotlin + kotlin-test-common + ${project.version} + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + -Xallow-kotlin-package + -Xmulti-platform + + + + + + compile + compile + + compile + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/AsserterLookup.kt b/libraries/kotlin.test/jvm/src/main/kotlin/AsserterLookup.kt similarity index 95% rename from libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/AsserterLookup.kt rename to libraries/kotlin.test/jvm/src/main/kotlin/AsserterLookup.kt index 1ca12800b69..0c270b5fd29 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/AsserterLookup.kt +++ b/libraries/kotlin.test/jvm/src/main/kotlin/AsserterLookup.kt @@ -8,6 +8,8 @@ private val inited = AtomicBoolean() private val lock = ReentrantLock() private val contributors = ArrayList() +internal impl fun lookupAsserter(): Asserter = lookup() + internal fun lookup(): Asserter { initContributorsIfNeeded() diff --git a/libraries/kotlin.test/jvm/src/main/kotlin/AssertionError.kt b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionError.kt new file mode 100644 index 00000000000..cfe76d065c9 --- /dev/null +++ b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionError.kt @@ -0,0 +1,21 @@ +/* + * 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 + +impl fun AssertionError(message: String): Throwable = java.lang.AssertionError(message) +impl fun AssertionError(): Throwable = java.lang.AssertionError() + diff --git a/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt similarity index 71% rename from libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt rename to libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt index ff146cbba9b..5aa45cad915 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt +++ b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt @@ -1,7 +1,24 @@ +/* + * 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:kotlin.jvm.JvmMultifileClass @file:kotlin.jvm.JvmName("AssertionsKt") package kotlin.test +import kotlin.internal.* import kotlin.reflect.* /** Asserts that a [block] fails with a specific exception being thrown. */ @@ -13,9 +30,13 @@ private fun assertFailsWithImpl(exceptionClass: Class, messag @Suppress("UNCHECKED_CAST") return e as T } - asserter.fail((message?.let { "$it. " } ?: "") + "Expected an exception of type $exceptionClass to be thrown, but was $e") + + @Suppress("INVISIBLE_MEMBER") + asserter.fail(messagePrefix(message) + "Expected an exception of type $exceptionClass to be thrown, but was $e") } - val msg = message?.let { "$it. " } ?: "" + + @Suppress("INVISIBLE_MEMBER") + val msg = messagePrefix(message) asserter.fail(msg + "Expected an exception of type $exceptionClass to be thrown, but was completed successfully.") } @@ -28,7 +49,7 @@ fun assertFailsWith(exceptionClass: KClass, message: String?, /** Asserts that a [block] fails with a specific exception of type [T] being thrown. * Since inline method doesn't allow to trace where it was invoked, it is required to pass a [message] to distinguish this method call from others. */ -@kotlin.internal.InlineOnly +@InlineOnly inline fun assertFailsWith(message: String? = null, noinline block: () -> Unit): T = assertFailsWith(T::class, message, block) @@ -36,7 +57,7 @@ inline fun assertFailsWith(message: String? = null, noin * Comments out a [block] of test code until it is implemented while keeping a link to the code * to implement in your unit test output */ -@kotlin.internal.InlineOnly +@InlineOnly inline fun todo(@Suppress("UNUSED_PARAMETER") block: () -> Unit) { System.out.println("TODO at " + currentStackTrace()[0]) } @@ -47,13 +68,6 @@ inline fun todo(@Suppress("UNUSED_PARAMETER") block: () -> Unit) { * stack, which is the place where [currentStackTrace] function was called from. */ @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") -@kotlin.internal.InlineOnly +@InlineOnly inline fun currentStackTrace() = (java.lang.Exception() as java.lang.Throwable).stackTrace -/** - * The active implementation of [Asserter]. An implementation of [Asserter] can be provided - * using the [Java service loader](http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html) mechanism. - */ -val asserter: Asserter - get() = lookup() - diff --git a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/CollectionAssertions.kt b/libraries/kotlin.test/jvm/src/main/kotlin/CollectionAssertions.kt similarity index 89% rename from libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/CollectionAssertions.kt rename to libraries/kotlin.test/jvm/src/main/kotlin/CollectionAssertions.kt index c43d75aec4d..3357f773a30 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/CollectionAssertions.kt +++ b/libraries/kotlin.test/jvm/src/main/kotlin/CollectionAssertions.kt @@ -1,5 +1,20 @@ -@file:Suppress("DEPRECATION") +/* + * 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("DEPRECATION") package kotlin.test import java.util.* diff --git a/libraries/kotlin.test/jvm/src/main/kotlin/annotations.kt b/libraries/kotlin.test/jvm/src/main/kotlin/annotations.kt new file mode 100644 index 00000000000..76a295c89bc --- /dev/null +++ b/libraries/kotlin.test/jvm/src/main/kotlin/annotations.kt @@ -0,0 +1,16 @@ +package kotlin.internal + + +/** + * The value of this type parameter should be mentioned in input types (argument types, receiver type or expected type). + */ +@Target(AnnotationTarget.TYPE_PARAMETER) +@Retention(AnnotationRetention.BINARY) +internal annotation class OnlyInputTypes + +/** + * Specifies that this function should not be called directly without inlining + */ +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.BINARY) +internal annotation class InlineOnly \ No newline at end of file diff --git a/libraries/kotlin.test/pom.xml b/libraries/kotlin.test/pom.xml index 516fc7111dd..572252688ab 100644 --- a/libraries/kotlin.test/pom.xml +++ b/libraries/kotlin.test/pom.xml @@ -14,7 +14,8 @@ shared junit - + jvm + js diff --git a/libraries/kotlin.test/shared/pom.xml b/libraries/kotlin.test/shared/pom.xml index fdbc20f0071..3a0bc809136 100644 --- a/libraries/kotlin.test/shared/pom.xml +++ b/libraries/kotlin.test/shared/pom.xml @@ -7,13 +7,42 @@ 4.0.0 - kotlin-test + kotlin-test-common + + + + + + + + src/main/kotlin src/test/kotlin + + org.jetbrains.kotlin + kotlin-maven-plugin + ${project.version} + + + + -Xallow-kotlin-package + + + + + + compile + + metadata + + + + + maven-assembly-plugin @@ -30,147 +59,88 @@ + + + maven-jar-plugin + + + kotlin/internal/OnlyInputTypes* + kotlin/internal/InlineOnly* + kotlin/internal + + + + true + + + + - - kotlin-js - - false - + + + + + - - - org.jetbrains.kotlin - kotlin-js-library - - - + + + + + + + + + + + - - - - org.jetbrains.kotlin - kotlin-maven-plugin + + + + + - - - -Xallow-kotlin-package - - + + + + + - - - test-compile-js - test-compile - - test-js - - - - ${project.basedir}/src/test/kotlin - ${project.basedir}/src/test/kotlin.js - - - + + + + + + + + + + + + + + - - js-compile - compile - - js - - - ${project.build.outputDirectory}/${project.artifactId}.js - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/main/kotlin.js - - - - - - - - - - kotlin-jvm - - true - - - - - org.jetbrains.kotlin - kotlin-runtime - - - junit - junit - test - - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - - - - -Xallow-kotlin-package - - - - - - compile - compile - - compile - - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/main/kotlin.jvm - - - - - - test-compile - test-compile - - test-compile - - - - ${project.basedir}/src/test/kotlin - ${project.basedir}/src/test/kotlin.jvm - - - - - - - maven-jar-plugin - - - kotlin/internal/OnlyInputTypes* - kotlin/internal/InlineOnly* - kotlin/internal - - - - true - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/libraries/kotlin.test/shared/src/main/kotlin.js/kotlin/jvm/annotations.kt b/libraries/kotlin.test/shared/src/main/kotlin.js/kotlin/jvm/annotations.kt deleted file mode 100644 index c9c23e59564..00000000000 --- a/libraries/kotlin.test/shared/src/main/kotlin.js/kotlin/jvm/annotations.kt +++ /dev/null @@ -1,25 +0,0 @@ -package kotlin.jvm - - -/** - * Specifies the name for the Java class or method - * which is generated from this element. - * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/java-interop.html#handling-signature-clashes-with-platformname) - * for more information. - * @property name the name of the element. - */ -@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FILE) -@Retention(AnnotationRetention.BINARY) -@MustBeDocumented -internal annotation class JvmName(public val name: String) - -/** - * Instructs the Kotlin compiler to generate a multifile class with top-level functions and properties declared in this file as one of its parts. - * Name of the corresponding multifile class is provided by the [JvmName] annotation. - */ -@Target(AnnotationTarget.FILE) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -internal annotation class JvmMultifileClass - - diff --git a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/internal/internalAnnotations.kt b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/internal/internalAnnotations.kt index 76a295c89bc..9bad03bf83c 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/internal/internalAnnotations.kt +++ b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/internal/internalAnnotations.kt @@ -4,13 +4,15 @@ package kotlin.internal /** * The value of this type parameter should be mentioned in input types (argument types, receiver type or expected type). */ +@Suppress("HEADER_WITHOUT_IMPLEMENTATION") @Target(AnnotationTarget.TYPE_PARAMETER) @Retention(AnnotationRetention.BINARY) -internal annotation class OnlyInputTypes +internal header annotation class OnlyInputTypes /** * Specifies that this function should not be called directly without inlining */ +@Suppress("HEADER_WITHOUT_IMPLEMENTATION") @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.BINARY) -internal annotation class InlineOnly \ No newline at end of file +internal header annotation class InlineOnly diff --git a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/jvm/internalAnnotations.kt b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/jvm/internalAnnotations.kt new file mode 100644 index 00000000000..05526240fef --- /dev/null +++ b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/jvm/internalAnnotations.kt @@ -0,0 +1,9 @@ +package kotlin.jvm + +@Suppress("HEADER_WITHOUT_IMPLEMENTATION") +@Target(AnnotationTarget.FILE) +internal header annotation class JvmMultifileClass + +@Suppress("HEADER_WITHOUT_IMPLEMENTATION") +@Target(AnnotationTarget.FILE) +internal header annotation class JvmName(val name: String) diff --git a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/TestAssertions.kt b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/Assertions.kt similarity index 90% rename from libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/TestAssertions.kt rename to libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/Assertions.kt index 56aa678f42b..28a2d1d592c 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/TestAssertions.kt +++ b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/Assertions.kt @@ -14,16 +14,20 @@ * limitations under the License. */ -@file:kotlin.jvm.JvmMultifileClass -@file:kotlin.jvm.JvmName("AssertionsKt") - /** * A number of helper methods for writing unit tests. */ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("AssertionsKt") +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + package kotlin.test import kotlin.internal.* +val asserter: Asserter + get() = lookupAsserter() + /** Asserts that the given [block] returns `true`. */ fun assertTrue(message: String? = null, block: () -> Boolean): Unit = assertTrue(block(), message) @@ -95,8 +99,7 @@ fun assertFails(message: String?, block: () -> Unit): Throwable { } catch (e: Throwable) { return e } - val msg = message?.let { "$it. " } ?: "" - asserter.fail(msg + "Expected an exception to be thrown, but was completed successfully.") + asserter.fail(messagePrefix(message) + "Expected an exception to be thrown, but was completed successfully.") } /** @@ -137,7 +140,7 @@ interface Asserter { * @param message the message to report if the assertion fails. */ fun assertEquals(message: String?, expected: Any?, actual: Any?): Unit { - assertTrue({ (message?.let { "$it. " } ?: "") + "Expected <$expected>, actual <$actual>." }, actual == expected) + assertTrue({ messagePrefix(message) + "Expected <$expected>, actual <$actual>." }, actual == expected) } /** @@ -146,7 +149,7 @@ interface Asserter { * @param message the message to report if the assertion fails. */ fun assertNotEquals(message: String?, illegal: Any?, actual: Any?): Unit { - assertTrue({ (message?.let { "$it. " } ?: "") + "Illegal value: <$actual>." }, actual != illegal) + assertTrue({ messagePrefix(message) + "Illegal value: <$actual>." }, actual != illegal) } /** @@ -155,7 +158,7 @@ interface Asserter { * @param message the message to report if the assertion fails. */ fun assertNull(message: String?, actual: Any?): Unit { - assertTrue({ (message?.let { "$it. " } ?: "") + "Expected value to be null, but was: <$actual>." }, actual == null) + assertTrue({ messagePrefix(message) + "Expected value to be null, but was: <$actual>." }, actual == null) } /** @@ -164,7 +167,7 @@ interface Asserter { * @param message the message to report if the assertion fails. */ fun assertNotNull(message: String?, actual: Any?): Unit { - assertTrue({ (message?.let { "$it. " } ?: "") + "Expected value to be not null." }, actual != null) + assertTrue({ messagePrefix(message) + "Expected value to be not null." }, actual != null) } } diff --git a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/DefaultAsserter.kt b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/DefaultAsserter.kt index b5cedf80a61..a72c8d9d365 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/DefaultAsserter.kt +++ b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/DefaultAsserter.kt @@ -11,4 +11,7 @@ class DefaultAsserter() : Asserter { else throw AssertionError(message) } -} \ No newline at end of file +} + +header fun AssertionError(message: String): Throwable +header fun AssertionError(): Throwable diff --git a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/Utils.kt b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/Utils.kt index fa69c62357d..d64a45c3fe8 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/Utils.kt +++ b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/Utils.kt @@ -1,4 +1,4 @@ package kotlin.test -internal fun T.let(block: (T) -> R): R = block(this) - +internal fun messagePrefix(message: String?) = if (message == null) "" else "$message. " +internal header fun lookupAsserter(): Asserter \ No newline at end of file diff --git a/libraries/kotlin.test/shared/src/main/kotlin/org/junit/Test.kt b/libraries/kotlin.test/shared/src/main/kotlin/org/junit/Test.kt new file mode 100644 index 00000000000..c50c989809c --- /dev/null +++ b/libraries/kotlin.test/shared/src/main/kotlin/org/junit/Test.kt @@ -0,0 +1,4 @@ +package org.junit + +@Suppress("HEADER_WITHOUT_IMPLEMENTATION") +header annotation class Test diff --git a/libraries/tools/kotlin-js-tests/pom.xml b/libraries/tools/kotlin-js-tests/pom.xml index 538793000ba..cbb41f3ca26 100644 --- a/libraries/tools/kotlin-js-tests/pom.xml +++ b/libraries/tools/kotlin-js-tests/pom.xml @@ -21,6 +21,11 @@ kotlin-js-library ${project.version} + + org.jetbrains.kotlin + kotlin-test-js + ${project.version} + @@ -109,6 +114,13 @@ ${project.build.directory}/js/lib *.js + + org.jetbrains.kotlin + kotlin-test-js + ${project.version} + ${project.build.directory}/js/lib + *.js + diff --git a/libraries/tools/kotlin-js-tests/src/test/web/index.html b/libraries/tools/kotlin-js-tests/src/test/web/index.html index 0cb07490af4..72bf49d1554 100644 --- a/libraries/tools/kotlin-js-tests/src/test/web/index.html +++ b/libraries/tools/kotlin-js-tests/src/test/web/index.html @@ -8,6 +8,7 @@ +