File: trap-on-exception-execution.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (116 lines) | stat: -rw-r--r-- 3,181 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// RUN: %empty-directory(%t)
// RUN: split-file %S/trap-on-exception-irgen-itanium.swift %t

// RUN: %target-build-swift %s -I %t/Inputs -o %t/trap-exceptions -Xfrontend -enable-experimental-cxx-interop -Xfrontend -validate-tbd-against-ir=none -g
// RUN: %target-codesign %t/trap-exceptions
// RUN: %target-run %t/trap-exceptions

// RUN: %target-build-swift %s -I %t/Inputs -o %t/trap-exceptions-no-debug -Xfrontend -enable-experimental-cxx-interop -Xfrontend -validate-tbd-against-ir=none
// RUN: %target-codesign %t/trap-exceptions-no-debug
// RUN: %target-run %t/trap-exceptions-no-debug

// RUN: %target-build-swift %s -I %t/Inputs -o %t/trap-exceptions-opt -Xfrontend -enable-experimental-cxx-interop -Xfrontend -validate-tbd-against-ir=none -O
// RUN: %target-codesign %t/trap-exceptions-opt
// RUN: %target-run %t/trap-exceptions-opt

// REQUIRES: executable_test

// FIXME: Support MSVC exceptions.
// UNSUPPORTED: OS=windows-msvc

import CxxModule
import StdlibUnittest

func makeCInt() -> CInt {
  return 42
}

var TrapOnExecutionTestSuite = TestSuite("TrapOnExecution")

TrapOnExecutionTestSuite.test("freeFunctionNoThrow") {
  expectEqual(freeFunctionNoThrow(makeCInt()), -42)
}

TrapOnExecutionTestSuite.test("freeFunctionThrows") {
  expectCrashLater()
  let _ = freeFunctionThrows(2)
}

TrapOnExecutionTestSuite.test("freeFunctionThrowsNoException") {
  expectEqual(freeFunctionThrows(-1), 1)
}

TrapOnExecutionTestSuite.test("freeFunctionCatchesException") {
  expectEqual(freeFunctionCatchesException(-1), 1)
  expectEqual(freeFunctionCatchesException(2), 2)
}

TrapOnExecutionTestSuite.test("TestClassMethodThrows") {
  expectCrashLater()
  let v = TestClass()
  v.method(2)
}

TrapOnExecutionTestSuite.test("TestClassNoExceptMethod") {
  var v = TestClass()
  expectEqual(v.noExceptMethod(1), -1)
}

TrapOnExecutionTestSuite.test("TestTemplateIntDependentNoExceptMethod") {
  var v = TestTemplateInt()
  v.dependentNoExceptMethod()
}

TrapOnExecutionTestSuite.test("TestTemplateBoolDependentNoExceptMethod") {
  expectCrashLater()
  var v = TestTemplateBool()
  v.dependentNoExceptMethod()
}

protocol MethodProtocol {
  func method(_ x: CInt) -> CInt
}

extension TestClass: MethodProtocol {
}

TrapOnExecutionTestSuite.test("TestProtocolConformanceThunkInvoke") {
  let v = TestClass()
  let p: MethodProtocol = v
  expectCrashLater()
  let _ = p.method(2)
}

TrapOnExecutionTestSuite.test("TestClassWithSubscript") {
  let v = ClassWithSubscript()
  expectEqual(v[0], 0)
  expectCrashLater()
  let _ = v[1]
}

TrapOnExecutionTestSuite.test("TestClassWithThrowingDestructor") {
  expectCrashLater()
  let _ = ClassWithThrowingDestructor()
}

TrapOnExecutionTestSuite.test("TestClassWithThrowingCopyConstructor") {
  expectCrashLater()
  let p1 = ClassWithThrowingCopyConstructor()
  var p2 = p1
  expectEqual(p2.m, 0)
  p2.m = 1
  expectEqual(p2.m, 1)
  expectEqual(p1.m, 0)
}

TrapOnExecutionTestSuite.test("ClassWithThrowingConstructor") {
  expectCrashLater()
  let _ = ClassWithThrowingConstructor()
}

TrapOnExecutionTestSuite.test("ClassWithNoThrowingConstructor") {
  let obj = ClassWithNoThrowingConstructor()
  expectEqual(obj.m, 0)
}

runAllTests()