Refactor: extract JVM-specific tests into separate files

Make KotlinVersion random comparison test running in JS
This commit is contained in:
Ilya Gorbunov
2018-03-21 18:52:00 +03:00
parent 2d099a29b8
commit 7a40b4c5f1
12 changed files with 260 additions and 204 deletions
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
@file:JvmVersion
package test.utils
import kotlin.test.*
class AssertionsJVMTest() {
@Test fun passingAssert() {
assert(true)
var called = false
assert(true) { called = true; "some message" }
assertFalse(called)
}
@Test fun failingAssert() {
val error = assertFailsWith<AssertionError> {
assert(false)
}
assertEquals("Assertion failed", error.message)
}
@Test fun failingAssertWithMessage() {
val error = assertFailsWith<AssertionError> {
assert(false) { "Hello" }
}
assertEquals("Hello", error.message)
}
}
@@ -1,5 +1,6 @@
package test.utils
import test.randomInt
import kotlin.test.*
@@ -55,10 +56,8 @@ class KotlinVersionTest {
}
}
@JvmVersion // until there's random in JS
@Test fun randomVersionComparison() {
val random = java.util.Random()
fun randomComponent(): Int = random.nextInt(KotlinVersion.MAX_COMPONENT_VALUE + 1)
fun randomComponent(): Int = randomInt(KotlinVersion.MAX_COMPONENT_VALUE + 1)
fun randomVersion() = KotlinVersion(randomComponent(), randomComponent(), randomComponent())
repeat(1000) {
val v1 = randomVersion()
@@ -89,33 +89,6 @@ class PreconditionsTest() {
}
}
@kotlin.jvm.JvmVersion
@Test fun passingAssert() {
assert(true)
var called = false
assert(true) { called = true; "some message" }
assertFalse(called)
}
@kotlin.jvm.JvmVersion
@Test fun failingAssert() {
val error = assertFailsWith<AssertionError> {
assert(false)
}
assertEquals("Assertion failed", error.message)
}
@kotlin.jvm.JvmVersion
@Test fun failingAssertWithMessage() {
val error = assertFailsWith<AssertionError> {
assert(false) { "Hello" }
}
assertEquals("Hello", error.message)
}
@Test fun error() {
val error = assertFailsWith<IllegalStateException> {
error("There was a problem")