|
1 | 1 | /*
|
2 | 2 | This source file is part of the Swift.org open source project
|
3 | 3 |
|
4 |
| -Copyright 2015 - 2016 Apple Inc. and the Swift project authors |
| 4 | +Copyright 2015 - 2022 Apple Inc. and the Swift project authors |
5 | 5 | Licensed under Apache License v2.0 with Runtime Library Exception
|
6 | 6 |
|
7 | 7 | See http://swift.org/LICENSE.txt for license information
|
@@ -209,7 +209,7 @@ public struct SwiftTestTool: SwiftCommand {
|
209 | 209 | switch options.mode {
|
210 | 210 | case .listTests:
|
211 | 211 | let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool)
|
212 |
| - let testSuites = try getTestSuites(in: testProducts, swiftTool: swiftTool) |
| 212 | + let testSuites = try getTestSuites(in: testProducts, swiftTool: swiftTool, swiftOptions: swiftOptions) |
213 | 213 | let tests = try testSuites
|
214 | 214 | .filteredTests(specifier: options.testCaseSpecifier)
|
215 | 215 | .skippedTests(specifier: options.testCaseSkip)
|
@@ -245,7 +245,7 @@ public struct SwiftTestTool: SwiftCommand {
|
245 | 245 | #endif
|
246 | 246 | let graph = try swiftTool.loadPackageGraph()
|
247 | 247 | let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool)
|
248 |
| - let testSuites = try getTestSuites(in: testProducts, swiftTool: swiftTool) |
| 248 | + let testSuites = try getTestSuites(in: testProducts, swiftTool: swiftTool, swiftOptions: swiftOptions) |
249 | 249 | let allTestSuites = testSuites.values.flatMap { $0 }
|
250 | 250 | let generator = LinuxMainGenerator(graph: graph, testSuites: allTestSuites)
|
251 | 251 | try generator.generate()
|
@@ -278,7 +278,7 @@ public struct SwiftTestTool: SwiftCommand {
|
278 | 278 | }
|
279 | 279 |
|
280 | 280 | // Find the tests we need to run.
|
281 |
| - let testSuites = try getTestSuites(in: testProducts, swiftTool: swiftTool) |
| 281 | + let testSuites = try getTestSuites(in: testProducts, swiftTool: swiftTool, swiftOptions: swiftOptions) |
282 | 282 | let tests = try testSuites
|
283 | 283 | .filteredTests(specifier: options.testCaseSpecifier)
|
284 | 284 | .skippedTests(specifier: options.testCaseSkip)
|
@@ -317,7 +317,7 @@ public struct SwiftTestTool: SwiftCommand {
|
317 | 317 | case .runParallel:
|
318 | 318 | let toolchain = try swiftTool.getToolchain()
|
319 | 319 | let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool)
|
320 |
| - let testSuites = try getTestSuites(in: testProducts, swiftTool: swiftTool) |
| 320 | + let testSuites = try getTestSuites(in: testProducts, swiftTool: swiftTool, swiftOptions: swiftOptions) |
321 | 321 | let tests = try testSuites
|
322 | 322 | .filteredTests(specifier: options.testCaseSpecifier)
|
323 | 323 | .skippedTests(specifier: options.testCaseSkip)
|
@@ -461,70 +461,6 @@ public struct SwiftTestTool: SwiftCommand {
|
461 | 461 | }
|
462 | 462 | }
|
463 | 463 |
|
464 |
| - /// Locates XCTestHelper tool inside the libexec directory and bin directory. |
465 |
| - /// Note: It is a fatalError if we are not able to locate the tool. |
466 |
| - /// |
467 |
| - /// - Returns: Path to XCTestHelper tool. |
468 |
| - private func xctestHelperPath(swiftTool: SwiftTool) throws -> AbsolutePath { |
469 |
| - let xctestHelperBin = "swiftpm-xctest-helper" |
470 |
| - let binDirectory = AbsolutePath(CommandLine.arguments.first!, |
471 |
| - relativeTo: swiftTool.originalWorkingDirectory).parentDirectory |
472 |
| - // XCTestHelper tool is installed in libexec. |
473 |
| - let maybePath = binDirectory.parentDirectory.appending(components: "libexec", "swift", "pm", xctestHelperBin) |
474 |
| - if localFileSystem.isFile(maybePath) { |
475 |
| - return maybePath |
476 |
| - } |
477 |
| - // This will be true during swiftpm development. |
478 |
| - // FIXME: Factor all of the development-time resource location stuff into a common place. |
479 |
| - let path = binDirectory.appending(component: xctestHelperBin) |
480 |
| - if localFileSystem.isFile(path) { |
481 |
| - return path |
482 |
| - } |
483 |
| - throw InternalError("XCTestHelper binary not found.") |
484 |
| - } |
485 |
| - |
486 |
| - fileprivate func getTestSuites(in testProducts: [BuiltTestProduct], swiftTool: SwiftTool) throws -> [AbsolutePath: [TestSuite]] { |
487 |
| - let testSuitesByProduct = try testProducts |
488 |
| - .map { try ($0.bundlePath, self.getTestSuites(fromTestAt: $0.bundlePath, swiftTool: swiftTool)) } |
489 |
| - return Dictionary(uniqueKeysWithValues: testSuitesByProduct) |
490 |
| - } |
491 |
| - |
492 |
| - /// Runs the corresponding tool to get tests JSON and create TestSuite array. |
493 |
| - /// On macOS, we use the swiftpm-xctest-helper tool bundled with swiftpm. |
494 |
| - /// On Linux, XCTest can dump the json using `--dump-tests-json` mode. |
495 |
| - /// |
496 |
| - /// - Parameters: |
497 |
| - /// - path: Path to the XCTest bundle(macOS) or executable(Linux). |
498 |
| - /// |
499 |
| - /// - Throws: TestError, SystemError, TSCUtility.Error |
500 |
| - /// |
501 |
| - /// - Returns: Array of TestSuite |
502 |
| - fileprivate func getTestSuites(fromTestAt path: AbsolutePath, swiftTool: SwiftTool) throws -> [TestSuite] { |
503 |
| - // Run the correct tool. |
504 |
| - #if os(macOS) |
505 |
| - let data: String = try withTemporaryFile { tempFile in |
506 |
| - let args = [try xctestHelperPath(swiftTool: swiftTool).pathString, path.pathString, tempFile.path.pathString] |
507 |
| - var env = try constructTestEnvironment(toolchain: try swiftTool.getToolchain(), options: swiftOptions, buildParameters: swiftTool.buildParametersForTest()) |
508 |
| - // Add the sdk platform path if we have it. If this is not present, we |
509 |
| - // might always end up failing. |
510 |
| - if let sdkPlatformFrameworksPath = Destination.sdkPlatformFrameworkPaths() { |
511 |
| - // appending since we prefer the user setting (if set) to the one we inject |
512 |
| - env.appendPath("DYLD_FRAMEWORK_PATH", value: sdkPlatformFrameworksPath.fwk.pathString) |
513 |
| - env.appendPath("DYLD_LIBRARY_PATH", value: sdkPlatformFrameworksPath.lib.pathString) |
514 |
| - } |
515 |
| - try Process.checkNonZeroExit(arguments: args, environment: env) |
516 |
| - // Read the temporary file's content. |
517 |
| - return try localFileSystem.readFileContents(tempFile.path).validDescription ?? "" |
518 |
| - } |
519 |
| - #else |
520 |
| - let env = try constructTestEnvironment(toolchain: try swiftTool.getToolchain(), options: swiftOptions, buildParameters: swiftTool.buildParametersForTest()) |
521 |
| - let args = [path.description, "--dump-tests-json"] |
522 |
| - let data = try Process.checkNonZeroExit(arguments: args, environment: env) |
523 |
| - #endif |
524 |
| - // Parse json and return TestSuites. |
525 |
| - return try TestSuite.parse(jsonString: data) |
526 |
| - } |
527 |
| - |
528 | 464 | /// Private function that validates the commands arguments
|
529 | 465 | ///
|
530 | 466 | /// - Throws: if a command argument is invalid
|
@@ -1022,54 +958,6 @@ fileprivate extension Array where Element == UnitTest {
|
1022 | 958 | }
|
1023 | 959 | }
|
1024 | 960 |
|
1025 |
| -/// Creates the environment needed to test related tools. |
1026 |
| -fileprivate func constructTestEnvironment( |
1027 |
| - toolchain: UserToolchain, |
1028 |
| - options: SwiftToolOptions, |
1029 |
| - buildParameters: BuildParameters |
1030 |
| -) throws -> EnvironmentVariables { |
1031 |
| - var env = EnvironmentVariables.process() |
1032 |
| - |
1033 |
| - // Add the code coverage related variables. |
1034 |
| - if options.shouldEnableCodeCoverage { |
1035 |
| - // Defines the path at which the profraw files will be written on test execution. |
1036 |
| - // |
1037 |
| - // `%m` will create a pool of profraw files and append the data from |
1038 |
| - // each execution in one of the files. This doesn't matter for serial |
1039 |
| - // execution but is required when the tests are running in parallel as |
1040 |
| - // SwiftPM repeatedly invokes the test binary with the test case name as |
1041 |
| - // the filter. |
1042 |
| - let codecovProfile = buildParameters.buildPath.appending(components: "codecov", "default%m.profraw") |
1043 |
| - env["LLVM_PROFILE_FILE"] = codecovProfile.pathString |
1044 |
| - } |
1045 |
| - #if !os(macOS) |
1046 |
| - #if os(Windows) |
1047 |
| - if let location = toolchain.configuration.xctestPath { |
1048 |
| - env.prependPath("Path", value: location.pathString) |
1049 |
| - } |
1050 |
| - #endif |
1051 |
| - return env |
1052 |
| - #else |
1053 |
| - // Fast path when no sanitizers are enabled. |
1054 |
| - if options.sanitizers.isEmpty { |
1055 |
| - return env |
1056 |
| - } |
1057 |
| - |
1058 |
| - // Get the runtime libraries. |
1059 |
| - var runtimes = try options.sanitizers.map({ sanitizer in |
1060 |
| - return try toolchain.runtimeLibrary(for: sanitizer).pathString |
1061 |
| - }) |
1062 |
| - |
1063 |
| - // Append any existing value to the front. |
1064 |
| - if let existingValue = env["DYLD_INSERT_LIBRARIES"], !existingValue.isEmpty { |
1065 |
| - runtimes.insert(existingValue, at: 0) |
1066 |
| - } |
1067 |
| - |
1068 |
| - env["DYLD_INSERT_LIBRARIES"] = runtimes.joined(separator: ":") |
1069 |
| - return env |
1070 |
| - #endif |
1071 |
| -} |
1072 |
| - |
1073 | 961 | /// xUnit XML file generator for a swift-test run.
|
1074 | 962 | final class XUnitGenerator {
|
1075 | 963 | typealias TestResult = ParallelTestRunner.TestResult
|
@@ -1130,12 +1018,3 @@ private extension Basics.Diagnostic {
|
1130 | 1018 | .warning("No matching test cases were run")
|
1131 | 1019 | }
|
1132 | 1020 | }
|
1133 |
| - |
1134 |
| -private extension SwiftTool { |
1135 |
| - func buildParametersForTest() throws -> BuildParameters { |
1136 |
| - var parameters = try self.buildParameters() |
1137 |
| - // for test commands, alway enable building with testability enabled |
1138 |
| - parameters.enableTestability = true |
1139 |
| - return parameters |
1140 |
| - } |
1141 |
| -} |
0 commit comments