1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import SWBUtil
import SWBCore
import SWBTaskExecution
import ArgumentParser
class TestEntryPointGenerationTaskAction: TaskAction {
override class var toolIdentifier: String {
"TestEntryPointGenerationTaskAction"
}
override func performTaskAction(_ task: any ExecutableTask, dynamicExecutionDelegate: any DynamicTaskExecutionDelegate, executionDelegate: any TaskExecutionDelegate, clientDelegate: any TaskExecutionClientDelegate, outputDelegate: any TaskOutputDelegate) async -> CommandResult {
do {
let options = try Options.parse(Array(task.commandLineAsStrings.dropFirst()))
try executionDelegate.fs.write(options.output, contents: #"""
#if canImport(Testing)
import Testing
#endif
@main
@available(macOS 10.15, iOS 11, watchOS 4, tvOS 11, visionOS 1, *)
@available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings")
struct Runner {
private static func testingLibrary() -> String {
var iterator = CommandLine.arguments.makeIterator()
while let argument = iterator.next() {
if argument == "--testing-library", let libraryName = iterator.next() {
return libraryName.lowercased()
}
}
// Fallback if not specified: run XCTest (legacy behavior)
return "xctest"
}
#if os(Linux)
@_silgen_name("$ss13_runAsyncMainyyyyYaKcF")
private static func _runAsyncMain(_ asyncFun: @Sendable @escaping () async throws -> ())
static func main() {
let testingLibrary = Self.testingLibrary()
#if canImport(Testing)
if testingLibrary == "swift-testing" {
_runAsyncMain {
await Testing.__swiftPMEntryPoint() as Never
}
}
#endif
}
#else
static func main() async {
let testingLibrary = Self.testingLibrary()
#if canImport(Testing)
if testingLibrary == "swift-testing" {
await Testing.__swiftPMEntryPoint() as Never
}
#endif
}
#endif
}
"""#)
return .succeeded
} catch {
outputDelegate.emitError("\(error)")
return .failed
}
}
}
private struct Options: ParsableArguments {
@Option var output: Path
}
|