forked from swiftlang/swift
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodableBacktrace.swift
67 lines (50 loc) · 1.4 KB
/
CodableBacktrace.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
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -target %target-cpu-macos15.0 -Xfrontend -parse-as-library -Onone -o %t/CodableBacktrace
// RUN: %target-codesign %t/CodableBacktrace
// RUN: %target-run %t/CodableBacktrace | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: backtracing
// REQUIRES: OS=macosx
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
import Runtime
import Foundation
func level1(){
level2()
}
func level2(){
level3()
}
func level3(){
level4()
}
func level4(){
level5()
}
func level5(){
letbacktrace=try!Backtrace.capture()
letencoder=JSONEncoder()
encoder.outputFormatting =[.prettyPrinted,.sortedKeys,.withoutEscapingSlashes]
letdata=try! encoder.encode(backtrace)
letjson=String(data: data, encoding:.utf8)!
print(json)
// CHECK: {
// CHECK: "architecture" : "{{.*}}",
// CHECK: "backtrace" : "{{[A-Za-z0-9+/]*}}"
// CHECK: }
letdecoder=JSONDecoder()
letbt2=try! decoder.decode(Backtrace.self, from: data)
print(bt2)
// CHECK: 0{{[ \t]+}}0x{{[0-9a-f]+}} [ra]
// CHECK-NEXT: 1{{[ \t]+}}0x{{[0-9a-f]+}} [ra]
// CHECK-NEXT: 2{{[ \t]+}}0x{{[0-9a-f]+}} [ra]
// CHECK-NEXT: 3{{[ \t]+}}0x{{[0-9a-f]+}} [ra]
// CHECK-NEXT: 4{{[ \t]+}}0x{{[0-9a-f]+}} [ra]
// CHECK-NEXT: 5{{[ \t]+}}0x{{[0-9a-f]+}} [ra]
}
@main
structCodableBacktrace{
staticfunc main(){
level1()
}
}