|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2024 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See http://swift.org/LICENSE.txt for license information |
| 9 | +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import Testing |
| 14 | + |
| 15 | +import SWBBuildSystem |
| 16 | +import SWBCore |
| 17 | +import SWBTestSupport |
| 18 | +import SWBTaskExecution |
| 19 | +import SWBUtil |
| 20 | + |
| 21 | +@Suite |
| 22 | +fileprivate struct CustomTaskBuildOperationTests: CoreBasedTests { |
| 23 | + |
| 24 | + @Test(.requireSDKs(.host)) |
| 25 | + func outputParsing() async throws { |
| 26 | + try await withTemporaryDirectory { tmpDir in |
| 27 | + let testProject = TestProject( |
| 28 | + "aProject", |
| 29 | + sourceRoot: tmpDir, |
| 30 | + groupTree: TestGroup( |
| 31 | + "SomeFiles", path: "Sources", |
| 32 | + children: [ |
| 33 | + TestFile("tool.swift"), |
| 34 | + TestFile("foo.c"), |
| 35 | + ]), |
| 36 | + buildConfigurations: [ |
| 37 | + TestBuildConfiguration( |
| 38 | + "Debug", |
| 39 | + buildSettings: [ |
| 40 | + "GENERATE_INFOPLIST_FILE": "YES", |
| 41 | + "PRODUCT_NAME": "$(TARGET_NAME)", |
| 42 | + "SWIFT_VERSION": try await swiftVersion, |
| 43 | + "SDKROOT": "auto", |
| 44 | + "CODE_SIGNING_ALLOWED": "NO", |
| 45 | + "MACOSX_DEPLOYMENT_TARGET": "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)" |
| 46 | + ]), |
| 47 | + ], |
| 48 | + targets: [ |
| 49 | + TestStandardTarget( |
| 50 | + "CoreFoo", type: .dynamicLibrary, |
| 51 | + buildPhases: [ |
| 52 | + TestSourcesBuildPhase(["foo.c"]) |
| 53 | + ], |
| 54 | + customTasks: [ |
| 55 | + TestCustomTask( |
| 56 | + commandLine: ["$(BUILD_DIR)/$(CONFIGURATION)/tool"], |
| 57 | + environment: [:], |
| 58 | + workingDirectory: tmpDir.str, |
| 59 | + executionDescription: "My Custom Task", |
| 60 | + inputs: ["$(BUILD_DIR)/$(CONFIGURATION)/tool"], |
| 61 | + outputs: [Path.root.join("output").str], |
| 62 | + enableSandboxing: false, |
| 63 | + preparesForIndexing: false) |
| 64 | + ], |
| 65 | + dependencies: ["tool"] |
| 66 | + ), |
| 67 | + TestStandardTarget( |
| 68 | + "tool", type: .hostBuildTool, |
| 69 | + buildPhases: [ |
| 70 | + TestSourcesBuildPhase(["tool.swift"]) |
| 71 | + ] |
| 72 | + ), |
| 73 | + ]) |
| 74 | + let core = try await getCore() |
| 75 | + let tester = try await BuildOperationTester(core, testProject, simulated: false) |
| 76 | + |
| 77 | + let parameters = BuildParameters(action: .build, configuration: "Debug") |
| 78 | + |
| 79 | + try await tester.fs.writeFileContents(tmpDir.join("Sources").join("tool.swift")) { stream in |
| 80 | + stream <<< |
| 81 | + """ |
| 82 | + @main |
| 83 | + struct Entry { |
| 84 | + static func main() { |
| 85 | + print("warning: this is a warning") |
| 86 | + } |
| 87 | + } |
| 88 | + """ |
| 89 | + } |
| 90 | + |
| 91 | + try await tester.fs.writeFileContents(tmpDir.join("Sources").join("foo.c")) { stream in |
| 92 | + stream <<< |
| 93 | + """ |
| 94 | + void foo(void) {} |
| 95 | + """ |
| 96 | + } |
| 97 | + |
| 98 | + try await tester.checkBuild(parameters: parameters) { results in |
| 99 | + results.checkWarning(.contains("this is a warning")) |
| 100 | + results.checkNoDiagnostics() |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +} |
0 commit comments