Skip to content

Commit e372f7a

Browse files
authored
Add better unit test failure diagnostics for when basic SwiftPM commands fail (#3334)
The motivation here is to find and fix a unit test failure that only seems to happen in CI.
1 parent cdaaf0a commit e372f7a

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

Tests/CommandsTests/BuildToolTests.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -41,15 +41,18 @@ final class BuildToolTests: XCTestCase {
4141
}
4242

4343
func testUsage() throws {
44-
XCTAssert(try execute(["-help"]).stdout.contains("USAGE: swift build"))
44+
let stdout = try execute(["-help"]).stdout
45+
XCTAssert(stdout.contains("USAGE: swift build"), "got stdout:\n" + stdout)
4546
}
4647

4748
func testSeeAlso() throws {
48-
XCTAssert(try execute(["--help"]).stdout.contains("SEE ALSO: swift run, swift package, swift test"))
49+
let stdout = try execute(["--help"]).stdout
50+
XCTAssert(stdout.contains("SEE ALSO: swift run, swift package, swift test"), "got stdout:\n" + stdout)
4951
}
5052

5153
func testVersion() throws {
52-
XCTAssert(try execute(["--version"]).stdout.contains("Swift Package Manager"))
54+
let stdout = try execute(["--version"]).stdout
55+
XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout)
5356
}
5457

5558
func testCreatingSanitizers() throws {

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -34,15 +34,18 @@ final class PackageToolTests: XCTestCase {
3434
}
3535

3636
func testUsage() throws {
37-
XCTAssert(try execute(["--help"]).stdout.contains("USAGE: swift package"))
37+
let stdout = try execute(["-help"]).stdout
38+
XCTAssert(stdout.contains("USAGE: swift package"), "got stdout:\n" + stdout)
3839
}
3940

4041
func testSeeAlso() throws {
41-
XCTAssert(try execute(["--help"]).stdout.contains("SEE ALSO: swift build, swift run, swift test"))
42+
let stdout = try execute(["--help"]).stdout
43+
XCTAssert(stdout.contains("SEE ALSO: swift build, swift run, swift test"), "got stdout:\n" + stdout)
4244
}
4345

4446
func testVersion() throws {
45-
XCTAssert(try execute(["--version"]).stdout.contains("Swift Package Manager"))
47+
let stdout = try execute(["--version"]).stdout
48+
XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout)
4649
}
4750

4851
func testNetrcSupportedOS() throws {

Tests/CommandsTests/RunToolTests.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -23,15 +23,18 @@ final class RunToolTests: XCTestCase {
2323
}
2424

2525
func testUsage() throws {
26-
XCTAssert(try execute(["--help"]).stdout.contains("USAGE: swift run <options>"))
26+
let stdout = try execute(["-help"]).stdout
27+
XCTAssert(stdout.contains("USAGE: swift run <options>"), "got stdout:\n" + stdout)
2728
}
2829

2930
func testSeeAlso() throws {
30-
XCTAssert(try execute(["--help"]).stdout.contains("SEE ALSO: swift build, swift package, swift test"))
31+
let stdout = try execute(["--help"]).stdout
32+
XCTAssert(stdout.contains("SEE ALSO: swift build, swift package, swift test"), "got stdout:\n" + stdout)
3133
}
3234

3335
func testVersion() throws {
34-
XCTAssert(try execute(["--version"]).stdout.contains("Swift Package Manager"))
36+
let stdout = try execute(["--version"]).stdout
37+
XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout)
3538
}
3639

3740
func testUnkownProductAndArgumentPassing() throws {

Tests/CommandsTests/TestToolTests.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -19,15 +19,18 @@ final class TestToolTests: XCTestCase {
1919
}
2020

2121
func testUsage() throws {
22-
XCTAssert(try execute(["--help"]).stdout.contains("USAGE: swift test"))
22+
let stdout = try execute(["-help"]).stdout
23+
XCTAssert(stdout.contains("USAGE: swift test"), "got stdout:\n" + stdout)
2324
}
2425

2526
func testSeeAlso() throws {
26-
XCTAssert(try execute(["--help"]).stdout.contains("SEE ALSO: swift build, swift run, swift package"))
27+
let stdout = try execute(["--help"]).stdout
28+
XCTAssert(stdout.contains("SEE ALSO: swift build, swift run, swift package"), "got stdout:\n" + stdout)
2729
}
2830

2931
func testVersion() throws {
30-
XCTAssert(try execute(["--version"]).stdout.contains("Swift Package Manager"))
32+
let stdout = try execute(["--version"]).stdout
33+
XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout)
3134
}
3235

3336
func testNumWorkersParallelRequeriment() throws {

0 commit comments

Comments
 (0)