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

This commit is contained in:
Roberto Rosmaninho
2022-10-18 18:53:30 -03:00
parent 0f8b42a7f6
commit 5af07a470c
3 changed files with 88 additions and 6 deletions

View File

@@ -1,8 +1,8 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/swift-functions-errors.swift -typecheck -module-name Functions -clang-header-expose-decls=all-public -emit-clang-header-path %t/functions.h
// 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
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-functions-errors-execution.o
// RUN: %target-interop-build-clangxx -std=c++17 -x objective-c++ -c %s -I %t -o %t/swift-functions-errors-execution.o
// 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
// RUN: %target-codesign %t/swift-functions-errors-execution
@@ -27,7 +27,11 @@ int main() {
try {
Functions::throwFunction();
} catch (swift::Error& e) {
printf("Exception\n");
auto errorVal = e.as<Functions::NaiveErrors, Functions::_impl::_impl_NaiveErrors>();
if (errorVal) {
assert(errorVal == Functions::NaiveErrors::throwError);
errorVal->getMessage();
}
}
try {
Functions::throwFunctionWithReturn();
@@ -43,7 +47,7 @@ int main() {
// CHECK: passEmptyThrowFunction
// CHECK-NEXT: passThrowFunction
// CHECK-NEXT: Exception
// CHECK-NEXT: throwError
// CHECK-NEXT: passThrowFunctionWithReturn
// CHECK-NEXT: Exception
// CHECK-NEXT: Test destroyed