Skip to content

Add GitHub action to run tests using swift-syntax-dev-utils #3003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,41 @@ jobs:
persist-credentials: false
- name: Validate generated code
run: "./swift-syntax-dev-utils verify-source-code --toolchain /usr"
test_using_swift_syntax_dev_utils_linux:
name: Run tests using swift-syntax-dev-utils (Linux)
runs-on: ubuntu-latest
container:
image: swift:latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Test
run: "./swift-syntax-dev-utils test --enable-rawsyntax-validation --enable-test-fuzzing --toolchain /usr"
test_using_swift_syntax_dev_utils_windows:
name: Run tests using swift-syntax-dev-utils (Windows)
runs-on: windows-2022
steps:
- name: Pull Docker image
id: pull_docker_image
run: |
$Image = "swift:windowsservercore-ltsc2022"
docker pull $Image
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Test
run: |
mkdir $env:TEMP\test-script
echo @'
Set-PSDebug -Trace 1
$SwiftPath = where.exe swift
swift.exe run --package-path "C:\Source\SwiftSyntaxDevUtils" swift-syntax-dev-utils test --enable-rawsyntax-validation --enable-test-fuzzing --toolchain "$SwiftPath\..\.."
if ($LastExitCode -ne 0) {
exit $LastExitCode
}
'@ >> $env:TEMP\test-script\run.ps1
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
30 changes: 20 additions & 10 deletions Examples/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
.executable(name: "CodeGenerationUsingSwiftSyntaxBuilder", targets: ["CodeGenerationUsingSwiftSyntaxBuilder"]),
],
dependencies: [
.package(path: "../")
.package(name: "swift-syntax", path: "../")
],
targets: [
.executableTarget(
Expand All @@ -39,15 +39,6 @@ let package = Package(
],
path: "Sources/MacroExamples/Implementation"
),
.testTarget(
name: "MacroExamplesImplementationTests",
dependencies: [
"MacroExamplesImplementation",
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
],
path: "Tests/MacroExamples/Implementation"
),
.target(
name: "MacroExamplesInterface",
dependencies: [
Expand All @@ -65,6 +56,25 @@ let package = Package(
]
)

#if !os(Windows)
// We can't write a test target for macros on Windows because that results in duplicate definitoions of `main`: Once
// from the macro (which is effectively an executable), and once from the test bundle.
package.targets.append(
.testTarget(
name: "MacroExamplesImplementationTests",
dependencies: [
"MacroExamplesImplementation",
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
],
path: "Tests/MacroExamples/Implementation"
)
)
#else
// Add a dummy test target on Windows so that `swift test` invocations from `swift-syntax-dev-utils` don't fail.
package.targets.append(.testTarget(name: "Dummy", dependencies: []))
#endif

// This is a fake target that depends on all targets in the package.
// We need to define it manually because the `Examples-Package` target doesn't exist for `swift build`.

Expand Down
11 changes: 11 additions & 0 deletions Examples/Tests/Dummy/Empty.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//