forked from swiftlang/swift-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure we parse diagnostics from CustomTasks in PIF (swiftlang#85)
- Loading branch information
Showing
2 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Tests/SWBBuildSystemTests/CustomTaskBuildOperationTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2024 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 Testing | ||
|
||
import SWBBuildSystem | ||
import SWBCore | ||
import SWBTestSupport | ||
import SWBTaskExecution | ||
import SWBUtil | ||
|
||
@Suite | ||
fileprivate struct CustomTaskBuildOperationTests: CoreBasedTests { | ||
|
||
@Test(.requireSDKs(.host)) | ||
func outputParsing() async throws { | ||
try await withTemporaryDirectory { tmpDir in | ||
let testProject = TestProject( | ||
"aProject", | ||
sourceRoot: tmpDir, | ||
groupTree: TestGroup( | ||
"SomeFiles", path: "Sources", | ||
children: [ | ||
TestFile("tool.swift"), | ||
TestFile("foo.c"), | ||
]), | ||
buildConfigurations: [ | ||
TestBuildConfiguration( | ||
"Debug", | ||
buildSettings: [ | ||
"GENERATE_INFOPLIST_FILE": "YES", | ||
"PRODUCT_NAME": "$(TARGET_NAME)", | ||
"SWIFT_VERSION": try await swiftVersion, | ||
"SDKROOT": "auto", | ||
"CODE_SIGNING_ALLOWED": "NO", | ||
"MACOSX_DEPLOYMENT_TARGET": "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)" | ||
]), | ||
], | ||
targets: [ | ||
TestStandardTarget( | ||
"CoreFoo", type: .dynamicLibrary, | ||
buildPhases: [ | ||
TestSourcesBuildPhase(["foo.c"]) | ||
], | ||
customTasks: [ | ||
TestCustomTask( | ||
commandLine: ["$(BUILD_DIR)/$(CONFIGURATION)/tool"], | ||
environment: [:], | ||
workingDirectory: tmpDir.str, | ||
executionDescription: "My Custom Task", | ||
inputs: ["$(BUILD_DIR)/$(CONFIGURATION)/tool"], | ||
outputs: [Path.root.join("output").str], | ||
enableSandboxing: false, | ||
preparesForIndexing: false) | ||
], | ||
dependencies: ["tool"] | ||
), | ||
TestStandardTarget( | ||
"tool", type: .hostBuildTool, | ||
buildPhases: [ | ||
TestSourcesBuildPhase(["tool.swift"]) | ||
] | ||
), | ||
]) | ||
let core = try await getCore() | ||
let tester = try await BuildOperationTester(core, testProject, simulated: false) | ||
|
||
let parameters = BuildParameters(action: .build, configuration: "Debug") | ||
|
||
try await tester.fs.writeFileContents(tmpDir.join("Sources").join("tool.swift")) { stream in | ||
stream <<< | ||
""" | ||
@main | ||
struct Entry { | ||
static func main() { | ||
print("warning: this is a warning") | ||
} | ||
} | ||
""" | ||
} | ||
|
||
try await tester.fs.writeFileContents(tmpDir.join("Sources").join("foo.c")) { stream in | ||
stream <<< | ||
""" | ||
void foo(void) {} | ||
""" | ||
} | ||
|
||
try await tester.checkBuild(parameters: parameters) { results in | ||
results.checkWarning(.contains("this is a warning")) | ||
results.checkNoDiagnostics() | ||
} | ||
} | ||
} | ||
} |