FIR: Adjust testData for spec tests: contracts

This commit is contained in:
Denis Zharkov
2020-04-15 13:05:05 +03:00
parent 243f9bb758
commit 86e1aadd31
78 changed files with 7320 additions and 0 deletions
@@ -0,0 +1,18 @@
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
/*
* KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE)
*
* SECTIONS: contracts, declarations, contractFunction
* NUMBER: 1
* DESCRIPTION: Check that recursion isn't allowed in contract functions with CallsInPlace effect.
*/
import kotlin.contracts.*
// TESTCASE NUMBER: 1
inline fun case_1(block: () -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
block()
case_1(block)
}
@@ -0,0 +1,82 @@
// !LANGUAGE: +AllowContractsForNonOverridableMembers +AllowReifiedGenericsInContracts
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
/*
* KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE)
*
* SECTIONS: contracts, declarations, contractFunction
* NUMBER: 2
* DESCRIPTION: Check report about use contracts in literal functions, lambdas or not top-level functions.
* ISSUES: KT-26149
* HELPERS: classes
*/
import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1() {
val fun_1 = fun(block: () -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return block()
}
fun_1 { throw Exception() }
println("1")
}
// TESTCASE NUMBER: 2
fun case_2() {
val lambda_1 = { block: () -> Unit ->
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
block()
}
lambda_1 { throw Exception() }
println("1")
}
/*
* TESTCASE NUMBER: 4
* ISSUES: KT-26244
*/
class case_4 : ClassLevel3() {
fun <T : Number?>T.case_4_1(): Boolean {
contract { returns(false) implies (this@case_4 !is ClassLevel1) }
return this == null
}
fun <T : Boolean>T.case_4_2() {
contract { returns() implies (!this@case_4_2) }
if (this) throw Exception()
}
fun <T>T.case_4_3_wrap() {
fun case_4_3_contract() {
contract { returns() implies (this@case_4_3_wrap is ClassLevel1) }
if (this@case_4_3_wrap !is ClassLevel1) throw Exception()
}
case_4_3_contract()
println("!")
}
fun case_4_3() = ClassLevel3().case_4_3_wrap()
}
/*
* TESTCASE NUMBER: 5
* ISSUES: KT-26244
*/
class case_5<T> : ClassLevel5() {
inner class case_5_1 {
fun <K : Number?>K.case_5_1_1() {
contract { returns() implies (this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this@case_5_1_1 is Float) }
if (!(this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this is Float)) throw Exception()
}
fun case_5_1_2() {
contract { returns() implies (this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null) }
if (!(this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null)) throw Exception()
}
}
}
@@ -0,0 +1,66 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
/*
* KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE)
*
* SECTIONS: contracts, declarations, contractFunction
* NUMBER: 4
* DESCRIPTION: Check that fun with contract and CallsInPlace effect is an inline function.
* ISSUES: KT-27090
*/
import kotlin.contracts.*
// TESTCASE NUMBER: 1
val Boolean.case_1: () -> Unit
get() {
contract {
returns() implies (this@case_1)
}
return {}
}
// TESTCASE NUMBER: 2
val (() -> Unit).case_2: () -> Unit
get() {
contract {
callsInPlace(this@case_2, InvocationKind.EXACTLY_ONCE)
}
return {}
}
// TESTCASE NUMBER: 3
var Boolean.case_3: () -> Unit
get() {
return {}
}
set(value) {
contract {
callsInPlace(value, InvocationKind.EXACTLY_ONCE)
}
}
// TESTCASE NUMBER: 4
var (() -> Unit).case_4: () -> Unit
get() {
return {}
}
set(value) {
contract {
callsInPlace(this@case_4, InvocationKind.EXACTLY_ONCE)
}
}
// TESTCASE NUMBER: 5
val Boolean.case_5: () -> Unit
get() {
contract {
returns() implies (this@case_5)
}
if (!this@case_5)
throw Exception()
return {}
}
@@ -0,0 +1,36 @@
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
/*
* KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE)
*
* SECTIONS: contracts, declarations, contractFunction
* NUMBER: 1
* DESCRIPTION: Use a contract function before the declaration it.
*/
import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1_1(x: Any?) {
if (case_1_2(x)) {
x.length
}
}
// TESTCASE NUMBER: 2
fun case_2_1(x: Number?) {
case_2_2(x)
println(x.toByte())
}
// TESTCASE NUMBER: 1
fun case_1_2(x: Any?): Boolean {
contract { returns(true) implies (x is String) }
return x is String
}
// TESTCASE NUMBER: 2
fun case_2_2(x: Any?) {
contract { returns() implies(x != null) }
if (x == null) throw Exception()
}