tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
class MyString {
|
||||
var s = ""
|
||||
operator fun plus(x : String) : MyString {
|
||||
s += x
|
||||
return this
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun test1() : MyString {
|
||||
var r = MyString()
|
||||
try {
|
||||
r + "Try1"
|
||||
|
||||
try {
|
||||
r + "Try2"
|
||||
if (true)
|
||||
return r
|
||||
} finally {
|
||||
r + "Finally2"
|
||||
if (true) {
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
return r
|
||||
} finally {
|
||||
r + "Finally1"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return if (test1().toString() == "Try1Try2Finally2Finally1") "OK" else "fail: ${test1()}"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
fun test1() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
throw Exception()
|
||||
} catch (x : Exception) {
|
||||
s += "Catch";
|
||||
throw x
|
||||
} finally {
|
||||
s += "Finally";
|
||||
}
|
||||
} catch (x : Exception) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
fun test2() : String {
|
||||
var s = "";
|
||||
|
||||
try {
|
||||
s += "Try";
|
||||
throw Exception()
|
||||
} catch (x : Exception) {
|
||||
s += "Catch";
|
||||
} finally {
|
||||
s += "Finally";
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun box() : String {
|
||||
if (test1() != "TryCatchFinally") return "fail1: ${test1()}"
|
||||
|
||||
if (test2() != "TryCatchFinally") return "fail2: ${test2()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fun f(): Int {
|
||||
try {
|
||||
return 0
|
||||
}
|
||||
finally {
|
||||
try { // culprit ?? remove this try-catch and it works.
|
||||
} catch (ignore: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (f() != 0) return "fail1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
fun fail() = if (true) throw RuntimeException() else 1
|
||||
|
||||
fun test1(): String {
|
||||
var r = ""
|
||||
try {
|
||||
try {
|
||||
r += "Try"
|
||||
return r
|
||||
} catch (e: RuntimeException) {
|
||||
r += "Catch"
|
||||
return r
|
||||
}
|
||||
finally {
|
||||
r += "Finally"
|
||||
fail()
|
||||
}
|
||||
} catch (e: RuntimeException) {
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(): String {
|
||||
var r = ""
|
||||
try {
|
||||
try {
|
||||
r += "Try"
|
||||
} catch (e: RuntimeException) {
|
||||
r += "Catch"
|
||||
}
|
||||
finally {
|
||||
r += "Finally"
|
||||
fail()
|
||||
}
|
||||
} catch (e: RuntimeException) {
|
||||
return r
|
||||
}
|
||||
return r + "Fail"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != "TryFinally") return "fail1: ${test1()}"
|
||||
|
||||
if (test2() != "TryFinally") return "fail2: ${test2()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
fun test1(): String {
|
||||
var r = ""
|
||||
for (i in 1..2) {
|
||||
try {
|
||||
r += "O"
|
||||
continue
|
||||
} finally {
|
||||
r += "K"
|
||||
break
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
fun test2(): String {
|
||||
var r = ""
|
||||
for (i in 1..2) {
|
||||
try {
|
||||
r += "O"
|
||||
break
|
||||
} finally {
|
||||
r += "K"
|
||||
continue
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != "OK") return "fail1: ${test1()}"
|
||||
|
||||
if (test2() != "OKOK") return "fail2: ${test2()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
class MyString {
|
||||
var s = ""
|
||||
operator fun plus(x : String) : MyString {
|
||||
s += x
|
||||
return this
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
fun test1() : MyString {
|
||||
var r = MyString()
|
||||
while (true) {
|
||||
try {
|
||||
r + "Try"
|
||||
|
||||
if (true) {
|
||||
r + "Break"
|
||||
break
|
||||
}
|
||||
|
||||
} finally {
|
||||
return r + "Finally"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (test1().toString() != "TryBreakFinally") return "fail1: ${test1().toString()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun <T, R> io(s: R, a: (R) -> T): T {
|
||||
try {
|
||||
return a(s)
|
||||
} finally {
|
||||
try {
|
||||
s.toString()
|
||||
} catch(e: Exception) {
|
||||
//NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return io(("OK"), {it})
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
//KT-3869 Loops and finally: outer finally block not run
|
||||
|
||||
class MyString {
|
||||
var s = ""
|
||||
operator fun plus(x : String) : MyString {
|
||||
s += x
|
||||
return this
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
fun test1() : MyString {
|
||||
var r = MyString()
|
||||
try {
|
||||
r + "Try"
|
||||
|
||||
while(r.toString() != "") {
|
||||
return r + "Loop"
|
||||
}
|
||||
|
||||
return r + "Fail"
|
||||
} finally {
|
||||
r + "Finally"
|
||||
}
|
||||
}
|
||||
|
||||
fun test2() : MyString {
|
||||
var r = MyString()
|
||||
try {
|
||||
r + "Try"
|
||||
|
||||
do {
|
||||
if (r.toString() != "") {
|
||||
return r + "Loop"
|
||||
}
|
||||
} while (r.toString() != "")
|
||||
|
||||
return r + "Fail"
|
||||
} finally {
|
||||
r + "Finally"
|
||||
}
|
||||
}
|
||||
|
||||
fun test3() : MyString {
|
||||
var r = MyString()
|
||||
try {
|
||||
r + "Try"
|
||||
|
||||
for(i in 1..2) {
|
||||
r + "Loop"
|
||||
return r
|
||||
}
|
||||
|
||||
return r + "Fail"
|
||||
} finally {
|
||||
r + "Finally"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1().toString() != "TryLoopFinally") return "fail1: ${test1()}"
|
||||
if (test2().toString() != "TryLoopFinally") return "fail2: ${test2()}"
|
||||
if (test3().toString() != "TryLoopFinally") return "fail3: ${test3()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
fun unsupportedEx() {
|
||||
if (true) throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun runtimeEx() {
|
||||
if (true) throw RuntimeException()
|
||||
}
|
||||
|
||||
fun test1() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
} catch (x : UnsupportedOperationException) {
|
||||
s += "Catch";
|
||||
runtimeEx()
|
||||
} catch (e: RuntimeException) {
|
||||
s += "WrongCatch"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
fun test1WithFinally() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
} catch (x : UnsupportedOperationException) {
|
||||
s += "Catch";
|
||||
runtimeEx()
|
||||
} catch (e: RuntimeException) {
|
||||
s += "WrongCatch"
|
||||
} finally {
|
||||
s += "Finally"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
fun test2() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
return s
|
||||
} catch (x : UnsupportedOperationException) {
|
||||
s += "Catch";
|
||||
runtimeEx()
|
||||
return s
|
||||
} catch (e: RuntimeException) {
|
||||
s += "WrongCatch"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
fun test2WithFinally() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
return s
|
||||
} catch (x : UnsupportedOperationException) {
|
||||
s += "Catch";
|
||||
runtimeEx()
|
||||
return s
|
||||
} catch (e: RuntimeException) {
|
||||
s += "WrongCatch"
|
||||
} finally {
|
||||
s += "Finally"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun box() : String {
|
||||
if (test1() != "TryCatch") return "fail1: ${test1()}"
|
||||
if (test1WithFinally() != "TryCatchFinally") return "fail2: ${test1WithFinally()}"
|
||||
|
||||
if (test2() != "TryCatch") return "fail3: ${test2()}"
|
||||
if (test2WithFinally() != "TryCatchFinally") return "fail4: ${test2WithFinally()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
fun unsupportedEx() {
|
||||
if (true) throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun runtimeEx() {
|
||||
if (true) throw RuntimeException()
|
||||
}
|
||||
|
||||
fun test1WithFinally() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
} finally {
|
||||
s += "Finally"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
|
||||
fun test2WithFinally() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
return s
|
||||
} finally {
|
||||
s += "Finally"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if (test1WithFinally() != "TryFinally") return "fail2: ${test1WithFinally()}"
|
||||
|
||||
if (test2WithFinally() != "TryFinally") return "fail4: ${test2WithFinally()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//test for appropriate
|
||||
|
||||
class MyString {
|
||||
var s = ""
|
||||
operator fun plus(x : String) : MyString {
|
||||
s += x
|
||||
return this
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun test1() : MyString {
|
||||
var r = MyString()
|
||||
try {
|
||||
r + "Try1"
|
||||
for(i in 1..1) {
|
||||
try {
|
||||
r + "Try2"
|
||||
} finally {
|
||||
return r + "Finally2"
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
r + "Finally1"
|
||||
}
|
||||
return r + "Fail"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (test1().toString() == "Try1Try2Finally2Finally1") "OK" else "fail: ${test1()}"
|
||||
}
|
||||
Reference in New Issue
Block a user