Skip to content

Commit 95f8eb3

Browse files
MaxDesiatovfurby-tm
authored andcommitted
Add end-to-end tests for sdk and experimental-sdk commands (swiftlang#7517)
Previously these commands weren't covered with end-to-end tests. Now we verify that installation/listing/removal of a fixture Swift SDK succeeds, and also verify that `experimental-sdk` invocations issue a deprecation warning.
1 parent 26e6f8f commit 95f8eb3

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

Fixtures/SwiftSDKs/Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// This empty file tells test fixture logic to copy this directory's content to the test case temp directory.

Sources/SPMTestSupport/SwiftPMProduct.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ package enum SwiftPM {
2525
case Registry
2626
case Test
2727
case Run
28+
case experimentalSDK
29+
case sdk
2830
}
2931

3032
extension SwiftPM {
@@ -41,6 +43,10 @@ extension SwiftPM {
4143
return "swift-test"
4244
case .Run:
4345
return "swift-run"
46+
case .experimentalSDK:
47+
return "swift-experimental-sdk"
48+
case .sdk:
49+
return "swift-sdk"
4450
}
4551
}
4652

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2014-2024 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 Basics
14+
import Commands
15+
import SPMTestSupport
16+
import XCTest
17+
18+
import class TSCBasic.Process
19+
import enum TSCBasic.ProcessEnv
20+
21+
private let deprecationWarning = "warning: `swift experimental-sdk` command is deprecated and will be removed in a future version of SwiftPM. Use `swift sdk` instead."
22+
23+
final class SDKCommandTests: CommandsTestCase {
24+
func testUsage() throws {
25+
for command in [SwiftPM.sdk, SwiftPM.experimentalSDK] {
26+
let stdout = try command.execute(["-help"]).stdout
27+
XCTAssert(stdout.contains("USAGE: swift sdk <subcommand>") || stdout.contains("USAGE: swift sdk [<subcommand>]"), "got stdout:\n" + stdout)
28+
}
29+
}
30+
31+
func testVersion() throws {
32+
for command in [SwiftPM.sdk, SwiftPM.experimentalSDK] {
33+
let stdout = try command.execute(["--version"]).stdout
34+
XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout)
35+
}
36+
}
37+
38+
func testInstallSDK() throws {
39+
for command in [SwiftPM.sdk, SwiftPM.experimentalSDK] {
40+
try fixture(name: "SwiftSDKs") { fixturePath in
41+
for bundle in ["test-sdk.artifactbundle.tar.gz", "test-sdk.artifactbundle.zip"] {
42+
var (stdout, stderr) = try command.execute(
43+
[
44+
"install",
45+
"--swift-sdks-path", fixturePath.pathString,
46+
fixturePath.appending(bundle).pathString
47+
]
48+
)
49+
50+
if command == .experimentalSDK {
51+
XCTAssertMatch(stdout, .contains(deprecationWarning))
52+
}
53+
54+
// We only expect tool's output on the stdout stream.
55+
XCTAssertMatch(
56+
stdout,
57+
.contains("\(bundle)` successfully installed as test-sdk.artifactbundle.")
58+
)
59+
60+
XCTAssertEqual(stderr.count, 0)
61+
62+
(stdout, stderr) = try command.execute(
63+
["list", "--swift-sdks-path", fixturePath.pathString])
64+
65+
if command == .experimentalSDK {
66+
XCTAssertMatch(stdout, .contains(deprecationWarning))
67+
}
68+
69+
// We only expect tool's output on the stdout stream.
70+
XCTAssertMatch(stdout, .contains("test-artifact"))
71+
XCTAssertEqual(stderr.count, 0)
72+
73+
XCTAssertThrowsError(try command.execute(
74+
[
75+
"install",
76+
"--swift-sdks-path", fixturePath.pathString,
77+
fixturePath.appending(bundle).pathString
78+
]
79+
)) { error in
80+
guard case SwiftPMError.executionFailure(_, _, let stderr) = error else {
81+
XCTFail()
82+
return
83+
}
84+
85+
XCTAssertTrue(
86+
stderr.contains(
87+
"Error: Swift SDK bundle with name `test-sdk.artifactbundle` is already installed. Can't install a new bundle with the same name."
88+
),
89+
"got stderr: \(stderr)"
90+
)
91+
}
92+
93+
if command == .experimentalSDK {
94+
XCTAssertMatch(stdout, .contains(deprecationWarning))
95+
}
96+
97+
(stdout, stderr) = try command.execute(
98+
["remove", "--swift-sdks-path", fixturePath.pathString, "test-artifact"])
99+
100+
if command == .experimentalSDK {
101+
XCTAssertMatch(stdout, .contains(deprecationWarning))
102+
}
103+
104+
// We only expect tool's output on the stdout stream.
105+
XCTAssertMatch(stdout, .contains("test-sdk.artifactbundle` was successfully removed from the file system."))
106+
XCTAssertEqual(stderr.count, 0)
107+
108+
(stdout, stderr) = try command.execute(
109+
["list", "--swift-sdks-path", fixturePath.pathString])
110+
111+
if command == .experimentalSDK {
112+
XCTAssertMatch(stdout, .contains(deprecationWarning))
113+
}
114+
115+
// We only expect tool's output on the stdout stream.
116+
XCTAssertNoMatch(stdout, .contains("test-artifact"))
117+
XCTAssertEqual(stderr.count, 0)
118+
}
119+
}
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)