-
Notifications
You must be signed in to change notification settings - Fork 28
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
Swiftly proxies #155
Open
cmcgee1024
wants to merge
29
commits into
swiftlang:main
Choose a base branch
from
cmcgee1024:proxies-design
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Swiftly proxies #155
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e4efbeb
DRAFT: Swiftly proxies
cmcgee1024 3b5c404
Add a swiftly install workflow where the version comes from the .swif…
cmcgee1024 956256f
update design to make auto-installation an error instead
cmcgee1024 375df29
provide a mechanism to find the currently in-use toolchain physical l…
cmcgee1024 ed68a9e
add more details about the selector prefix, and methods to escape
cmcgee1024 c745f4c
Restructure the PR to move the selector syntax from the proxies to a …
cmcgee1024 560236d
Implement proxy mechanism with dynamic toolchain selection
cmcgee1024 ae29e88
Merge branch 'main' of github.com:cmcgee1024/swiftly into proxies-design
cmcgee1024 ce0d27a
Rewrite the select toolchain function with a type for the selection r…
cmcgee1024 66dd459
Update the documentation
cmcgee1024 2df7357
Create a swiftly run command
cmcgee1024 8976bba
Fix empty command case with a single ++++
cmcgee1024 3caab66
Write run command and proxy tests
cmcgee1024 31f4327
Regenerate the cli reference documentation
cmcgee1024 16caf80
Fix design document discrepancies and add install proxy argument tests
cmcgee1024 b2aa165
Update the list command to decorate default, and in-use toolchains
cmcgee1024 7504dd3
Update list tests to check for in use and default labels
cmcgee1024 0e7b661
Make the version argument optional in the install subcommand
cmcgee1024 43d620a
Fix case of empty bin directory when checking for overwrite
cmcgee1024 2e3c59d
Remove +install selector option from swift run in favour of regular `…
cmcgee1024 9dd640c
Import GPG keys on every install to get new signing keys from swift.org
cmcgee1024 5e615ea
Make recommended documentation changes.
cmcgee1024 10a0856
Merge branch 'main' of github.com:cmcgee1024/swiftly into proxies-design
cmcgee1024 6d6050e
Provide a better error message on swiftly install with no version
cmcgee1024 6989796
Update README, and add documentation for the new run subcommand
cmcgee1024 52d081f
Prompt before updating the `.swift-version` file.
cmcgee1024 2f6d701
Merge branch 'main' of github.com:cmcgee1024/swiftly into proxies-design
cmcgee1024 cb0e923
Create proxies on toolchain installation, creating only the necessary…
cmcgee1024 bb36de0
Fix the design document
cmcgee1024 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Write run command and proxy tests
- Loading branch information
commit 3caab6679634299a841221a6129f6ee39b743785
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import Foundation | ||
@testable import Swiftly | ||
@testable import SwiftlyCore | ||
import XCTest | ||
|
||
final class RunTests: SwiftlyTests { | ||
static let homeName = "runTests" | ||
|
||
/// Tests that the `run` command can switch between installed toolchains. | ||
func testRunSelection() async throws { | ||
try await self.withMockedHome(homeName: Self.homeName, toolchains: Self.allToolchains) { | ||
// GIVEN: a set of installed toolchains | ||
// WHEN: invoking the run command with a selector argument for that toolchain | ||
var run = try self.parseCommand(Run.self, ["run", "swift", "--version", "+\(Self.newStable.name)"]) | ||
var output = try await run.runWithMockedIO() | ||
// THEN: the output confirms that it ran with the selected toolchain | ||
XCTAssert(output.contains(Self.newStable.name)) | ||
|
||
// GIVEN: a set of installed toolchains and one is selected with a .swift-version file | ||
let versionFile = URL(fileURLWithPath: FileManager.default.currentDirectoryPath).appendingPathComponent(".swift-version") | ||
try Self.oldStable.name.write(to: versionFile, atomically: true, encoding: .utf8) | ||
// WHEN: invoking the run command without any selector arguments for toolchains | ||
run = try self.parseCommand(Run.self, ["run", "swift", "--version"]) | ||
output = try await run.runWithMockedIO() | ||
// THEN: the output confirms that it ran with the selected toolchain | ||
XCTAssert(output.contains(Self.oldStable.name)) | ||
|
||
// GIVEN: a set of installed toolchains | ||
// WHEN: invoking the run command with a selector argument for a toolchain that isn't installed | ||
run = try self.parseCommand(Run.self, ["run", "swift", "+1.2.3", "--version"]) | ||
do { | ||
try await run.run() | ||
XCTAssert(false) | ||
} catch let e as Error { | ||
XCTAssert(e.message.contains("didn't match any of the installed toolchains")) | ||
} | ||
// THEN: an error is shown because there is no matching toolchain that is installed | ||
} | ||
} | ||
|
||
/// Tests the `run` command verifying that the environment is as expected | ||
func testRunEnvironment() async throws { | ||
try await self.withMockedHome(homeName: Self.homeName, toolchains: Self.allToolchains) { | ||
// The toolchains directory should be the fist entry on the path | ||
var run = try self.parseCommand(Run.self, ["run", try await Swiftly.currentPlatform.getShell(), "-c", "echo $PATH"]) | ||
var output = try await run.runWithMockedIO() | ||
XCTAssert(output[0].contains(Swiftly.currentPlatform.swiftlyToolchainsDir.path)) | ||
|
||
// The CC and CXX variables should be set to clang/clang++ in the toolchains | ||
run = try self.parseCommand(Run.self, ["run", try await Swiftly.currentPlatform.getShell(), "-c", "echo $CC; echo $CXX"]) | ||
output = try await run.runWithMockedIO() | ||
XCTAssert(output[0].hasPrefix(Swiftly.currentPlatform.swiftlyToolchainsDir.path)) | ||
XCTAssert(output[0].hasSuffix("clang")) | ||
XCTAssert(output[1].hasPrefix(Swiftly.currentPlatform.swiftlyToolchainsDir.path)) | ||
XCTAssert(output[1].hasSuffix("clang++")) | ||
} | ||
} | ||
|
||
/// Tests the extraction of proxy arguments from the run command arguments. | ||
func testExtractProxyArguments() throws { | ||
var (command, selector, install) = try extractProxyArguments(command: ["swift", "build"]) | ||
XCTAssertEqual(["swift", "build"], command) | ||
XCTAssertEqual(false, install) | ||
XCTAssertEqual(nil, selector) | ||
|
||
(command, selector, install) = try extractProxyArguments(command: ["swift", "+1.2.3", "build"]) | ||
XCTAssertEqual(["swift", "build"], command) | ||
XCTAssertEqual(false, install) | ||
XCTAssertEqual(try! ToolchainSelector(parsing: "1.2.3"), selector) | ||
|
||
(command, selector, install) = try extractProxyArguments(command: ["swift", "build", "+latest"]) | ||
XCTAssertEqual(["swift", "build"], command) | ||
XCTAssertEqual(false, install) | ||
XCTAssertEqual(try! ToolchainSelector(parsing: "latest"), selector) | ||
|
||
(command, selector, install) = try extractProxyArguments(command: ["+5.6", "swift", "build"]) | ||
XCTAssertEqual(["swift", "build"], command) | ||
XCTAssertEqual(false, install) | ||
XCTAssertEqual(try! ToolchainSelector(parsing: "5.6"), selector) | ||
|
||
(command, selector, install) = try extractProxyArguments(command: ["swift", "++1.2.3", "build"]) | ||
XCTAssertEqual(["swift", "+1.2.3", "build"], command) | ||
XCTAssertEqual(false, install) | ||
XCTAssertEqual(nil, selector) | ||
|
||
(command, selector, install) = try extractProxyArguments(command: ["swift", "++", "+1.2.3", "build"]) | ||
XCTAssertEqual(["swift", "+1.2.3", "build"], command) | ||
XCTAssertEqual(false, install) | ||
XCTAssertEqual(nil, selector) | ||
|
||
do { | ||
let _ = try extractProxyArguments(command: ["+1.2.3"]) | ||
XCTAssert(false) | ||
} catch {} | ||
|
||
do { | ||
let _ = try extractProxyArguments(command: []) | ||
XCTAssert(false) | ||
} catch {} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than splitting and joining again, can we just concatenate
tcPath
,":"
, andnewPath
?