-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Update command-line interface for .netrc file handling #3763
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
94db3c5
Default --netrc to true, adding --no-netrc inversion
mattt e824ef7
Deprecate --netrc-optional flag
mattt a19d241
Add help and documentation comments for --netrc flag and --netrc-file…
mattt f219f4f
Update testNetrcFile
mattt 85fa08a
Fix .netrc file handling behavior
mattt ca5af5a
Refactor tests for .netrc option handling
mattt 4573b0a
Return nil configuration if .netrc file doesn't exist
mattt 9dcb637
Emit warning if --netrc-optional is passed
mattt 51785cf
Use --enable-netrc / --disable-netrc inversion flags
mattt 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
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -50,6 +50,34 @@ final class PackageToolTests: XCTestCase { | |
XCTAssertMatch(stdout, .contains("Swift Package Manager")) | ||
} | ||
|
||
func testNetrc() throws { | ||
fixture(name: "DependencyResolution/External/XCFramework") { packageRoot in | ||
// --enable-netrc flag | ||
try self.execute(["resolve", "--enable-netrc"], packagePath: packageRoot) | ||
|
||
// --disable-netrc flag | ||
try self.execute(["resolve", "--disable-netrc"], packagePath: packageRoot) | ||
|
||
// --enable-netrc and --disable-netrc flags | ||
XCTAssertThrowsError( | ||
try self.execute(["resolve", "--enable-netrc", "--disable-netrc"], packagePath: packageRoot) | ||
) { error in | ||
XCTAssertMatch(String(describing: error), .contains("Value to be set with flag '--disable-netrc' had already been set with flag '--enable-netrc'")) | ||
} | ||
|
||
// deprecated --netrc flag | ||
let stderr = try self.execute(["resolve", "--netrc"], packagePath: packageRoot).stderr | ||
XCTAssertMatch(stderr, .contains("'--netrc' option is deprecated")) | ||
} | ||
} | ||
|
||
func testNetrcOptional() throws { | ||
fixture(name: "DependencyResolution/External/XCFramework") { packageRoot in | ||
let stderr = try self.execute(["resolve", "--netrc-optional"], packagePath: packageRoot).stderr | ||
XCTAssertMatch(stderr, .contains("'--netrc-optional' option is deprecated")) | ||
} | ||
} | ||
|
||
func testNetrcFile() throws { | ||
fixture(name: "DependencyResolution/External/XCFramework") { packageRoot in | ||
let fs = localFileSystem | ||
|
@@ -58,39 +86,28 @@ final class PackageToolTests: XCTestCase { | |
stream <<< "machine mymachine.labkey.org login [email protected] password mypassword" | ||
} | ||
|
||
do { | ||
// file at correct location | ||
try execute(["--netrc-file", netrcPath.pathString, "resolve"], packagePath: packageRoot) | ||
// file does not exist, but is optional | ||
let textOutput = try execute(["--netrc-file", "/foo", "--netrc-optional", "resolve"], packagePath: packageRoot).stderr | ||
XCTAssertMatch(textOutput, .contains("warning: Did not find optional .netrc file at /foo.")) | ||
|
||
// required file does not exist, will throw | ||
try execute(["--netrc-file", "/foo", "resolve"], packagePath: packageRoot) | ||
} catch { | ||
XCTAssertMatch(String(describing: error), .contains("Cannot find mandatory .netrc file at /foo")) | ||
// valid .netrc file path | ||
try execute(["resolve", "--netrc-file", netrcPath.pathString], packagePath: packageRoot) | ||
|
||
// valid .netrc file path with --disable-netrc option | ||
XCTAssertThrowsError( | ||
try execute(["resolve", "--netrc-file", netrcPath.pathString, "--disable-netrc"], packagePath: packageRoot) | ||
) { error in | ||
XCTAssertMatch(String(describing: error), .contains("'--disable-netrc' and '--netrc-file' are mutually exclusive")) | ||
} | ||
} | ||
|
||
fixture(name: "DependencyResolution/External/XCFramework") { packageRoot in | ||
do { | ||
// Developer machine may have .netrc file at NSHomeDirectory; modify test accordingly | ||
if localFileSystem.exists(localFileSystem.homeDirectory.appending(RelativePath(".netrc"))) { | ||
try execute(["--netrc", "resolve"], packagePath: packageRoot) | ||
} else { | ||
// file does not exist, but is optional | ||
let textOutput = try execute(["--netrc", "--netrc-optional", "resolve"], packagePath: packageRoot) | ||
XCTAssertMatch(textOutput.stderr, .contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc.")) | ||
|
||
// file does not exist, but is optional | ||
let textOutput2 = try execute(["--netrc-optional", "resolve"], packagePath: packageRoot) | ||
XCTAssertMatch(textOutput2.stderr, .contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc.")) | ||
|
||
// required file does not exist, will throw | ||
try execute(["--netrc", "resolve"], packagePath: packageRoot) | ||
} | ||
} catch { | ||
XCTAssertMatch(String(describing: error), .contains("Cannot find mandatory .netrc file at \(localFileSystem.homeDirectory)/.netrc")) | ||
// invalid .netrc file path | ||
XCTAssertThrowsError( | ||
try execute(["resolve", "--netrc-file", "/foo"], packagePath: packageRoot) | ||
) { error in | ||
XCTAssertMatch(String(describing: error), .contains("Did not find .netrc file at /foo.")) | ||
} | ||
|
||
// invalid .netrc file path with --disable-netrc option | ||
XCTAssertThrowsError( | ||
try execute(["resolve", "--netrc-file", "/foo", "--disable-netrc"], packagePath: packageRoot) | ||
) { error in | ||
XCTAssertMatch(String(describing: error), .contains("'--disable-netrc' and '--netrc-file' are mutually exclusive")) | ||
} | ||
} | ||
} | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.