Skip to content

Commit e208fe5

Browse files
committed
Run CodeGeneration tests in CI
With the migration of build-script.py to Swift, we accidentally dropped running the CodeGeneration tests. Re-enable them and fix two test failures.
1 parent a381b0d commit e208fe5

File tree

3 files changed

+35
-41
lines changed

3 files changed

+35
-41
lines changed

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ class ValidateSyntaxNodes: XCTestCase {
515515
ValidationFailure(node: .differentiabilityArguments, message: "could conform to trait 'Parenthesized' but does not"),
516516
ValidationFailure(node: .editorPlaceholderDecl, message: "could conform to trait 'MissingNode' but does not"),
517517
ValidationFailure(node: .editorPlaceholderExpr, message: "could conform to trait 'MissingNode' but does not"),
518+
ValidationFailure(node: .editorPlaceholderPattern, message: "could conform to trait 'MissingNode' but does not"),
519+
ValidationFailure(node: .editorPlaceholderType, message: "could conform to trait 'MissingNode' but does not"),
518520
ValidationFailure(node: .enumCaseElement, message: "could conform to trait 'NamedDecl' but does not"),
519521
ValidationFailure(node: .genericParameter, message: "could conform to trait 'NamedDecl' but does not"),
520522
ValidationFailure(node: .precedenceGroupDecl, message: "could conform to trait 'Braced' but does not"),

SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Test.swift

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ struct Test: ParsableCommand, BuildCommand {
2424
var arguments: BuildArguments
2525

2626
func run() throws {
27-
try buildExample(exampleName: "ExamplePlugin")
28-
2927
try runTests()
28+
try runCodeGenerationTests()
3029

3130
logSection("All tests passed")
3231
}
@@ -41,31 +40,29 @@ struct Test: ParsableCommand, BuildCommand {
4140

4241
swiftpmCallArguments += ["--test-product", "swift-syntaxPackageTests"]
4342

44-
var additionalEnvironment: [String: String] = [:]
45-
additionalEnvironment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1"
43+
try invokeSwiftPM(
44+
action: "test",
45+
packageDir: Paths.packageDir,
46+
additionalArguments: swiftpmCallArguments,
47+
additionalEnvironment: swiftPMEnvironmentVariables,
48+
captureStdout: false,
49+
captureStderr: false
50+
)
51+
}
4652

47-
if arguments.enableRawSyntaxValidation {
48-
additionalEnvironment["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1"
49-
}
53+
private func runCodeGenerationTests() throws {
54+
logSection("Running CodeGeneration Tests")
55+
var swiftpmCallArguments: [String] = []
5056

51-
if arguments.enableTestFuzzing {
52-
additionalEnvironment["SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION"] = "1"
57+
if arguments.verbose {
58+
swiftpmCallArguments += ["--verbose"]
5359
}
5460

55-
// Tell other projects in the unified build to use local dependencies
56-
additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1"
57-
additionalEnvironment["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] =
58-
arguments.toolchain
59-
.appendingPathComponent("lib")
60-
.appendingPathComponent("swift")
61-
.appendingPathComponent("macosx")
62-
.path
63-
6461
try invokeSwiftPM(
6562
action: "test",
66-
packageDir: Paths.packageDir,
63+
packageDir: Paths.codeGenerationDir,
6764
additionalArguments: swiftpmCallArguments,
68-
additionalEnvironment: additionalEnvironment,
65+
additionalEnvironment: swiftPMEnvironmentVariables,
6966
captureStdout: false,
7067
captureStderr: false
7168
)

SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/BuildCommand.swift

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ extension BuildCommand {
2727
try build(packageDir: packageDir, name: targetName, isProduct: false)
2828
}
2929

30-
func buildExample(exampleName: String) throws {
31-
logSection("Building example " + exampleName)
32-
try build(packageDir: Paths.examplesDir, name: exampleName, isProduct: true)
33-
}
34-
3530
@discardableResult
3631
func invokeSwiftPM(
3732
action: String,
@@ -116,15 +111,9 @@ extension BuildCommand {
116111
}
117112
}
118113

119-
private func build(packageDir: URL, name: String, isProduct: Bool) throws {
120-
let args: [String]
121-
122-
if isProduct {
123-
args = ["--product", name]
124-
} else {
125-
args = ["--target", name]
126-
}
127-
114+
/// Environment variables that should be set when invoking `swift build` or
115+
/// `swift test`.
116+
var swiftPMEnvironmentVariables: [String: String] {
128117
var additionalEnvironment: [String: String] = [:]
129118
additionalEnvironment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1"
130119

@@ -138,18 +127,24 @@ extension BuildCommand {
138127

139128
// Tell other projects in the unified build to use local dependencies
140129
additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1"
141-
additionalEnvironment["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] =
142-
arguments.toolchain
143-
.appendingPathComponent("lib")
144-
.appendingPathComponent("swift")
145-
.appendingPathComponent("macos")
146-
.path
130+
131+
return additionalEnvironment
132+
}
133+
134+
private func build(packageDir: URL, name: String, isProduct: Bool) throws {
135+
let args: [String]
136+
137+
if isProduct {
138+
args = ["--product", name]
139+
} else {
140+
args = ["--target", name]
141+
}
147142

148143
try invokeSwiftPM(
149144
action: "build",
150145
packageDir: packageDir,
151146
additionalArguments: args,
152-
additionalEnvironment: additionalEnvironment,
147+
additionalEnvironment: swiftPMEnvironmentVariables,
153148
captureStdout: false,
154149
captureStderr: false
155150
)

0 commit comments

Comments
 (0)