Skip to content

Commit 6be3a11

Browse files
committed
Include total count when listing tests
1 parent ea21826 commit 6be3a11

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Documentation/Linux.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ $ ./FooTests Tests.FooTestCase # Run all the tests in FooTestCase
4444

4545
```sh
4646
$ ./FooTests --list-tests
47+
Listing 4 tests in FooTests.xctest:
48+
4749
Tests.FooTestCase/testFoo
4850
Tests.FooTestCase/testBar
4951
Tests.BarTestCase/test123

Sources/XCTest/TestListing.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ internal struct TestListing {
2727
/// Prints a flat list of the tests in the suite, in the format used to
2828
/// specify a test by name when running tests.
2929
func printTestList() {
30+
let list = testSuite.list()
31+
let tests = list.count == 1 ? "test" : "tests"
32+
let bundleName = testSuite.findBundleTestSuite()?.name ?? "<<unknown bundle>>"
33+
34+
print("Listing \(list.count) \(tests) in \(bundleName):\n")
3035
for entry in testSuite.list() {
3136
print(entry)
3237
}
@@ -76,6 +81,14 @@ extension XCTestSuite: Listable {
7681
"tests": listedTests.bridge()
7782
].bridge()
7883
}
84+
85+
func findBundleTestSuite() -> XCTestSuite? {
86+
if name.hasSuffix(".xctest") {
87+
return self
88+
} else {
89+
return tests.flatMap({ ($0 as? XCTestSuite)?.findBundleTestSuite() }).first
90+
}
91+
}
7992
}
8093

8194
extension XCTestCase: Listable {

Tests/Functional/ListTests/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ if Process.arguments.contains("--verify") {
3232
exit(0)
3333
}
3434

35+
// CHECK: Listing 4 tests in .*\.xctest:
36+
// CHECK: ^$
3537

3638
class FirstTestCase: XCTestCase {
3739
static var allTests = {

0 commit comments

Comments
 (0)