[JS IR] Add infra to test compilation with error

- add bunch of tests
 - fix help test
This commit is contained in:
Roman Artemev
2020-09-01 12:04:15 +03:00
parent e592b3af1d
commit 0bff406a12
19 changed files with 460 additions and 13 deletions
@@ -0,0 +1,16 @@
// ERROR_POLICY: SEMANTIC
// FILE: t.kt
fun foo(o: Any): Any = o as ErrType
// FILE: b.kt
fun box(): String {
try {
foo(Any())
} catch (e: IllegalStateException) {
return "OK"
}
return "fail"
}
@@ -0,0 +1,24 @@
// ERROR_POLICY: SEMANTIC
// FILE: t.kt
fun bar() { throw Exception("..") }
fun foo(): String {
try {
bar()
} catch (e: ErrType) {
throw Expception(e)
}
}
// FILE: b.kt
fun box(): String {
try {
foo()
} catch (e: IllegalStateException) {
return "OK"
}
return "fail"
}
@@ -0,0 +1,31 @@
// ERROR_POLICY: SEMANTIC
// FILE: t.kt
fun bar(aa: Any, bb: Any, cc: Any) {
}
fun foo() {
qux(a(), b(), c())
beer()
f()
}
fun a(): Any { storage += "a"; return storage }
fun b(): Any { storage += "b"; return storage }
fun c(): Any { storage += "c"; return storage }
fun f(): Any { storage += "FAIL"; return storage }
var storage = ""
// FILE: b.kt
fun box(): String {
try {
foo()
} catch (e: IllegalStateException) {
return if (storage == "abc") "OK" else "FAIL ABC"
return "FAIL"
}
}
@@ -0,0 +1,19 @@
// ERROR_POLICY: SEMANTIC
// FILE: t.kt
fun bar<T>(a: T): T = a
var storage = ""
fun foo() {
storage += bar("O")
storage += bar<Any, String, Number>("K")
}
// FILE: b.kt
fun box(): String {
foo()
return storage
}
@@ -0,0 +1,17 @@
// ERROR_POLICY: SEMANTIC
// FILE: t.kt
fun bar(a: String, b: String): String
fun foo(): String {
return bar("O", "K")
}
// FILE: b.kt
fun box(): String {
val r = foo()
if (r is String) return r
return "OK"
}
@@ -0,0 +1,23 @@
// ERROR_POLICY: SEMANTIC
// FILE: t.kt
fun <reified T> bar(t: T) = t
fun <reified T> qux() = T::class
fun foo(): String {
return bar<String>("OK")
}
fun dec() { qux() }
// FILE: b.kt
fun box(): String {
try {
dec()
} catch (e: Throwable /*js ReferenceError*/) {
return foo()
}
}
@@ -0,0 +1,22 @@
// ERROR_POLICY: SEMANTIC
// FILE: t.kt
class A
class B
fun bar(): B = B()
fun foo(): A {
return bar()
}
// FILE: b.kt
fun box(): String {
try {
foo()
} catch (e: ClassCastException) {
return "OK"
}
return "FAIL"
}
@@ -0,0 +1,31 @@
// ERROR_POLICY: SEMANTIC
// FILE: t.kt
var storage = ""
fun bar(a: String, b: String) { storage += a; storage += b; }
fun foo1() {
bar("O", "K")
bar("FAIL1")
}
fun foo2() {
bar("FAIL2", "FAIL2", "FAIL2", "FAIL2")
}
// FILE: b.kt
fun box(): String {
try {
foo1()
} catch (e: IllegalStateException) {
try {
foo2()
} catch (e: IllegalStateException) {
return storage
}
}
return "FAIL"
}
@@ -0,0 +1,17 @@
// ERROR_POLICY: SEMANTIC
// FILE: t.kt
fun foo() { bar() }
// FILE: b.kt
fun box(): String {
try {
foo()
} catch (e: IllegalStateException) {
return "OK"
}
return "FAIL"
}