Skip to content

Rewrite part of file with StdlibUnittest #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,17 @@ struct _ParentProcess {

internal var _runTestsInProcess: Bool
internal var _filter: String?
internal var _args: [String]

init(runTestsInProcess: Bool, filter: String?) {
init(runTestsInProcess: Bool, args: [String], filter: String?) {
self._runTestsInProcess = runTestsInProcess
self._filter = filter
self._args = args
}

mutating func _spawnChild() {
let (pid, childStdinFD, childStdoutFD, childStderrFD) =
spawnChild([ "--stdlib-unittest-run-child" ])
let params = [ "--stdlib-unittest-run-child" ] + _args
let (pid, childStdinFD, childStdoutFD, childStderrFD) = spawnChild(params)
_pid = pid
_childStdin = _FDOutputStream(fd: childStdinFD)
_childStdout = _FDInputStream(fd: childStdoutFD)
Expand Down Expand Up @@ -782,6 +784,7 @@ public func runAllTests() {
} else {
var runTestsInProcess: Bool = false
var filter: String? = nil
var args = [String]()
var i = 0
while i < Process.arguments.count {
let arg = Process.arguments[i]
Expand All @@ -807,13 +810,15 @@ public func runAllTests() {
print(message)
return
}

// pass through arguments to the child process
args.append(Process.arguments[i])

// FIXME: skipping unrecognized parameters.
i += 1
}

var parent = _ParentProcess(
runTestsInProcess: runTestsInProcess, filter: filter)
runTestsInProcess: runTestsInProcess, args: args, filter: filter)
parent.run()
}
}
Expand Down
157 changes: 157 additions & 0 deletions test/1_stdlib/Inputs/PrintTestTypes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
public protocol ProtocolUnrelatedToPrinting {}

public struct StructPrintable : CustomStringConvertible,
ProtocolUnrelatedToPrinting {

let x: Int

public init(_ x: Int) {
self.x = x
}

public var description: String {
return "►\(x)◀︎"
}
}

public struct LargeStructPrintable : CustomStringConvertible,
ProtocolUnrelatedToPrinting {

let a: Int
let b: Int
let c: Int
let d: Int

public init(_ a: Int, _ b: Int, _ c: Int, _ d: Int) {
self.a = a
self.b = b
self.c = c
self.d = d
}

public var description: String {
return "<\(a) \(b) \(c) \(d)>"
}
}

public struct StructDebugPrintable : CustomDebugStringConvertible {
let x: Int

public init(_ x: Int) {
self.x = x
}

public var debugDescription: String {
return "►\(x)◀︎"
}
}

public struct StructVeryPrintable : CustomStringConvertible,
CustomDebugStringConvertible, ProtocolUnrelatedToPrinting {

let x: Int

public init(_ x: Int) {
self.x = x
}

public var description: String {
return "<description: \(x)>"
}

public var debugDescription: String {
return "<debugDescription: \(x)>"
}
}

public struct EmptyStructWithoutDescription {
public init() {}
}

public struct WithoutDescription {
let x: Int

public init(_ x: Int) {
self.x = x
}
}

public struct ValuesWithoutDescription<T, U, V> {
let t: T
let u: U
let v: V

public init(_ t: T, _ u: U, _ v: V) {
self.t = t
self.u = u
self.v = v
}
}


public class ClassPrintable : CustomStringConvertible,
ProtocolUnrelatedToPrinting {

let x: Int

public init(_ x: Int) {
self.x = x
}

public var description: String {
return "►\(x)◀︎"
}
}

public class ClassVeryPrintable : CustomStringConvertible,
CustomDebugStringConvertible, ProtocolUnrelatedToPrinting {

let x: Int

public init(_ x: Int) {
self.x = x
}

public var description: String {
return "<description: \(x)>"
}

public var debugDescription: String {
return "<debugDescription: \(x)>"
}
}

public struct MyString : StringLiteralConvertible,
StringInterpolationConvertible {

public init(str: String) {
value = str
}

public var value: String

public init(unicodeScalarLiteral value: String) {
self.init(str: value)
}

public init(extendedGraphemeClusterLiteral value: String) {
self.init(str: value)
}

public init(stringLiteral value: String) {
self.init(str: value)
}

public init(stringInterpolation strings: MyString...) {
var result = ""
for s in strings {
result += s.value
}
self.init(str: result)
}

public init<T>(stringInterpolationSegment expr: T) {
self.init(str: "<segment " + String(expr) + ">")
}
}

Loading