Skip to content

Commit 9fc88d2

Browse files
authored
[test] Fix testExamplePackageDealer (#9134)
The test `testExamplePackageDealer` was failing on Amazon Linux and not in Swift.org's CI See #9126 ### Motivation: The reason why the test is working on Swift.org's CI is because it silently ignores outbound connection issues. The test fails to clone the project on github.com and silently stops. When the clone operation succeed, the test fails. This is the case on macOS and Amazon Linux 2023, probably others OSes too. ### Modifications: I observed multiple problems in this test. 1. the test was not marked `async` and the `withTemporaryDirectory` was not await. The test completed execution before the `git clone` operation finished. 2. The `git clone` operation requires an environment variable `HOME` to be defined 3. On Swift 6.1 and later, the second build recompiles the plugins. There are some lines `Compiling plugin` that are valid and should not fail the test. Here is an example of a valid output. It contains `Compiling plugin` ``` ➜ example-package-dealer git:(main) ✗ swift build > output.txt 2>&1 ➜ example-package-dealer git:(main) ✗ cat output.txt [0/1] Planning build [1/1] Compiling plugin GenerateManual [2/2] Compiling plugin GenerateDoccReference Building for debugging... [2/5] Write swift-version-1FA6DEBB9BBC2F77.txt Build complete! (1.01s) ➜ example-package-dealer git:(main) ✗ swift --version Apple Swift version 6.1.2 (swift-6.1.2-RELEASE) Target: arm64-apple-macosx15.0 ``` ### Result: The test passes on macOS and Amazon Linux 2023 ``` ✗ swift test --filter testExamplePackageDealer Building for debugging... [9/9] Linking SwiftPMPackageTests Build complete! (12.99s) Test Suite 'Selected tests' started at 2025-09-12 21:04:15.723. Test Suite 'SwiftPMPackageTests.xctest' started at 2025-09-12 21:04:15.727. Test Suite 'SwiftPMPackageTests.xctest' passed at 2025-09-12 21:04:15.727. Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds Test Suite 'Selected tests' passed at 2025-09-12 21:04:15.727. Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.004) seconds 􀟈 Test run started. 􀄵 Testing Library Version: 6.1.2 (d6b70f9ef9eb207) 􀄵 Target Platform: arm64-apple-macosx 􀟈 Suite BasicTests started. 􀟈 Test testExamplePackageDealer() started. 􁁛 Test testExamplePackageDealer() passed after 17.278 seconds. 􁁛 Suite BasicTests passed after 17.279 seconds. 􁁛 Test run with 1 test passed after 17.279 seconds. ```
1 parent b38eb07 commit 9fc88d2

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

Tests/IntegrationTests/BasicTests.swift

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,31 @@ private struct BasicTests {
2727
Tag.Feature.Command.Build,
2828
),
2929
)
30-
func testExamplePackageDealer() throws {
31-
try withTemporaryDirectory { tempDir in
30+
func testExamplePackageDealer() async throws {
31+
try await withTemporaryDirectory { tempDir in
3232
let packagePath = tempDir.appending(component: "dealer")
33+
let repoToClone = "https://github.com/swiftlang/example-package-dealer"
3334
withKnownIssue(isIntermittent: true) {
34-
// marking as withKnownIssue(intermittent: trye) as git operation can fail.
35-
try sh("git\(ProcessInfo.exeSuffix)", "clone", "https://github.com/apple/example-package-dealer", packagePath)
35+
// marking as withKnownIssue(intermittent: true) as git operation can fail.
36+
37+
#if os(macOS)
38+
// On macOS, we add the HOME variable to avoid git errors.
39+
try sh("git\(ProcessInfo.exeSuffix)", "clone", repoToClone, packagePath, env: ["HOME": tempDir.pathString])
40+
#else
41+
try sh("git\(ProcessInfo.exeSuffix)", "clone", repoToClone, packagePath)
42+
#endif
43+
}
44+
45+
// Do not run the test when the git clone operation failed
46+
if !FileManager.default.fileExists(atPath: packagePath.pathString) {
47+
//TODO: use Test Cancellation when available
48+
//https://forums.swift.org/t/pitch-test-cancellation/81847/18
49+
#if compiler(>=6.3)
50+
Issue.record("Can't clone the repository \(repoToClone), abording the test.", severity: .warning)
51+
#endif
52+
return
3653
}
54+
3755
let build1Output = try await executeSwiftBuild(
3856
packagePath,
3957
buildSystem: .native,
@@ -59,7 +77,11 @@ private struct BasicTests {
5977
buildSystem: .native,
6078
).stdout
6179
#expect(build2Output.contains("Build complete"))
62-
#expect(build2Output.contains("Compiling") == false)
80+
81+
// Check that no compilation happened (except for plugins which are allowed)
82+
// catch "Compiling xxx" but ignore "Compiling plugin" messages
83+
let compilingRegex = try Regex("Compiling (?!plugin)")
84+
#expect(build2Output.contains(compilingRegex) == false)
6385
}
6486
}
6587

0 commit comments

Comments
 (0)