From 4b97d8cad60d5dfecc620b38f26b65fee28eb134 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Tue, 4 Feb 2020 16:27:18 +0300 Subject: [PATCH] Add more tests for `@Throws` --- .../tests/framework/values/expectedLazy.h | 1 + backend.native/tests/framework/values/values.kt | 3 +++ backend.native/tests/framework/values/values.swift | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/backend.native/tests/framework/values/expectedLazy.h b/backend.native/tests/framework/values/expectedLazy.h index 3c500bfa927..2fe38a8b6e3 100644 --- a/backend.native/tests/framework/values/expectedLazy.h +++ b/backend.native/tests/framework/values/expectedLazy.h @@ -1102,6 +1102,7 @@ __attribute__((swift_name("ValuesKt"))) + (BOOL)isFrozenObj:(id)obj __attribute__((swift_name("isFrozen(obj:)"))); + (id)kotlinLambdaBlock:(id (^)(id))block __attribute__((swift_name("kotlinLambda(block:)"))); + (int64_t)multiplyInt:(int32_t)int_ long:(int64_t)long_ __attribute__((swift_name("multiply(int:long:)"))); ++ (id _Nullable)callFoo1Bridge:(ValuesBridgeBase *)bridge error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("callFoo1(bridge:)"))); + (id)same:(id)receiver __attribute__((swift_name("same(_:)"))); + (ValuesInt * _Nullable)callBase1:(id)base1 value:(ValuesInt * _Nullable)value __attribute__((swift_name("call(base1:value:)"))); + (ValuesInt * _Nullable)callExtendedBase1:(id)extendedBase1 value:(ValuesInt * _Nullable)value __attribute__((swift_name("call(extendedBase1:value:)"))); diff --git a/backend.native/tests/framework/values/values.kt b/backend.native/tests/framework/values/values.kt index c2c9b1397d8..756237074d4 100644 --- a/backend.native/tests/framework/values/values.kt +++ b/backend.native/tests/framework/values/values.kt @@ -272,6 +272,9 @@ class Bridge : BridgeBase() { override fun foo4() = throw MyException() } +@Throws(NullPointerException::class) +fun callFoo1(bridge: BridgeBase) = bridge.foo1() + fun Any.same() = this // https://github.com/JetBrains/kotlin-native/issues/2571 diff --git a/backend.native/tests/framework/values/values.swift b/backend.native/tests/framework/values/values.swift index c0491d1c6dd..969450649c4 100644 --- a/backend.native/tests/framework/values/values.swift +++ b/backend.native/tests/framework/values/values.swift @@ -275,6 +275,13 @@ func testFunctions() throws { try assertEquals(actual: ValuesKt.multiply(int: 3, long: 2), expected: 6) } +class BridgeSwift : BridgeBase { + class Err : Error {} + + override func foo1() throws -> Any { + throw Err() + } +} func testExceptions() throws { let bridge = Bridge() @@ -300,6 +307,13 @@ func testExceptions() throws { } catch let error as NSError { try assertTrue(error.kotlinException is MyException) } + do { + try ValuesKt.callFoo1(bridge: BridgeSwift()) + } catch let error as BridgeSwift.Err { + // Ok + } catch { + try assertTrue(false) + } } func testFuncType() throws {