Skip to content

Commit c2b2074

Browse files
committed
Add GitHub action to run tests using swift-syntax-dev-utils
swift-syntax-dev-utils also runs the CodeGeneration and Examples tests. It is also a convenient place where we can enable RawSyntax validation and test fuzzing. Running this using only the latest Swift version should be sufficient because we don't expect to find differences between versions here and expect contributors to swift-syntax to use the latests released Swift version anyway.
1 parent cb5e497 commit c2b2074

File tree

3 files changed

+69
-10
lines changed

3 files changed

+69
-10
lines changed

.github/workflows/pull_request.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,41 @@ jobs:
2727
persist-credentials: false
2828
- name: Validate generated code
2929
run: "./swift-syntax-dev-utils verify-source-code --toolchain /usr"
30+
test_using_swift_syntax_dev_utils_linux:
31+
name: Run tests using swift-syntax-dev-utils (Linux)
32+
runs-on: ubuntu-latest
33+
container:
34+
image: swift:latest
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
with:
39+
persist-credentials: false
40+
- name: Test
41+
run: "./swift-syntax-dev-utils test --enable-rawsyntax-validation --enable-test-fuzzing --toolchain /usr"
42+
test_using_swift_syntax_dev_utils_windows:
43+
name: Run tests using swift-syntax-dev-utils (Windows)
44+
runs-on: windows-2022
45+
steps:
46+
- name: Pull Docker image
47+
id: pull_docker_image
48+
run: |
49+
$Image = "swift:windowsservercore-ltsc2022"
50+
docker pull $Image
51+
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
52+
- name: Checkout repository
53+
uses: actions/checkout@v4
54+
with:
55+
persist-credentials: false
56+
- name: Test
57+
run: |
58+
mkdir $env:TEMP\test-script
59+
echo @'
60+
Set-PSDebug -Trace 1
61+
$SwiftPath = where.exe swift
62+
swift.exe run --package-path "C:\Source\SwiftSyntaxDevUtils" swift-syntax-dev-utils test --enable-rawsyntax-validation --enable-test-fuzzing --toolchain "$SwiftPath\..\.."
63+
if ($LastExitCode -ne 0) {
64+
exit $LastExitCode
65+
}
66+
'@ >> $env:TEMP\test-script\run.ps1
67+
docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script ${{ steps.pull_docker_image.outputs.image }} powershell.exe -NoLogo -File C:\test-script\run.ps1

Examples/Package.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let package = Package(
1313
.executable(name: "CodeGenerationUsingSwiftSyntaxBuilder", targets: ["CodeGenerationUsingSwiftSyntaxBuilder"]),
1414
],
1515
dependencies: [
16-
.package(path: "../")
16+
.package(name: "swift-syntax", path: "../")
1717
],
1818
targets: [
1919
.executableTarget(
@@ -39,15 +39,6 @@ let package = Package(
3939
],
4040
path: "Sources/MacroExamples/Implementation"
4141
),
42-
.testTarget(
43-
name: "MacroExamplesImplementationTests",
44-
dependencies: [
45-
"MacroExamplesImplementation",
46-
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
47-
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
48-
],
49-
path: "Tests/MacroExamples/Implementation"
50-
),
5142
.target(
5243
name: "MacroExamplesInterface",
5344
dependencies: [
@@ -65,6 +56,25 @@ let package = Package(
6556
]
6657
)
6758

59+
#if !os(Windows)
60+
// We can't write a test target for macros on Windows because that results in duplicate definitoions of `main`: Once
61+
// from the macro (which is effectively an executable), and once from the test bundle.
62+
package.targets.append(
63+
.testTarget(
64+
name: "MacroExamplesImplementationTests",
65+
dependencies: [
66+
"MacroExamplesImplementation",
67+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
68+
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
69+
],
70+
path: "Tests/MacroExamples/Implementation"
71+
)
72+
)
73+
#else
74+
// Add a dummy test target on Windows so that `swift test` invocations from `swift-syntax-dev-utils` don't fail.
75+
package.targets.append(.testTarget(name: "Dummy", dependencies: []))
76+
#endif
77+
6878
// This is a fake target that depends on all targets in the package.
6979
// We need to define it manually because the `Examples-Package` target doesn't exist for `swift build`.
7080

Examples/Tests/Dummy/Empty.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)