Run kotlin-test-js tests with kotlin-stdlib-js
Rework kotlin-test common tests to make them runnable with qunit. Change the way how asserter is overridden in js box tests. Minor: remove unneeded test configs
This commit is contained in:
@@ -189,9 +189,8 @@ public final class RhinoUtils {
|
|||||||
runFileWithRhino(DIST_DIR_JS_PATH + "../../js/js.translator/testData/rhino-polyfills.js", context, scope);
|
runFileWithRhino(DIST_DIR_JS_PATH + "../../js/js.translator/testData/rhino-polyfills.js", context, scope);
|
||||||
runFileWithRhino(DIST_DIR_JS_PATH + "kotlin.js", context, scope);
|
runFileWithRhino(DIST_DIR_JS_PATH + "kotlin.js", context, scope);
|
||||||
runFileWithRhino(DIST_DIR_JS_PATH + "kotlin-test.js", context, scope);
|
runFileWithRhino(DIST_DIR_JS_PATH + "kotlin-test.js", context, scope);
|
||||||
|
|
||||||
context.evaluateString(scope,
|
context.evaluateString(scope,
|
||||||
"this['kotlin-test'].kotlin.test._asserter = new this['kotlin-test'].kotlin.test.DefaultAsserter();",
|
"this['kotlin-test'].kotlin.test.overrideAsserter_wbnzx$(new this['kotlin-test'].kotlin.test.DefaultAsserter());",
|
||||||
"change asserter to DefaultAsserter", 1, null);
|
"change asserter to DefaultAsserter", 1, null);
|
||||||
|
|
||||||
//runFileWithRhino(pathToTestFilesRoot() + "jshint.js", context, scope);
|
//runFileWithRhino(pathToTestFilesRoot() + "jshint.js", context, scope);
|
||||||
|
|||||||
Vendored
+3
-30
@@ -20,7 +20,7 @@ var kotlinJsTestLocation = process.env.KOTLIN_JS_TEST_LOCATION || __dirname + "/
|
|||||||
|
|
||||||
var kotlin = require("kotlin");
|
var kotlin = require("kotlin");
|
||||||
var kotlinTest = require(kotlinJsTestLocation);
|
var kotlinTest = require(kotlinJsTestLocation);
|
||||||
supplyAsserter(kotlin, kotlinTest);
|
supplyAsserter(kotlinTest);
|
||||||
var requireFromString = require('require-from-string');
|
var requireFromString = require('require-from-string');
|
||||||
|
|
||||||
var baseDir = "out";
|
var baseDir = "out";
|
||||||
@@ -102,33 +102,6 @@ function runTest(testRunner, location) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function supplyAsserter(kotlin, kotlinTest) {
|
function supplyAsserter(kotlinTest) {
|
||||||
function AsserterClass() {
|
kotlinTest.kotlin.test.overrideAsserter_wbnzx$(new kotlinTest.kotlin.test.DefaultAsserter());
|
||||||
}
|
|
||||||
AsserterClass.prototype.assertTrue_o10pc4$ = function(lazyMessage, actual) {
|
|
||||||
kotlinTest.kotlin.test.assertTrue_ifx8ge$(actual, lazyMessage());
|
|
||||||
};
|
|
||||||
AsserterClass.prototype.assertTrue_4mavae$ = function(message, actual) {
|
|
||||||
if (!actual) {
|
|
||||||
this.failWithMessage(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
AsserterClass.prototype.assertNotNull_67rc9h$ = kotlinTest.kotlin.test.Asserter.prototype.assertNotNull_67rc9h$;
|
|
||||||
AsserterClass.prototype.assertEquals_lzc6tz$ = kotlinTest.kotlin.test.Asserter.prototype.assertEquals_lzc6tz$;
|
|
||||||
AsserterClass.prototype.fail_pdl1vj$ = function(message) {
|
|
||||||
this.failWithMessage(message);
|
|
||||||
};
|
|
||||||
AsserterClass.prototype.failWithMessage = function(message) {
|
|
||||||
if (message == null) {
|
|
||||||
throw new Kotlin.AssertionError();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Kotlin.AssertionError(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
AsserterClass.$metadata$ = {
|
|
||||||
type: kotlin.Kind.CLASS,
|
|
||||||
baseClasses: [kotlinTest.kotlin.test.Asserter]
|
|
||||||
};
|
|
||||||
kotlinTest.kotlin.test._asserter = new AsserterClass();
|
|
||||||
}
|
}
|
||||||
@@ -25,8 +25,14 @@ package kotlin.test
|
|||||||
|
|
||||||
import kotlin.internal.*
|
import kotlin.internal.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current adapter providing assertion implementations
|
||||||
|
*/
|
||||||
val asserter: Asserter
|
val asserter: Asserter
|
||||||
get() = lookupAsserter()
|
get() = _asserter ?: lookupAsserter()
|
||||||
|
|
||||||
|
/** Used to override current asserter internally */
|
||||||
|
internal var _asserter: Asserter? = null
|
||||||
|
|
||||||
/** Asserts that the given [block] returns `true`. */
|
/** Asserts that the given [block] returns `true`. */
|
||||||
fun assertTrue(message: String? = null, block: () -> Boolean): Unit = assertTrue(block(), message)
|
fun assertTrue(message: String? = null, block: () -> Boolean): Unit = assertTrue(block(), message)
|
||||||
@@ -97,6 +103,7 @@ fun assertFails(message: String?, block: () -> Unit): Throwable {
|
|||||||
try {
|
try {
|
||||||
block()
|
block()
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
assertEquals(e.message, e.message) // success path assertion for qunit
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
asserter.fail(messagePrefix(message) + "Expected an exception to be thrown, but was completed successfully.")
|
asserter.fail(messagePrefix(message) + "Expected an exception to be thrown, but was completed successfully.")
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package kotlin.test
|
|||||||
/**
|
/**
|
||||||
* Default [Asserter] implementation to avoid dependency on JUnit or TestNG.
|
* Default [Asserter] implementation to avoid dependency on JUnit or TestNG.
|
||||||
*/
|
*/
|
||||||
class DefaultAsserter() : Asserter {
|
// TODO: make object in 1.2
|
||||||
|
class DefaultAsserter : Asserter {
|
||||||
override fun fail(message: String?): Nothing {
|
override fun fail(message: String?): Nothing {
|
||||||
if (message == null)
|
if (message == null)
|
||||||
throw AssertionError()
|
throw AssertionError()
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
package kotlin.test
|
package kotlin.test
|
||||||
|
|
||||||
internal fun messagePrefix(message: String?) = if (message == null) "" else "$message. "
|
internal fun messagePrefix(message: String?) = if (message == null) "" else "$message. "
|
||||||
internal header fun lookupAsserter(): Asserter
|
internal header fun lookupAsserter(): Asserter
|
||||||
|
|
||||||
|
@PublishedApi // required to get stable name as it's called from box tests
|
||||||
|
internal fun overrideAsserter(value: Asserter?): Asserter? {
|
||||||
|
// TODO: Replace with return _asserter.also { _asserter = value } after KT-17540 is fixed
|
||||||
|
val previous = _asserter
|
||||||
|
_asserter = value
|
||||||
|
return previous
|
||||||
|
}
|
||||||
+42
-15
@@ -18,8 +18,12 @@ class BasicAssertionsTest {
|
|||||||
fun testAssertFailsWith() {
|
fun testAssertFailsWith() {
|
||||||
assertFailsWith<IllegalStateException> { throw IllegalStateException() }
|
assertFailsWith<IllegalStateException> { throw IllegalStateException() }
|
||||||
assertFailsWith<AssertionError> { throw AssertionError() }
|
assertFailsWith<AssertionError> { throw AssertionError() }
|
||||||
|
}
|
||||||
|
|
||||||
run {
|
@Test fun testAssertFailsWithFails() {
|
||||||
|
assertTrue(true) // at least one assertion required for qunit
|
||||||
|
|
||||||
|
withDefaultAsserter run@ {
|
||||||
try {
|
try {
|
||||||
assertFailsWith<IllegalStateException> { throw IllegalArgumentException() }
|
assertFailsWith<IllegalStateException> { throw IllegalArgumentException() }
|
||||||
}
|
}
|
||||||
@@ -29,7 +33,7 @@ class BasicAssertionsTest {
|
|||||||
throw AssertionError("Expected to fail")
|
throw AssertionError("Expected to fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
run {
|
withDefaultAsserter run@ {
|
||||||
try {
|
try {
|
||||||
assertFailsWith<IllegalStateException> { }
|
assertFailsWith<IllegalStateException> { }
|
||||||
}
|
}
|
||||||
@@ -42,7 +46,7 @@ class BasicAssertionsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAssertEqualsFails() {
|
fun testAssertEqualsFails() {
|
||||||
assertFailsWith<AssertionError> { assertEquals(1, 2) }
|
checkFailedAssertion { assertEquals(1, 2) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -53,16 +57,20 @@ class BasicAssertionsTest {
|
|||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
fun testAssertTrueFails() {
|
fun testAssertTrueFails() {
|
||||||
assertFailsWith<AssertionError> { assertTrue(false) }
|
checkFailedAssertion { assertTrue(false) }
|
||||||
assertFailsWith<AssertionError> { assertTrue { false } }
|
checkFailedAssertion { assertTrue { false } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAssertFalse() {
|
fun testAssertFalse() {
|
||||||
assertFalse(false)
|
assertFalse(false)
|
||||||
assertFalse { false }
|
assertFalse { false }
|
||||||
assertFailsWith<AssertionError> { assertFalse(true) }
|
}
|
||||||
assertFailsWith<AssertionError> { assertFalse { true } }
|
|
||||||
|
@Test
|
||||||
|
fun testAssertFalseFails() {
|
||||||
|
checkFailedAssertion { assertFalse(true) }
|
||||||
|
checkFailedAssertion{ assertFalse { true } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -72,7 +80,7 @@ class BasicAssertionsTest {
|
|||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
fun testAssertFailsFails() {
|
fun testAssertFailsFails() {
|
||||||
assertFailsWith<AssertionError> { assertFails { } }
|
checkFailedAssertion { assertFails { } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -83,7 +91,7 @@ class BasicAssertionsTest {
|
|||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
fun testAssertNotEqualsFails() {
|
fun testAssertNotEqualsFails() {
|
||||||
assertFailsWith<AssertionError> { assertNotEquals(1, 1) }
|
checkFailedAssertion { assertNotEquals(1, 1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -93,7 +101,7 @@ class BasicAssertionsTest {
|
|||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
fun testAssertNotNullFails() {
|
fun testAssertNotNullFails() {
|
||||||
assertFailsWith<AssertionError> { assertNotNull(null) }
|
checkFailedAssertion { assertNotNull(null) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -103,7 +111,7 @@ class BasicAssertionsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAssertNotNullLambdaFails() {
|
fun testAssertNotNullLambdaFails() {
|
||||||
assertFailsWith<AssertionError> {
|
checkFailedAssertion {
|
||||||
val value: String? = null
|
val value: String? = null
|
||||||
assertNotNull(value) {
|
assertNotNull(value) {
|
||||||
it.substring(0, 0)
|
it.substring(0, 0)
|
||||||
@@ -118,18 +126,37 @@ class BasicAssertionsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAssertNullFails() {
|
fun testAssertNullFails() {
|
||||||
assertFailsWith<AssertionError> { assertNull("") }
|
checkFailedAssertion { assertNull("") }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
fun testFail() {
|
fun testFail() {
|
||||||
assertFailsWith<AssertionError> { fail("should fail") }
|
checkFailedAssertion { fail("should fail") }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testExpect() {
|
fun testExpect() {
|
||||||
expect(1) { 1 }
|
expect(1) { 1 }
|
||||||
assertFailsWith<AssertionError> { expect(1) { 2 } }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Test
|
||||||
|
fun testExpectFails() {
|
||||||
|
checkFailedAssertion { expect(1) { 2 } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun checkFailedAssertion(assertion: () -> Unit) {
|
||||||
|
assertFailsWith<AssertionError> { withDefaultAsserter(assertion) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("INVISIBLE_MEMBER")
|
||||||
|
private fun withDefaultAsserter(block: () -> Unit) {
|
||||||
|
val current = overrideAsserter(DefaultAsserter())
|
||||||
|
try {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
overrideAsserter(current)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,13 +38,14 @@ inline fun <reified T : Throwable> assertFailsWith(message: String? = null, noin
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var _asserter: Asserter = QUnitAsserter()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the JS implementation of asserter using [QUnit](http://QUnitjs.com/)
|
* Provides the JS implementation of asserter using [QUnit](http://QUnitjs.com/)
|
||||||
*/
|
*/
|
||||||
internal impl fun lookupAsserter(): Asserter = _asserter
|
internal impl fun lookupAsserter(): Asserter = qunitAsserter
|
||||||
|
|
||||||
|
private val qunitAsserter = QUnitAsserter()
|
||||||
|
|
||||||
|
// TODO: make object in 1.2
|
||||||
class QUnitAsserter : Asserter {
|
class QUnitAsserter : Asserter {
|
||||||
|
|
||||||
override fun assertTrue(lazyMessage: () -> String?, actual: Boolean) {
|
override fun assertTrue(lazyMessage: () -> String?, actual: Boolean) {
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2000-2015 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.
|
|
||||||
*/
|
|
||||||
module.exports = function (config) {
|
|
||||||
config.set({
|
|
||||||
frameworks: ['qunit'],
|
|
||||||
reporters: ['progress', 'junit'],
|
|
||||||
files: [
|
|
||||||
'../../../target/test-js/kotlin.js',
|
|
||||||
'../../../target/test-js/*.js',
|
|
||||||
'../../../target/classes/*.js'
|
|
||||||
],
|
|
||||||
exclude: [],
|
|
||||||
port: 9876,
|
|
||||||
runnerPort: 9100,
|
|
||||||
colors: true,
|
|
||||||
autoWatch: false,
|
|
||||||
browsers: [
|
|
||||||
'PhantomJS'
|
|
||||||
],
|
|
||||||
captureTimeout: 5000,
|
|
||||||
//singleRun: false,
|
|
||||||
singleRun: true,
|
|
||||||
reportSlowerThan: 500,
|
|
||||||
|
|
||||||
junitReporter: {
|
|
||||||
outputFile: '../../../target/reports/test-results.xml',
|
|
||||||
suite: ''
|
|
||||||
},
|
|
||||||
preprocessors: {
|
|
||||||
'**/*.js': ['sourcemap']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
};
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "karma-tests",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"devDependencies": {
|
|
||||||
"karma": "*",
|
|
||||||
"qunitjs": "*",
|
|
||||||
"karma-qunit": "*",
|
|
||||||
"karma-junit-reporter": "~0.2",
|
|
||||||
"karma-sourcemap-loader": "~0.3",
|
|
||||||
"karma-teamcity-reporter": "*",
|
|
||||||
"karma-phantomjs-launcher": "*",
|
|
||||||
"phantomjs": "1.9.13"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,6 +11,8 @@ private val contributors = ArrayList<AsserterContributor>()
|
|||||||
|
|
||||||
internal impl fun lookupAsserter(): Asserter = lookup()
|
internal impl fun lookupAsserter(): Asserter = lookup()
|
||||||
|
|
||||||
|
private val defaultAsserter = DefaultAsserter()
|
||||||
|
|
||||||
internal fun lookup(): Asserter {
|
internal fun lookup(): Asserter {
|
||||||
initContributorsIfNeeded()
|
initContributorsIfNeeded()
|
||||||
|
|
||||||
@@ -21,7 +23,7 @@ internal fun lookup(): Asserter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DefaultAsserter()
|
return defaultAsserter
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initContributors() {
|
private fun initContributors() {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ def jsSrcJsDir = "${jsSrcDir}/js"
|
|||||||
def jsOutputFile = "${buildDir}/classes/kotlin.js"
|
def jsOutputFile = "${buildDir}/classes/kotlin.js"
|
||||||
def jsTestOutputFile = "${buildDir}/classes/test/kotlin-stdlib-js_test.js"
|
def jsTestOutputFile = "${buildDir}/classes/test/kotlin-stdlib-js_test.js"
|
||||||
def kotlinTestJsOutputFile = "${project(':kotlin-test:kotlin-test-js').buildDir}/classes/main/kotlin-test.js"
|
def kotlinTestJsOutputFile = "${project(':kotlin-test:kotlin-test-js').buildDir}/classes/main/kotlin-test.js"
|
||||||
|
def kotlinTestJsTestOutputFile = "${project(':kotlin-test:kotlin-test-js').buildDir}/classes/test/kotlin-test-js_test.js"
|
||||||
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
builtins {
|
builtins {
|
||||||
@@ -268,10 +270,13 @@ karma {
|
|||||||
sourceFiles = []
|
sourceFiles = []
|
||||||
|
|
||||||
testBases = ['']
|
testBases = ['']
|
||||||
testFiles = [jsTestOutputFile]
|
testFiles = [jsTestOutputFile, kotlinTestJsTestOutputFile]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
karmaGenerateConfig.outputs.upToDateWhen { false }
|
karmaGenerateConfig.outputs.upToDateWhen { false }
|
||||||
karmaRun.dependsOn testClasses
|
karmaRun {
|
||||||
|
dependsOn testClasses
|
||||||
|
dependsOn tasks.getByPath(':kotlin-test:kotlin-test-js:testClasses')
|
||||||
|
}
|
||||||
clean.dependsOn karmaClean
|
clean.dependsOn karmaClean
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<script src="../build/classes/kotlin.js"></script>
|
<script src="../build/classes/kotlin.js"></script>
|
||||||
<script src="../../../kotlin.test/js/build/classes/main/kotlin-test.js"></script>
|
<script src="../../../kotlin.test/js/build/classes/main/kotlin-test.js"></script>
|
||||||
<script src="../build/classes/test/kotlin-stdlib-js_test.js"></script>
|
<script src="../build/classes/test/kotlin-stdlib-js_test.js"></script>
|
||||||
|
<script src="../../../kotlin.test/js/build/classes/test/kotlin-test-js_test.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="qunit"></div>
|
<div id="qunit"></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user