KT-2752: fix some tests and make them slightly less fragile

This commit is contained in:
Alexey Andreev
2016-09-23 15:20:36 +03:00
parent 9c7c82b151
commit 831ac97ecd
8 changed files with 96 additions and 80 deletions
+50 -39
View File
@@ -161,72 +161,83 @@ fun test(expected: String, f: () -> Unit) {
}
}
val privateMangledRegex = Regex("baz_[0-9a-zA-Z]+\\\$_0")
fun testMangledPrivate(f: () -> Unit) {
val actual = f.extractNames()
if (!privateMangledRegex.matches(actual[1])) {
fail("Failed on '$testGroup' group: actual[1] = \"${actual[1]}\"\n actual = $actual, should look like 'baz_<hash>_0'")
}
if ("_za3lpa\$" in actual[1]) {
fail("Failed on '$testGroup' group: actual[1] = \"${actual[1]}\"\n actual = $actual, should not contains 'za3lpa\$'")
}
}
public fun stable_mangled_baz(i: Int) {
}
val SIMPLE = "baz"
val SIMPLE1 = "${SIMPLE}_1"
val SIMPLE0 = "${SIMPLE}_0"
val NATIVE = SIMPLE
val STABLE = { stable_mangled_baz(0) }.extractNames()[1]
fun box(): String {
// TODO: these tests are too fragile
testGroup = "Top Level"
test(STABLE) { public_baz(0) }
test(NATIVE) { public_baz("native") }
//test(SIMPLE1) { internal_baz(0) }
//test(NATIVE) { internal_baz("native") }
//test(SIMPLE1) { private_baz(0) }
//test(NATIVE) { private_baz("native") }
test(SIMPLE0) { internal_baz(0) }
test(NATIVE) { internal_baz("native") }
test(SIMPLE0) { private_baz(0) }
test(NATIVE) { private_baz("native") }
testGroup = "Public Class"
test(STABLE) { PublicClass().public_baz(0) }
test(NATIVE) { PublicClass().public_baz("native") }
//test(SIMPLE1) { PublicClass().internal_baz(0) }
//test(NATIVE) { PublicClass().internal_baz("native") }
//test(SIMPLE1, PublicClass().call_private_baz)
//test(NATIVE, PublicClass().call_private_native_baz)
test(SIMPLE0) { PublicClass().internal_baz(0) }
test(NATIVE) { PublicClass().internal_baz("native") }
test(SIMPLE0, PublicClass().call_private_baz)
test(NATIVE, PublicClass().call_private_native_baz)
testGroup = "Internal Class"
//test(SIMPLE1) { InternalClass().public_baz(0) }
//test(NATIVE) { InternalClass().public_baz("native") }
//test(SIMPLE1) { InternalClass().internal_baz(0) }
//test(NATIVE) { InternalClass().internal_baz("native") }
//test(SIMPLE1, InternalClass().call_private_baz)
//test(NATIVE, InternalClass().call_private_native_baz)
test(STABLE) { InternalClass().public_baz(0) }
test(NATIVE) { InternalClass().public_baz("native") }
test(SIMPLE0) { InternalClass().internal_baz(0) }
test(NATIVE) { InternalClass().internal_baz("native") }
test(SIMPLE0, InternalClass().call_private_baz)
test(NATIVE, InternalClass().call_private_native_baz)
testGroup = "Private Class"
//test(SIMPLE1) { PrivateClass().public_baz(0) }
//test(NATIVE) { PrivateClass().public_baz("native") }
//test(SIMPLE1) { PrivateClass().internal_baz(0) }
//test(NATIVE) { PrivateClass().internal_baz("native") }
//test(SIMPLE1, PrivateClass().call_private_baz)
//test(NATIVE, PrivateClass().call_private_native_baz)
test(STABLE) { PrivateClass().public_baz(0) }
test(NATIVE) { PrivateClass().public_baz("native") }
test(SIMPLE0) { PrivateClass().internal_baz(0) }
test(NATIVE) { PrivateClass().internal_baz("native") }
test(SIMPLE0, PrivateClass().call_private_baz)
test(NATIVE, PrivateClass().call_private_native_baz)
testGroup = "Open Public Class"
test(STABLE) { OpenPublicClass().public_baz(0) }
test(NATIVE) { OpenPublicClass().public_baz("native") }
//test(STABLE) { OpenPublicClass().internal_baz(0) }
//test(NATIVE) { OpenPublicClass().internal_baz("native") }
//test(STABLE, OpenPublicClass().call_private_baz)
//test(NATIVE, OpenPublicClass().call_private_native_baz)
testMangledPrivate { OpenPublicClass().internal_baz(0) }
test(NATIVE) { OpenPublicClass().internal_baz("native") }
testMangledPrivate(OpenPublicClass().call_private_baz)
test(NATIVE, OpenPublicClass().call_private_native_baz)
testGroup = "Open Internal Class"
//test(STABLE) { OpenInternalClass().public_baz(0) }
//test(NATIVE) { OpenInternalClass().public_baz("native") }
//test(STABLE) { OpenInternalClass().internal_baz(0) }
//test(NATIVE) { OpenInternalClass().internal_baz("native") }
//test(STABLE, OpenInternalClass().call_private_baz)
//test(NATIVE, OpenInternalClass().call_private_native_baz)
test(STABLE) { OpenInternalClass().public_baz(0) }
test(NATIVE) { OpenInternalClass().public_baz("native") }
test(SIMPLE0) { OpenInternalClass().internal_baz(0) }
test(NATIVE) { OpenInternalClass().internal_baz("native") }
test(SIMPLE0, OpenInternalClass().call_private_baz)
test(NATIVE, OpenInternalClass().call_private_native_baz)
testGroup = "Open Private Class"
//test(STABLE) { OpenPrivateClass().public_baz(0) }
//test(NATIVE) { OpenPrivateClass().public_baz("native") }
//test(STABLE) { OpenPrivateClass().internal_baz(0) }
//test(NATIVE) { OpenPrivateClass().internal_baz("native") }
//test(STABLE, OpenPrivateClass().call_private_baz)
//test(NATIVE, OpenPrivateClass().call_private_native_baz)
test(STABLE) { OpenPrivateClass().public_baz(0) }
test(NATIVE) { OpenPrivateClass().public_baz("native") }
test(SIMPLE0) { OpenPrivateClass().internal_baz(0) }
test(NATIVE) { OpenPrivateClass().internal_baz("native") }
test(SIMPLE0, OpenPrivateClass().call_private_baz)
test(NATIVE, OpenPrivateClass().call_private_native_baz)
return "OK"
}
@@ -3,6 +3,9 @@ package foo
public fun equals(a: Any?): Boolean = true
public fun hashCode(): Int = 0
public fun toString(): String = ""
fun equals(a: Any?, b: Any?): Boolean = true
fun hashCode(i: Int): Int = 0
fun toString(s: String): String = ""
public class PublicClass {
override fun equals(a: Any?): Boolean = this === a
@@ -58,12 +61,12 @@ fun test(expected: String, f: () -> Unit) {
}
}
val SIMPLE_EQUALS = "equals"
val SIMPLE_HASH_CODE_1 = "hashCode_1"
val SIMPLE_TO_STRING_1 = "toString_1"
val STABLE_EQUALS = { equals(0) }.extractNames()[1]
val STABLE_HASH_CODE = { hashCode() }.extractNames()[1]
val STABLE_TO_STRING = { toString() }.extractNames()[1]
val STABLE_EQUALS_2 = { equals(0, 0) }.extractNames()[1]
val STABLE_HASH_CODE_2 = { hashCode(0) }.extractNames()[1]
val STABLE_TO_STRING_2 = { toString("") }.extractNames()[1]
fun box(): String {
testGroup = "Public Class"
@@ -75,17 +78,17 @@ fun box(): String {
test(STABLE_EQUALS) { InternalClass().equals(0) }
test(STABLE_HASH_CODE) { InternalClass().hashCode() }
test(STABLE_TO_STRING) { InternalClass().toString() }
//test(SIMPLE_EQUALS) { InternalClass().equals(0, 1) }
//test(SIMPLE_HASH_CODE_1) { InternalClass().hashCode(2) }
//test(SIMPLE_TO_STRING_1) { InternalClass().toString("3") }
test(STABLE_EQUALS_2) { InternalClass().equals(0, 1) }
test(STABLE_HASH_CODE_2) { InternalClass().hashCode(2) }
test(STABLE_TO_STRING_2) { InternalClass().toString("3") }
testGroup = "Private Class"
test(STABLE_EQUALS) { PrivateClass().equals(0) }
test(STABLE_HASH_CODE) { PrivateClass().hashCode() }
test(STABLE_TO_STRING) { PrivateClass().toString() }
//test(SIMPLE_EQUALS) { PrivateClass().equals(0, 1) }
//test(SIMPLE_HASH_CODE_1) { PrivateClass().hashCode(2) }
//test(SIMPLE_TO_STRING_1) { PrivateClass().toString("3") }
test(STABLE_EQUALS_2) { PrivateClass().equals(0, 1) }
test(STABLE_HASH_CODE_2) { PrivateClass().hashCode(2) }
test(STABLE_TO_STRING_2) { PrivateClass().toString("3") }
return "OK"
}
@@ -31,9 +31,9 @@ private fun private_foo(): Int = 1
private fun private_foo(i: Int): Int = 2
@native private fun private_boo(a: Array<Int>): String = "should be ignored"
private fun private_boo(): Int = 1
private fun private_boo(i: Int): Int = 2
private fun private_boo(s: String): Int = 3
private fun private_boo(): Int = 1
val private_f = { private_foo() + private_foo(1) }
val private_b = { private_boo() + private_boo(1) }
@@ -56,12 +56,12 @@ val mixed_b = { mixed_boo() + mixed_boo(1) + mixed_boo("str") + mixed_boo("str",
class TestInternal {
@JsName("foo") internal fun foo(): Int = 1
@JsName("foo_2") internal fun foo(i: Int): Int = 2
internal fun foo(): Int = 1
internal fun foo(i: Int): Int = 2
@JsName("boo_2") internal fun boo(i: Int): Int = 2
@JsName("boo_3") internal fun boo(s: String): Int = 3
@JsName("boo") internal fun boo(): Int = 1
internal fun boo(): Int = 1
internal fun boo(i: Int): Int = 2
internal fun boo(s: String): Int = 3
}
val internal_in_class_f = { TestInternal().foo() + TestInternal().foo(1) }
@@ -85,9 +85,9 @@ class TestPrivate {
private fun foo(): Int = 1
private fun foo(i: Int): Int = 2
private fun boo(): Int = 1
private fun boo(i: Int): Int = 2
private fun boo(s: String): Int = 3
private fun boo(): Int = 1
val f = { foo() + foo(1) }
val b = { boo() + boo(1) }
@@ -149,12 +149,12 @@ fun test(testName: String, ff: Any, fb: Any) {
fun box(): String {
test("internal", internal_f, internal_b)
test("public", public_f, public_b)
//test("private", private_f, private_b)
test("private", private_f, private_b)
test("mixed", mixed_f, mixed_b)
test("internal_in_class", internal_in_class_f, internal_in_class_b)
test("public_in_class", public_in_class_f, public_in_class_b)
//test("private_in_class", private_in_class_f, private_in_class_b)
test("private_in_class", private_in_class_f, private_in_class_b)
test("mixed_in_class", mixed_in_class_f, mixed_in_class_b)
test("public_ext_prop", public_ext_f, public_ext_b)