@@ -50,6 +50,34 @@ final class PackageToolTests: XCTestCase {
50
50
XCTAssertMatch ( stdout, . contains( " Swift Package Manager " ) )
51
51
}
52
52
53
+ func testNetrc( ) throws {
54
+ fixture ( name: " DependencyResolution/External/XCFramework " ) { packageRoot in
55
+ // --enable-netrc flag
56
+ try self . execute ( [ " resolve " , " --enable-netrc " ] , packagePath: packageRoot)
57
+
58
+ // --disable-netrc flag
59
+ try self . execute ( [ " resolve " , " --disable-netrc " ] , packagePath: packageRoot)
60
+
61
+ // --enable-netrc and --disable-netrc flags
62
+ XCTAssertThrowsError (
63
+ try self . execute ( [ " resolve " , " --enable-netrc " , " --disable-netrc " ] , packagePath: packageRoot)
64
+ ) { error in
65
+ XCTAssertMatch ( String ( describing: error) , . contains( " Value to be set with flag '--disable-netrc' had already been set with flag '--enable-netrc' " ) )
66
+ }
67
+
68
+ // deprecated --netrc flag
69
+ let stderr = try self . execute ( [ " resolve " , " --netrc " ] , packagePath: packageRoot) . stderr
70
+ XCTAssertMatch ( stderr, . contains( " '--netrc' option is deprecated " ) )
71
+ }
72
+ }
73
+
74
+ func testNetrcOptional( ) throws {
75
+ fixture ( name: " DependencyResolution/External/XCFramework " ) { packageRoot in
76
+ let stderr = try self . execute ( [ " resolve " , " --netrc-optional " ] , packagePath: packageRoot) . stderr
77
+ XCTAssertMatch ( stderr, . contains( " '--netrc-optional' option is deprecated " ) )
78
+ }
79
+ }
80
+
53
81
func testNetrcFile( ) throws {
54
82
fixture ( name: " DependencyResolution/External/XCFramework " ) { packageRoot in
55
83
let fs = localFileSystem
@@ -58,39 +86,28 @@ final class PackageToolTests: XCTestCase {
58
86
stream
<<< " machine mymachine.labkey.org login [email protected] password mypassword "
59
87
}
60
88
61
- do {
62
- // file at correct location
63
- try execute ( [ " --netrc-file " , netrcPath. pathString, " resolve " ] , packagePath: packageRoot)
64
- // file does not exist, but is optional
65
- let textOutput = try execute ( [ " --netrc-file " , " /foo " , " --netrc-optional " , " resolve " ] , packagePath: packageRoot) . stderr
66
- XCTAssertMatch ( textOutput, . contains( " warning: Did not find optional .netrc file at /foo. " ) )
67
-
68
- // required file does not exist, will throw
69
- try execute ( [ " --netrc-file " , " /foo " , " resolve " ] , packagePath: packageRoot)
70
- } catch {
71
- XCTAssertMatch ( String ( describing: error) , . contains( " Cannot find mandatory .netrc file at /foo " ) )
89
+ // valid .netrc file path
90
+ try execute ( [ " resolve " , " --netrc-file " , netrcPath. pathString] , packagePath: packageRoot)
91
+
92
+ // valid .netrc file path with --disable-netrc option
93
+ XCTAssertThrowsError (
94
+ try execute ( [ " resolve " , " --netrc-file " , netrcPath. pathString, " --disable-netrc " ] , packagePath: packageRoot)
95
+ ) { error in
96
+ XCTAssertMatch ( String ( describing: error) , . contains( " '--disable-netrc' and '--netrc-file' are mutually exclusive " ) )
72
97
}
73
- }
74
98
75
- fixture ( name: " DependencyResolution/External/XCFramework " ) { packageRoot in
76
- do {
77
- // Developer machine may have .netrc file at NSHomeDirectory; modify test accordingly
78
- if localFileSystem. exists ( localFileSystem. homeDirectory. appending ( RelativePath ( " .netrc " ) ) ) {
79
- try execute ( [ " --netrc " , " resolve " ] , packagePath: packageRoot)
80
- } else {
81
- // file does not exist, but is optional
82
- let textOutput = try execute ( [ " --netrc " , " --netrc-optional " , " resolve " ] , packagePath: packageRoot)
83
- XCTAssertMatch ( textOutput. stderr, . contains( " Did not find optional .netrc file at \( localFileSystem. homeDirectory) /.netrc. " ) )
84
-
85
- // file does not exist, but is optional
86
- let textOutput2 = try execute ( [ " --netrc-optional " , " resolve " ] , packagePath: packageRoot)
87
- XCTAssertMatch ( textOutput2. stderr, . contains( " Did not find optional .netrc file at \( localFileSystem. homeDirectory) /.netrc. " ) )
88
-
89
- // required file does not exist, will throw
90
- try execute ( [ " --netrc " , " resolve " ] , packagePath: packageRoot)
91
- }
92
- } catch {
93
- XCTAssertMatch ( String ( describing: error) , . contains( " Cannot find mandatory .netrc file at \( localFileSystem. homeDirectory) /.netrc " ) )
99
+ // invalid .netrc file path
100
+ XCTAssertThrowsError (
101
+ try execute ( [ " resolve " , " --netrc-file " , " /foo " ] , packagePath: packageRoot)
102
+ ) { error in
103
+ XCTAssertMatch ( String ( describing: error) , . contains( " Did not find .netrc file at /foo. " ) )
104
+ }
105
+
106
+ // invalid .netrc file path with --disable-netrc option
107
+ XCTAssertThrowsError (
108
+ try execute ( [ " resolve " , " --netrc-file " , " /foo " , " --disable-netrc " ] , packagePath: packageRoot)
109
+ ) { error in
110
+ XCTAssertMatch ( String ( describing: error) , . contains( " '--disable-netrc' and '--netrc-file' are mutually exclusive " ) )
94
111
}
95
112
}
96
113
}
0 commit comments