Skip to content

Commit b42f45c

Browse files
[Interop][SwiftToCxx] Modifying tests to verify the that the dynamic cast error returns a Swift::Optional
1 parent f652c8e commit b42f45c

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

test/Interop/SwiftToCxx/functions/swift-functions-errors-execution.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend %S/swift-functions-errors.swift -typecheck -module-name Functions -clang-header-expose-decls=has-expose-attr -emit-clang-header-path %t/functions.h
3+
// RUN: %target-swift-frontend %S/swift-functions-errors.swift -typecheck -module-name Functions -enable-experimental-cxx-interop -emit-clang-header-path %t/functions.h
44

55
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-functions-errors-execution.o
66
// RUN: %target-interop-build-swift %S/swift-functions-errors.swift -o %t/swift-functions-errors-execution -Xlinker %t/swift-functions-errors-execution.o -module-name Functions -Xfrontend -entry-point-function-name -Xfrontend swiftMain
@@ -25,24 +25,27 @@ int main() {
2525

2626
try {
2727
Functions::emptyThrowFunction();
28-
} catch (swift::Error& e) {
28+
} catch (Swift::Error& e) {
2929
printf("Exception\n");
3030
}
3131
try {
3232
Functions::throwFunction();
33-
} catch (swift::Error& e) {
34-
auto errorVal = e.as<Functions::NaiveErrors>();
33+
} catch (Swift::Error& e) {
34+
auto errorOpt = e.as<Functions::NaiveErrors>();
35+
assert(errorOpt.isSome());
36+
37+
auto errorVal = errorOpt.get();
3538
assert(errorVal == Functions::NaiveErrors::throwError);
3639
errorVal.getMessage();
3740
}
3841
try {
3942
Functions::throwFunctionWithReturn();
40-
} catch (swift::Error& e) {
43+
} catch (Swift::Error& e) {
4144
printf("Exception\n");
4245
}
4346
try {
4447
Functions::testDestroyedError();
45-
} catch(const swift::Error &e) { }
48+
} catch(const Swift::Error &e) { }
4649

4750
return 0;
4851
}

test/Interop/SwiftToCxx/functions/swift-functions-errors.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -clang-header-expose-decls=has-expose-attr -emit-clang-header-path %t/functions.h
2+
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -enable-experimental-cxx-interop -emit-clang-header-path %t/functions.h
33
// RUN: %FileCheck %s < %t/functions.h
44

5-
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)
5+
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h -Wno-shadow -Wno-unused-function)
66

77
// CHECK-LABEL: namespace Functions __attribute__((swift_private)) {
88

@@ -31,7 +31,7 @@ public func emptyThrowFunction() throws { print("passEmptyThrowFunction") }
3131
// CHECK: void* _ctx = nullptr;
3232
// CHECK: _impl::$s9Functions18emptyThrowFunctionyyKF(_ctx, &opaqueError);
3333
// CHECK: if (opaqueError != nullptr)
34-
// CHECK: throw (swift::Error(opaqueError))
34+
// CHECK: throw (Swift::Error(opaqueError))
3535
// CHECK: }
3636

3737
class TestDestroyed {
@@ -53,7 +53,7 @@ public func testDestroyedError() throws { throw DestroyedError() }
5353
// CHECK: void* _ctx = nullptr;
5454
// CHECK: _impl::$s9Functions18testDestroyedErroryyKF(_ctx, &opaqueError);
5555
// CHECK: if (opaqueError != nullptr)
56-
// CHECK: throw (swift::Error(opaqueError))
56+
// CHECK: throw (Swift::Error(opaqueError))
5757
// CHECK: }
5858

5959
@_expose(Cxx)
@@ -67,7 +67,7 @@ public func throwFunction() throws {
6767
// CHECK: void* _ctx = nullptr;
6868
// CHECK: _impl::$s9Functions13throwFunctionyyKF(_ctx, &opaqueError);
6969
// CHECK: if (opaqueError != nullptr)
70-
// CHECK: throw (swift::Error(opaqueError))
70+
// CHECK: throw (Swift::Error(opaqueError))
7171
// CHECK: }
7272

7373
@_expose(Cxx)
@@ -82,6 +82,6 @@ public func throwFunctionWithReturn() throws -> Int {
8282
// CHECK: void* _ctx = nullptr;
8383
// CHECK: auto returnValue = _impl::$s9Functions23throwFunctionWithReturnSiyKF(_ctx, &opaqueError);
8484
// CHECK: if (opaqueError != nullptr)
85-
// CHECK: throw (swift::Error(opaqueError))
85+
// CHECK: throw (Swift::Error(opaqueError))
8686
// CHECK: return returnValue;
8787
// CHECK: }

0 commit comments

Comments
 (0)