-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathcoverage_errors_exec.swift
128 lines (106 loc) · 5.77 KB
/
coverage_errors_exec.swift
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
117
118
119
120
121
122
123
124
125
126
127
128
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -profile-generate -profile-coverage-mapping -o %t/main
// This unusual use of 'sh' allows the path of the profraw file to be
// substituted by %target-run.
// RUN: %target-codesign %t/main
// RUN: %target-run sh -c 'env LLVM_PROFILE_FILE=$1 $2' -- %t/default.profraw %t/main
// RUN: %llvm-profdata merge %t/default.profraw -o %t/default.profdata
// RUN: %llvm-cov show %t/main -instr-profile=%t/default.profdata | %FileCheck %s
// REQUIRES: profile_runtime
// REQUIRES: executable_test
// REQUIRES: OS=macosx
struct Err: Error {}
struct S {
static subscript() -> Int {
get throws { throw Err() }
}
func throwingMethod() throws -> Int { throw Err() }
}
func noThrowingFn() throws -> Int { 0 }
func throwingFn() throws -> Int { throw Err() }
var throwingProp: Int {
get throws { throw Err() }
}
var throwingS: S {
get throws { throw Err() }
}
var noThrowingS: S {
get throws { S() }
}
func test1() -> Int { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
do { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
let x = try throwingFn() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return x // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} catch { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return 0 // CHECK: {{ *}}[[@LINE]]|{{ *}}1
} // CHECK: {{ *}}[[@LINE]]|{{ *}}1
} // CHECK: {{ *}}[[@LINE]]|{{ *}}0
_ = test1() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
func test2() throws -> Int { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
let x = try throwingFn() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return x // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} // CHECK: {{ *}}[[@LINE]]|{{ *}}1
_ = try? test2() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
func test3() throws -> Int { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
let x = try throwingProp // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return x // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} // CHECK: {{ *}}[[@LINE]]|{{ *}}1
_ = try? test3() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
func test4() throws -> Int { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
let x = try S[] // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return x // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} // CHECK: {{ *}}[[@LINE]]|{{ *}}1
_ = try? test4() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
// Note we don't emit a region after the call since it would be empty.
func test5() -> Int { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
do { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return try throwingFn() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
} catch { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return 0 // CHECK: {{ *}}[[@LINE]]|{{ *}}1
} // CHECK: {{ *}}[[@LINE]]|{{ *}}1
} // CHECK: {{ *}}[[@LINE]]|{{ *}}0
_ = test5() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
func takesInts(_ x: Int, _ y: Int) {} // CHECK: {{ *}}[[@LINE]]|{{ *}}0
// The throwing expr is nested here, the region starts after the throwing expr.
func test6() throws { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
takesInts(try throwingFn(), 0) // CHECK: {{ *}}[[@LINE]]|{{ *}}1
} // CHECK: {{ *}}[[@LINE]]|{{ *}}0
try? test6() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
func test7() throws { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
takesInts( // CHECK: {{ *}}[[@LINE]]|{{ *}}1
try throwingFn(), // CHECK: {{ *}}[[@LINE]]|{{ *}}1
0 // CHECK: {{ *}}[[@LINE]]|{{ *}}0
) // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} // CHECK: {{ *}}[[@LINE]]|{{ *}}0
try? test7() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
func test8() throws -> Int { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
let x = try throwingS.throwingMethod() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return x // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} // CHECK: {{ *}}[[@LINE]]|{{ *}}1
_ = try? test8()
func test9() throws -> Int { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
let x = try noThrowingS.throwingMethod() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return x // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} // CHECK: {{ *}}[[@LINE]]|{{ *}}1
_ = try? test9() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
func test10() throws { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
takesInts( // CHECK: {{ *}}[[@LINE]]|{{ *}}1
try throwingFn(), // CHECK: {{ *}}[[@LINE]]|{{ *}}1
try throwingFn() // CHECK: {{ *}}[[@LINE]]|{{ *}}0
) // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} // CHECK: {{ *}}[[@LINE]]|{{ *}}0
try? test10() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
func test11() throws { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
takesInts( // CHECK: {{ *}}[[@LINE]]|{{ *}}1
try noThrowingFn(), // CHECK: {{ *}}[[@LINE]]|{{ *}}1
try throwingFn() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
) // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} // CHECK: {{ *}}[[@LINE]]|{{ *}}0
try? test11() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
func test21() throws -> Int { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
try { // CHECK: {{ *}}[[@LINE]]|{{ *}}1
throw Err() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
}() // CHECK: {{ *}}[[@LINE]]|{{ *}}1
return 1 // CHECK: {{ *}}[[@LINE]]|{{ *}}0
} // CHECK: {{ *}}[[@LINE]]|{{ *}}1
_ = try? test21() // CHECK: {{ *}}[[@LINE]]|{{ *}}1