Skip to content

Commit d4a61b8

Browse files
author
Luke Daley
committed
Add initial unit and task construction tests for task wiring
1 parent 973bdbe commit d4a61b8

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2025 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 Foundation
14+
import Testing
15+
import SWBUtil
16+
import SWBCore
17+
import SWBProtocol
18+
import SWBTestSupport
19+
import SWBMacro
20+
21+
@Suite fileprivate struct DependencySettingsTests {
22+
23+
@Test
24+
func emptyDependenciesValueDisablesVerification() throws {
25+
var table1 = MacroValueAssignmentTable(namespace: BuiltinMacros.namespace)
26+
table1.push(BuiltinMacros.DEPENDENCIES_VERIFICATION, literal: true)
27+
let scope1 = MacroEvaluationScope(table: table1)
28+
#expect(!DependencySettings(scope1).verification)
29+
30+
var table2 = MacroValueAssignmentTable(namespace: BuiltinMacros.namespace)
31+
table2.push(BuiltinMacros.DEPENDENCIES_VERIFICATION, literal: true)
32+
table2.push(BuiltinMacros.DEPENDENCIES, literal: ["Foo"])
33+
let scope2 = MacroEvaluationScope(table: table2)
34+
#expect(DependencySettings(scope2).verification)
35+
}
36+
37+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2025 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 SWBCore
16+
import SWBTaskConstruction
17+
import SWBTestSupport
18+
import SWBUtil
19+
20+
@Suite
21+
fileprivate struct DependencyVerificationTaskConstructionTests: CoreBasedTests {
22+
23+
let project = "TestProject"
24+
let target = "TestTarget"
25+
let sourceBaseName = "TestSource"
26+
let source = "TestSource.m"
27+
28+
func outputFile(_ srcroot: Path, _ filename: String) -> String {
29+
return "\(srcroot.str)/build/\(project).build/Debug/\(target).build/Objects-normal/x86_64/\(filename)"
30+
}
31+
32+
@Test
33+
func addsTraceArgsWhenDependenciesDeclared() async throws {
34+
try await testWith(dependencies: ["Foo"]) { tester, srcroot in
35+
await tester.checkBuild(runDestination: .macOS) { results in
36+
results.checkTask(.matchRuleType("Ld")) { task in
37+
task.checkCommandLineContains([
38+
"-Xlinker", "-trace_file",
39+
"-Xlinker", outputFile(srcroot, "\(target)_trace.json"),
40+
])
41+
}
42+
results.checkTask(.compileC(target, fileName: source)) { task in
43+
task.checkCommandLineContains([
44+
"-Xclang", "-header-include-file",
45+
"-Xclang", outputFile(srcroot, "\(sourceBaseName).o.trace.json"),
46+
"-Xclang", "-header-include-filtering=only-direct-system",
47+
"-Xclang", "-header-include-format=json"
48+
])
49+
}
50+
}
51+
}
52+
}
53+
54+
@Test
55+
func noTraceArgsWhenDependenciesDeclared() async throws {
56+
try await testWith(dependencies: []) { tester, srcroot in
57+
await tester.checkBuild(runDestination: .macOS) { results in
58+
results.checkTask(.matchRuleType("Ld")) { task in
59+
task.checkCommandLineDoesNotContain("-trace_file")
60+
}
61+
results.checkTask(.compileC(target, fileName: source)) { task in
62+
task.checkCommandLineDoesNotContain("-header-include-file")
63+
}
64+
}
65+
}
66+
}
67+
68+
private func testWith(dependencies: [String], _ assertions: (_ tester: TaskConstructionTester, _ srcroot: Path) async throws -> Void) async throws {
69+
let testProject = TestProject(
70+
project,
71+
groupTree: TestGroup(
72+
"TestGroup",
73+
children: [
74+
TestFile(source)
75+
]),
76+
buildConfigurations: [
77+
TestBuildConfiguration(
78+
"Debug",
79+
buildSettings: [
80+
"DEPENDENCIES": dependencies.joined(separator: " "),
81+
"PRODUCT_NAME": "$(TARGET_NAME)",
82+
"GENERATE_INFOPLIST_FILE": "YES",
83+
"CLANG_ENABLE_MODULES": "YES"
84+
])
85+
],
86+
targets: [
87+
TestStandardTarget(
88+
target,
89+
type: .framework,
90+
buildPhases: [
91+
TestSourcesBuildPhase([TestBuildFile(source)])
92+
]
93+
)
94+
])
95+
96+
let core = try await getCore()
97+
let tester = try TaskConstructionTester(core, testProject)
98+
let SRCROOT = tester.workspace.projects[0].sourceRoot
99+
100+
try await assertions(tester, SRCROOT)
101+
}
102+
103+
}

0 commit comments

Comments
 (0)