Skip to content

Commit decc7f5

Browse files
committed
Merge pull request #487 from frootloops/tests-print
Rewrite part of file with StdlibUnittest
2 parents e158017 + 9203f36 commit decc7f5

14 files changed

+959
-1034
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,17 @@ struct _ParentProcess {
477477

478478
internal var _runTestsInProcess: Bool
479479
internal var _filter: String?
480+
internal var _args: [String]
480481

481-
init(runTestsInProcess: Bool, filter: String?) {
482+
init(runTestsInProcess: Bool, args: [String], filter: String?) {
482483
self._runTestsInProcess = runTestsInProcess
483484
self._filter = filter
485+
self._args = args
484486
}
485487

486488
mutating func _spawnChild() {
487-
let (pid, childStdinFD, childStdoutFD, childStderrFD) =
488-
spawnChild([ "--stdlib-unittest-run-child" ])
489+
let params = [ "--stdlib-unittest-run-child" ] + _args
490+
let (pid, childStdinFD, childStdoutFD, childStderrFD) = spawnChild(params)
489491
_pid = pid
490492
_childStdin = _FDOutputStream(fd: childStdinFD)
491493
_childStdout = _FDInputStream(fd: childStdoutFD)
@@ -782,6 +784,7 @@ public func runAllTests() {
782784
} else {
783785
var runTestsInProcess: Bool = false
784786
var filter: String? = nil
787+
var args = [String]()
785788
var i = 0
786789
while i < Process.arguments.count {
787790
let arg = Process.arguments[i]
@@ -807,13 +810,15 @@ public func runAllTests() {
807810
print(message)
808811
return
809812
}
813+
814+
// pass through arguments to the child process
815+
args.append(Process.arguments[i])
810816

811-
// FIXME: skipping unrecognized parameters.
812817
i += 1
813818
}
814819

815820
var parent = _ParentProcess(
816-
runTestsInProcess: runTestsInProcess, filter: filter)
821+
runTestsInProcess: runTestsInProcess, args: args, filter: filter)
817822
parent.run()
818823
}
819824
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
public protocol ProtocolUnrelatedToPrinting {}
2+
3+
public struct StructPrintable : CustomStringConvertible,
4+
ProtocolUnrelatedToPrinting {
5+
6+
let x: Int
7+
8+
public init(_ x: Int) {
9+
self.x = x
10+
}
11+
12+
public var description: String {
13+
return "\(x)◀︎"
14+
}
15+
}
16+
17+
public struct LargeStructPrintable : CustomStringConvertible,
18+
ProtocolUnrelatedToPrinting {
19+
20+
let a: Int
21+
let b: Int
22+
let c: Int
23+
let d: Int
24+
25+
public init(_ a: Int, _ b: Int, _ c: Int, _ d: Int) {
26+
self.a = a
27+
self.b = b
28+
self.c = c
29+
self.d = d
30+
}
31+
32+
public var description: String {
33+
return "<\(a) \(b) \(c) \(d)>"
34+
}
35+
}
36+
37+
public struct StructDebugPrintable : CustomDebugStringConvertible {
38+
let x: Int
39+
40+
public init(_ x: Int) {
41+
self.x = x
42+
}
43+
44+
public var debugDescription: String {
45+
return "\(x)◀︎"
46+
}
47+
}
48+
49+
public struct StructVeryPrintable : CustomStringConvertible,
50+
CustomDebugStringConvertible, ProtocolUnrelatedToPrinting {
51+
52+
let x: Int
53+
54+
public init(_ x: Int) {
55+
self.x = x
56+
}
57+
58+
public var description: String {
59+
return "<description: \(x)>"
60+
}
61+
62+
public var debugDescription: String {
63+
return "<debugDescription: \(x)>"
64+
}
65+
}
66+
67+
public struct EmptyStructWithoutDescription {
68+
public init() {}
69+
}
70+
71+
public struct WithoutDescription {
72+
let x: Int
73+
74+
public init(_ x: Int) {
75+
self.x = x
76+
}
77+
}
78+
79+
public struct ValuesWithoutDescription<T, U, V> {
80+
let t: T
81+
let u: U
82+
let v: V
83+
84+
public init(_ t: T, _ u: U, _ v: V) {
85+
self.t = t
86+
self.u = u
87+
self.v = v
88+
}
89+
}
90+
91+
92+
public class ClassPrintable : CustomStringConvertible,
93+
ProtocolUnrelatedToPrinting {
94+
95+
let x: Int
96+
97+
public init(_ x: Int) {
98+
self.x = x
99+
}
100+
101+
public var description: String {
102+
return "\(x)◀︎"
103+
}
104+
}
105+
106+
public class ClassVeryPrintable : CustomStringConvertible,
107+
CustomDebugStringConvertible, ProtocolUnrelatedToPrinting {
108+
109+
let x: Int
110+
111+
public init(_ x: Int) {
112+
self.x = x
113+
}
114+
115+
public var description: String {
116+
return "<description: \(x)>"
117+
}
118+
119+
public var debugDescription: String {
120+
return "<debugDescription: \(x)>"
121+
}
122+
}
123+
124+
public struct MyString : StringLiteralConvertible,
125+
StringInterpolationConvertible {
126+
127+
public init(str: String) {
128+
value = str
129+
}
130+
131+
public var value: String
132+
133+
public init(unicodeScalarLiteral value: String) {
134+
self.init(str: value)
135+
}
136+
137+
public init(extendedGraphemeClusterLiteral value: String) {
138+
self.init(str: value)
139+
}
140+
141+
public init(stringLiteral value: String) {
142+
self.init(str: value)
143+
}
144+
145+
public init(stringInterpolation strings: MyString...) {
146+
var result = ""
147+
for s in strings {
148+
result += s.value
149+
}
150+
self.init(str: result)
151+
}
152+
153+
public init<T>(stringInterpolationSegment expr: T) {
154+
self.init(str: "<segment " + String(expr) + ">")
155+
}
156+
}
157+

0 commit comments

Comments
 (0)