Skip to content

swift test should warn when --filter excludes all tests (_à la_ XCTest.) #128

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

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 21 additions & 2 deletions Sources/Testing/Running/EntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,13 @@ func configurationForSwiftPMEntryPoint(withArguments args: [String]) throws -> C
/// - Parameters:
/// - configuration: The configuration to use for running.
func runTests(configuration: Configuration) async {
let eventRecorder = Event.ConsoleOutputRecorder(options: .forStandardError) { string in
let writeOptions: [Event.ConsoleOutputRecorder.Option] = .forStandardError
@Sendable func write(_ string: String) {
let stderr = swt_stderr()
fputs(string, stderr)
fflush(stderr)
}
let eventRecorder = Event.ConsoleOutputRecorder(options: writeOptions, writingUsing: write)

var configuration = configuration
let oldEventHandler = configuration.eventHandler
Expand All @@ -222,7 +224,24 @@ func runTests(configuration: Configuration) async {
}

let runner = await Runner(configuration: configuration)
await runner.run()

// If there are no steps to run, the plan is empty and we should report that
// instead of trying to run nothing. An empty plan can be produced either if
// there are no tests in the current process or if `configuration.testFilter`
// excludes all tests.
let isPlanEmpty = runner.plan.steps.lazy
.map(\.action)
.filter { action in
if case .run = action {
return true
}
return false
}.isEmpty
if isPlanEmpty {
write(warning("No matching tests were run.", options: writeOptions))
} else {
await runner.run()
}
}

// MARK: - Command-line interface options
Expand Down