[Spec tests] Add tests for try-expression (paragraphs 1, 2, 5-9)
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
java.lang.Exception
|
||||
_2_1Kt.throwException(2.1.kt:14)
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 2 -> sentence 2
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.
|
||||
* EXCEPTION: runtime
|
||||
*/
|
||||
|
||||
fun throwException(b: Boolean) = run { if (b) throw Exception() }
|
||||
class ExcA() : Exception()
|
||||
|
||||
|
||||
fun box() {
|
||||
|
||||
var flag = false
|
||||
try {
|
||||
throwException(true)
|
||||
flag = true
|
||||
} catch (e: ExcA) {
|
||||
|
||||
}
|
||||
//result java.lang.Exception cos of type mismatch
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 2 -> sentence 2
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.
|
||||
*/
|
||||
|
||||
fun throwException(b: Boolean) = run { if (b) throw Exception() }
|
||||
|
||||
|
||||
fun box(): String {
|
||||
var flag = false
|
||||
try {
|
||||
throwException(true)
|
||||
flag = true
|
||||
} catch (e: Exception) {
|
||||
if (!flag)
|
||||
return "OK"
|
||||
}
|
||||
return "NOK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 2 -> sentence 2
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.
|
||||
*/
|
||||
|
||||
fun throwExceptionB(b: Boolean) = run { if (b) throw ExcB() }
|
||||
|
||||
|
||||
class ExcA() : Exception()
|
||||
class ExcB() : Exception()
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var flag = false
|
||||
try {
|
||||
throwExceptionB(true)
|
||||
flag = true
|
||||
} catch (e: ExcA) {
|
||||
return "NOK"
|
||||
} catch (e: ExcB) {
|
||||
return if (flag)
|
||||
"NOK"
|
||||
else "OK"
|
||||
}
|
||||
return "NOK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 2 -> sentence 2
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 3
|
||||
* DESCRIPTION: catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.
|
||||
*/
|
||||
|
||||
fun throwExceptionB(b: Boolean) = run { if (b) throw ExcB() }
|
||||
|
||||
|
||||
class ExcA() : Exception()
|
||||
class ExcB() : Exception()
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var flag = false
|
||||
try {
|
||||
throwExceptionB(true)
|
||||
flag = true
|
||||
} catch (e: ExcA) {
|
||||
return "NOK"
|
||||
} catch (e: Exception) {
|
||||
return if (flag)
|
||||
"NOK"
|
||||
else "OK"
|
||||
}
|
||||
return "NOK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 2 -> sentence 3
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: If there are several catch blocks which match the exception type, the first one is picked.
|
||||
*/
|
||||
fun throwExceptionB(b: Boolean) = run { if (b) throw ExcB() }
|
||||
|
||||
|
||||
class ExcA() : Exception()
|
||||
class ExcB() : Exception()
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var flag = false
|
||||
try {
|
||||
throwExceptionB(true)
|
||||
flag = true
|
||||
} catch (e: ExcA) {
|
||||
return "NOK"
|
||||
} catch (e: Exception) {
|
||||
return if (flag)
|
||||
"NOK"
|
||||
else "OK"
|
||||
}catch (e : ExcB){
|
||||
return "NOK"
|
||||
}
|
||||
return "NOK"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 2 -> sentence 3
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: If there are several catch blocks which match the exception type, the first one is picked.
|
||||
*/
|
||||
|
||||
fun throwExceptionB(b: Boolean) = run { if (b) throw ExcB() }
|
||||
|
||||
|
||||
class ExcA() : Exception()
|
||||
class ExcB() : Exception()
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var flag = false
|
||||
try {
|
||||
throwExceptionB(true)
|
||||
flag = true
|
||||
} catch (e: ExcA) {
|
||||
return "NOK"
|
||||
} catch (e: ExcB) {
|
||||
return if (flag)
|
||||
"NOK"
|
||||
else "OK"
|
||||
}catch (e : Exception){
|
||||
return "NOK"
|
||||
}
|
||||
return "NOK"
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
ExcA
|
||||
_3_1Kt.throwExceptionA(3.1.kt:15)
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 5 -> sentence 3
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 4 -> sentence 1
|
||||
* exceptions, catching-exceptions -> paragraph 4 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: If an exception was thrown, but no catch block matched its type, the finally block is evaluated before propagating the exception up the call stack
|
||||
* EXCEPTION: runtime
|
||||
*/
|
||||
|
||||
fun throwExceptionA(b: Boolean) = run { if (b) throw ExcA() }
|
||||
|
||||
class ExcA() : Exception()
|
||||
class ExcB() : Exception()
|
||||
|
||||
fun box() {
|
||||
try {
|
||||
throwExceptionA(true)
|
||||
} catch (e: ExcB) {
|
||||
|
||||
} finally {
|
||||
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 5 -> sentence 1
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 4 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: If no exception is thrown during the evaluation of the try body, no catch blocks are executed, the finally block is evaluated after the try body, and the program execution continues as normal.
|
||||
*/
|
||||
|
||||
|
||||
fun box(): String {
|
||||
var isTryExecuted = false
|
||||
var isCatched = false
|
||||
var isFinallyExecuted = false
|
||||
var isExecutedFully = false
|
||||
try {
|
||||
isTryExecuted = true
|
||||
} catch (e: Exception) {
|
||||
isCatched = true
|
||||
} finally {
|
||||
isFinallyExecuted = true
|
||||
}
|
||||
isExecutedFully = true
|
||||
return if (isTryExecuted && !isCatched && isFinallyExecuted && isExecutedFully) "OK"
|
||||
else "NOK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 5 -> sentence 2
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 4 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: the finally block is evaluated after the evaluation of the matching catch block.
|
||||
*/
|
||||
|
||||
fun throwException(b: Boolean) = run { if (b) throw Exception() }
|
||||
|
||||
fun box(): String {
|
||||
var isTryExecuted = false
|
||||
var isCatched = false
|
||||
var isFinallyExecuted = false
|
||||
var isExecutedFully = false
|
||||
try {
|
||||
isTryExecuted = true
|
||||
throwException(true)
|
||||
} catch (e: Exception) {
|
||||
isCatched = true
|
||||
} finally {
|
||||
isFinallyExecuted = true
|
||||
}
|
||||
isExecutedFully = true
|
||||
return if (isTryExecuted &&isCatched && isFinallyExecuted && isExecutedFully) "OK"
|
||||
else "NOK"
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// SKIP_TXT
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 5 -> sentence 3
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 4 -> sentence 1
|
||||
* exceptions, catching-exceptions -> paragraph 4 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: If an exception was thrown, but no catch block matched its type, the finally block is evaluated before propagating the exception up the call stack
|
||||
*/
|
||||
fun throwExceptionA(b: Boolean) = run { if (b) throw ExcA() }
|
||||
|
||||
class ExcA() : Exception()
|
||||
class ExcB() : Exception()
|
||||
|
||||
fun box(): String {
|
||||
var isTryExecuted = false
|
||||
var isCatched = false
|
||||
var isFinallyExecuted = false
|
||||
var isExecutedFully = false
|
||||
var isTryExpressionPropagated = false
|
||||
|
||||
try {
|
||||
try {
|
||||
isTryExecuted = true
|
||||
throwExceptionA(true)
|
||||
} catch (e: ExcB) {
|
||||
isCatched = true
|
||||
} finally {
|
||||
isFinallyExecuted = true
|
||||
}
|
||||
} catch (e: ExcA) {
|
||||
isTryExpressionPropagated = true
|
||||
}
|
||||
|
||||
isExecutedFully = true
|
||||
return if (isTryExecuted &&
|
||||
!isCatched &&
|
||||
isFinallyExecuted &&
|
||||
isTryExpressionPropagated &&
|
||||
isExecutedFully
|
||||
) "OK"
|
||||
else "NOK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 6 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION:The value of the try-expression is the same as the value of the last expression of the try or catch block
|
||||
*/
|
||||
|
||||
fun box(): String {
|
||||
var a = 1
|
||||
val tryVal1 = try { 3 } catch (e: Exception) { 5 }
|
||||
val tryVal2 = try { 3 ; throw Exception() } catch (e: Exception) { 5 }
|
||||
if (tryVal1 == 3 && tryVal2 == 5)
|
||||
return "OK"
|
||||
else return "NOK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, try-expression -> paragraph 7 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: finally block has no effect on the value returned by the try-expression
|
||||
*/
|
||||
|
||||
fun box(): String {
|
||||
var a = 1
|
||||
val tryVal1 = try { 3 } catch (e: Exception) { 5 } finally { 100}
|
||||
val tryVal2 = try { 3; throw Exception() } catch (e: Exception) { 5 } finally { 100 }
|
||||
if (tryVal1 == 3 && tryVal2 == 5)
|
||||
return "OK"
|
||||
else return "NOK"
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
{
|
||||
"7": {
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "finally block has no effect on the value returned by the try-expression",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"6": {
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "The value of the try-expression is the same as the value of the last expression of the try or catch block",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"neg": {
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression/p-2/neg/2.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"pos": {
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression/p-2/pos/2.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression/p-2/pos/2.3.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression/p-2/pos/2.2.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"3": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "If there are several catch blocks which match the exception type, the first one is picked.",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "If there are several catch blocks which match the exception type, the first one is picked.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"5": {
|
||||
"neg": {
|
||||
"3": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "If an exception was thrown, but no catch block matched its type, the finally block is evaluated before propagating the exception up the call stack",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"pos": {
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "the finally block is evaluated after the evaluation of the matching catch block.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"3": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "If an exception was thrown, but no catch block matched its type, the finally block is evaluated before propagating the exception up the call stack",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "If no exception is thrown during the evaluation of the try body, no catch blocks are executed, the finally block is evaluated after the try body, and the program execution continues as normal.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"4": {
|
||||
"neg": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "If an exception was thrown, but no catch block matched its type, the finally block is evaluated before propagating the exception up the call stack",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression/p-5/neg/3.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "the finally block is evaluated after the evaluation of the matching catch block.",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression/p-5/pos/2.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "If an exception was thrown, but no catch block matched its type, the finally block is evaluated before propagating the exception up the call stack",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression/p-5/pos/3.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "If no exception is thrown during the evaluation of the try body, no catch blocks are executed, the finally block is evaluated after the try body, and the program execution continues as normal.",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression/p-5/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user