Skip to content

Commands/Utilities: remove GenerateLinuxMain #6490

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 1 commit into from
Apr 29, 2023
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
1 change: 0 additions & 1 deletion Sources/Commands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ add_library(Commands
Utilities/DependenciesSerializer.swift
Utilities/DescribedPackage.swift
Utilities/DOTManifestSerializer.swift
Utilities/GenerateLinuxMain.swift
Utilities/MultiRootSupport.swift
Utilities/PluginDelegate.swift
Utilities/SymbolGraphExtract.swift
Expand Down
63 changes: 0 additions & 63 deletions Sources/Commands/SwiftTestTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ struct TestToolOptions: ParsableArguments {
help: "Lists test methods in specifier format")
var _deprecated_shouldListTests: Bool = false

/// Generate LinuxMain entries and exit.
@Flag(name: .customLong("generate-linuxmain"), help: .hidden)
var _deprecated_shouldGenerateLinuxMain: Bool = false

/// If the path of the exported code coverage JSON should be printed.
@Flag(name: [.customLong("show-codecov-path"), .customLong("show-code-coverage-path"), .customLong("show-coverage-path")],
help: "Print the path of the exported code coverage JSON file")
Expand Down Expand Up @@ -146,7 +142,6 @@ public struct SwiftTestTool: SwiftCommand {
version: SwiftVersion.current.completeDisplayString,
subcommands: [
List.self,
GenerateLinuxMain.self
],
helpNames: [.short, .long, .customLong("help", withSingleDash: true)])

Expand Down Expand Up @@ -181,10 +176,6 @@ public struct SwiftTestTool: SwiftCommand {
// backward compatibility 6/2022 for deprecation of flag into a subcommand
let command = try List.parse()
try command.run(swiftTool)
} else if self.options._deprecated_shouldGenerateLinuxMain {
// backward compatibility 6/2022 for deprecation of flag into a subcommand
let command = try GenerateLinuxMain.parse()
try command.run(swiftTool)
} else if !self.options.shouldRunInParallel {
let toolchain = try swiftTool.getDestinationToolchain()
let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool)
Expand Down Expand Up @@ -435,10 +426,6 @@ public struct SwiftTestTool: SwiftCommand {
}
}

if options._deprecated_shouldGenerateLinuxMain {
observabilityScope.emit(warning: "'--generate-linuxmain' option is deprecated; tests are automatically discovered on all platforms")
}

if options._deprecated_shouldListTests {
observabilityScope.emit(warning: "'--list-tests' option is deprecated; use 'swift test list' instead")
}
Expand Down Expand Up @@ -540,56 +527,6 @@ extension SwiftTestTool {
}
}

extension SwiftTestTool {
// this functionality is deprecated as of 12/2020
// but we are keeping it here for transition purposes
// to be removed in future releases
// deprecation warning is emitted by validateArguments
struct GenerateLinuxMain: SwiftCommand {
static let configuration = CommandConfiguration(
commandName: "generate-linuxmain",
abstract: "Generate LinuxMain.swift (deprecated)"
)

@OptionGroup(visibility: .hidden)
var globalOptions: GlobalOptions

// for deprecated passthrough from SwiftTestTool (parse will fail otherwise)
@Flag(name: .customLong("generate-linuxmain"), help: .hidden)
var _deprecated_passthrough: Bool = false

func run(_ swiftTool: SwiftTool) throws {
#if os(Linux)
swiftTool.observabilityScope.emit(warning: "can't discover tests on Linux; please use this option on macOS instead")
#endif
let graph = try swiftTool.loadPackageGraph()
let testProducts = try buildTests(swiftTool: swiftTool)
let testSuites = try TestingSupport.getTestSuites(
in: testProducts,
swiftTool: swiftTool,
enableCodeCoverage: false,
sanitizers: globalOptions.build.sanitizers
)
let allTestSuites = testSuites.values.flatMap { $0 }
let generator = LinuxMainGenerator(graph: graph, testSuites: allTestSuites)
try generator.generate()
}

private func buildTests(swiftTool: SwiftTool) throws -> [BuiltTestProduct] {
let buildParameters = try swiftTool.buildParametersForTest(enableCodeCoverage: false)
let buildSystem = try swiftTool.createBuildSystem(customBuildParameters: buildParameters)

try buildSystem.build(subset: .allIncludingTests)

guard !buildSystem.builtTestProducts.isEmpty else {
throw TestError.testsExecutableNotFound
}

return buildSystem.builtTestProducts
}
}
}

/// A structure representing an individual unit test.
struct UnitTest {
/// The path to the test product containing the test.
Expand Down
219 changes: 0 additions & 219 deletions Sources/Commands/Utilities/GenerateLinuxMain.swift

This file was deleted.

57 changes: 0 additions & 57 deletions Tests/CommandsTests/TestToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,63 +209,6 @@ final class TestToolTests: CommandsTestCase {
#endif
}

func testGenerateLinuxMainDeprecation() throws {
try fixture(name: "Miscellaneous/TestDiscovery/Simple") { fixturePath in
let (_, stderr) = try SwiftPMProduct.SwiftTest.execute(["--generate-linuxmain"], packagePath: fixturePath)
// test deprecation warning
XCTAssertMatch(stderr, .contains("warning: '--generate-linuxmain' option is deprecated"))
}
}

func testGenerateLinuxMain() throws {
#if !os(macOS)
try XCTSkipIf(true, "test is only supported on macOS")
#endif
try fixture(name: "Miscellaneous/TestDiscovery/Simple") { fixturePath in
_ = try SwiftPMProduct.SwiftTest.execute(["--generate-linuxmain"], packagePath: fixturePath)

// Check LinuxMain
let linuxMain = fixturePath.appending(components: "Tests", "LinuxMain.swift")
XCTAssertEqual(try localFileSystem.readFileContents(linuxMain), """
import XCTest

import SimpleTests

var tests = [XCTestCaseEntry]()
tests += SimpleTests.__allTests()

XCTMain(tests)

""")

// Check test manifest
let testManifest = fixturePath.appending(components: "Tests", "SimpleTests", "XCTestManifests.swift")
XCTAssertEqual(try localFileSystem.readFileContents(testManifest), """
#if !canImport(ObjectiveC)
import XCTest

extension SimpleTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__SimpleTests = [
("test_Example2", test_Example2),
("testExample1", testExample1),
("testThrowing", testThrowing),
]
}

public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(SimpleTests.__allTests__SimpleTests),
]
}
#endif

""")
}
}

func testList() throws {
try fixture(name: "Miscellaneous/TestDiscovery/Simple") { fixturePath in
let (stdout, stderr) = try SwiftPMProduct.SwiftTest.execute(["list"], packagePath: fixturePath)
Expand Down