kotlin-test: extract from JS library, convert to multiplatform
This commit is contained in:
@@ -11,78 +11,84 @@
|
||||
|
||||
<artifactId>kotlin-test-js</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-js-library</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>2.10</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>unpack-dependencies</goal>
|
||||
</goals>
|
||||
<phase>generate-test-resources</phase>
|
||||
<configuration>
|
||||
<includeScope>test</includeScope>
|
||||
<includeTypes>jar</includeTypes>
|
||||
<outputDirectory>${project.basedir}/target/test-js</outputDirectory>
|
||||
<includes>*.js</includes>
|
||||
<excludes>*.meta.js</excludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.github.eirslett</groupId>
|
||||
<artifactId>frontend-maven-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>install node and npm</id>
|
||||
<!--<phase>generate-test-resources</phase>-->
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>install-node-and-npm</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>npm install</id>
|
||||
<!--<phase>generate-test-resources</phase>-->
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>npm</goal>
|
||||
</goals>
|
||||
<!-- Optional configuration which provides for running any npm command -->
|
||||
<configuration>
|
||||
<arguments>install</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>javascript tests</id>
|
||||
<goals>
|
||||
<goal>karma</goal>
|
||||
</goals>
|
||||
<!-- disable js tests -->
|
||||
<phase>none</phase>
|
||||
<configuration>
|
||||
<karmaConfPath>${project.basedir}/src/test/karma/karma.conf.js</karmaConfPath>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
|
||||
<configuration>
|
||||
<nodeVersion>v0.12.7</nodeVersion>
|
||||
<npmVersion>2.14.4</npmVersion>
|
||||
<args>
|
||||
<!--<arg>-Xallow-kotlin-package</arg>-->
|
||||
<arg>-Xmulti-platform</arg>
|
||||
</args>
|
||||
<moduleKind>umd</moduleKind>
|
||||
<kjsm>true</kjsm>
|
||||
<metaInfo>true</metaInfo>
|
||||
</configuration>
|
||||
|
||||
<workingDirectory>${project.basedir}/src/test/karma</workingDirectory>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>js</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
|
||||
<!--<execution>-->
|
||||
<!--<id>test-compile</id>-->
|
||||
<!--<phase>test-compile</phase>-->
|
||||
<!--<goals>-->
|
||||
<!--<goal>test-compile</goal>-->
|
||||
<!--</goals>-->
|
||||
<!--<configuration>-->
|
||||
<!--<sourceDirs>-->
|
||||
<!--<dir>${project.basedir}/src/test/kotlin</dir>-->
|
||||
<!--<dir>${project.basedir}/src/test/kotlin.jvm</dir>-->
|
||||
<!--</sourceDirs>-->
|
||||
<!--</configuration>-->
|
||||
<!--</execution>-->
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<configuration>
|
||||
<forceCreation>true</forceCreation>
|
||||
<classesDirectory>${project.build.directory}/js</classesDirectory>
|
||||
<includes>
|
||||
<include>**/*.js</include>
|
||||
<include>**/*.js.map</include>
|
||||
<include>**/*.kjsm</include>
|
||||
<include>**/*.kotlin_classes</include>
|
||||
<include>**/*.kotlin_string_table</include>
|
||||
<include>**/*.kotlin_file_table</include>
|
||||
</includes>
|
||||
<archive>
|
||||
<forced />
|
||||
<manifestEntries>
|
||||
<Built-By>${user.name}</Built-By>
|
||||
|
||||
<Implementation-Vendor>JetBrains s.r.o.</Implementation-Vendor>
|
||||
<Implementation-Version>${project.version}</Implementation-Version>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package kotlin.test
|
||||
|
||||
impl fun AssertionError(message: String): Throwable = kotlin.AssertionError(message)
|
||||
impl fun AssertionError(): Throwable = kotlin.AssertionError()
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
fun todo(block: () -> Any) {
|
||||
// println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
|
||||
println("TODO at " + block)
|
||||
}
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
inline fun <reified T : Throwable> assertFailsWith(message: String? = null, noinline block: () -> Unit): T {
|
||||
val exception = assertFails(message, block)
|
||||
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/)
|
||||
*/
|
||||
internal impl fun lookupAsserter(): Asserter = _asserter
|
||||
|
||||
class QUnitAsserter : Asserter {
|
||||
|
||||
override fun assertTrue(lazyMessage: () -> String?, actual: Boolean) {
|
||||
assertTrue(actual, lazyMessage())
|
||||
}
|
||||
|
||||
override fun assertTrue(message: String?, actual: Boolean) {
|
||||
QUnit.ok(actual, message)
|
||||
if (!actual) failWithMessage(message)
|
||||
}
|
||||
|
||||
override fun fail(message: String?): Nothing {
|
||||
QUnit.ok(false, message)
|
||||
failWithMessage(message)
|
||||
}
|
||||
|
||||
private fun failWithMessage(message: String?): Nothing {
|
||||
if (message == null)
|
||||
throw AssertionError()
|
||||
else
|
||||
throw AssertionError(message)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package QUnit
|
||||
|
||||
/**
|
||||
* The [QUnit](http://qunitjs.com/) API
|
||||
*/
|
||||
|
||||
external fun ok(actual: Boolean, message: String?): Unit = noImpl
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
package org.junit
|
||||
|
||||
@Suppress("IMPLEMENTATION_WITHOUT_HEADER")
|
||||
impl annotation class Test(val name: String = "")
|
||||
Reference in New Issue
Block a user