|
12 | 12 | // |
13 | 13 | //===----------------------------------------------------------------------===// |
14 | 14 |
|
15 | | -import Foundation |
16 | 15 | import Basics |
17 | | -import XCTest |
| 16 | +import Foundation |
| 17 | +import Testing |
18 | 18 |
|
19 | | -class AuthTests: XCTestCase, @unchecked Sendable { |
| 19 | +struct AuthTests { |
20 | 20 | // SwiftPM's NetrcAuthorizationProvider does not throw an error if the .netrc file |
21 | 21 | // does not exist. For simplicity the local vendored version does the same. |
22 | | - func testNonexistentNetrc() async throws { |
| 22 | + @Test func testNonexistentNetrc() async throws { |
23 | 23 | // Construct a URL to a nonexistent file in the bundle directory |
24 | 24 | let netrcURL = Bundle.module.resourceURL!.appendingPathComponent("netrc.nonexistent") |
25 | | - XCTAssertFalse(FileManager.default.fileExists(atPath: netrcURL.path)) |
| 25 | + #expect(!FileManager.default.fileExists(atPath: netrcURL.path)) |
26 | 26 |
|
27 | 27 | let authProvider = try NetrcAuthorizationProvider(netrcURL) |
28 | | - XCTAssertNil(authProvider.authentication(for: URL(string: "https://hub.example.com")!)) |
| 28 | + #expect(authProvider.authentication(for: URL(string: "https://hub.example.com")!) == nil) |
29 | 29 | } |
30 | 30 |
|
31 | | - func testEmptyNetrc() async throws { |
| 31 | + @Test func testEmptyNetrc() async throws { |
32 | 32 | let netrcURL = Bundle.module.url(forResource: "netrc", withExtension: "empty")! |
33 | 33 | let authProvider = try NetrcAuthorizationProvider(netrcURL) |
34 | | - XCTAssertNil(authProvider.authentication(for: URL(string: "https://hub.example.com")!)) |
| 34 | + #expect(authProvider.authentication(for: URL(string: "https://hub.example.com")!) == nil) |
35 | 35 | } |
36 | 36 |
|
37 | | - func testBasicNetrc() async throws { |
| 37 | + @Test func testBasicNetrc() async throws { |
38 | 38 | let netrcURL = Bundle.module.url(forResource: "netrc", withExtension: "basic")! |
39 | 39 | let authProvider = try NetrcAuthorizationProvider(netrcURL) |
40 | | - XCTAssertNil(authProvider.authentication(for: URL(string: "https://nothing.example.com")!)) |
| 40 | + #expect(authProvider.authentication(for: URL(string: "https://nothing.example.com")!) == nil) |
41 | 41 |
|
42 | 42 | guard let (user, password) = authProvider.authentication(for: URL(string: "https://hub.example.com")!) else { |
43 | | - return XCTFail("Expected to find a username and password") |
| 43 | + Issue.record("Expected to find a username and password") |
| 44 | + return |
44 | 45 | } |
45 | | - XCTAssertEqual(user, "swift") |
46 | | - XCTAssertEqual(password, "password") |
| 46 | + #expect(user == "swift") |
| 47 | + #expect(password == "password") |
47 | 48 | } |
48 | 49 |
|
49 | 50 | // The default entry is used if no specific entry matches |
50 | | - func testComplexNetrcWithDefault() async throws { |
| 51 | + @Test func testComplexNetrcWithDefault() async throws { |
51 | 52 | let netrcURL = Bundle.module.url(forResource: "netrc", withExtension: "default")! |
52 | 53 | let authProvider = try NetrcAuthorizationProvider(netrcURL) |
53 | 54 |
|
54 | 55 | guard let (user, password) = authProvider.authentication(for: URL(string: "https://nothing.example.com")!) |
55 | | - else { return XCTFail("Expected to find a username and password") } |
56 | | - XCTAssertEqual(user, "defaultlogin") |
57 | | - XCTAssertEqual(password, "defaultpassword") |
| 56 | + else { |
| 57 | + Issue.record("Expected to find a username and password") |
| 58 | + return |
| 59 | + } |
| 60 | + #expect(user == "defaultlogin") |
| 61 | + #expect(password == "defaultpassword") |
58 | 62 | } |
59 | 63 |
|
60 | 64 | // The default entry must be last in the file |
61 | | - func testComplexNetrcWithInvalidDefault() async throws { |
| 65 | + @Test func testComplexNetrcWithInvalidDefault() async throws { |
62 | 66 | let netrcURL = Bundle.module.url(forResource: "netrc", withExtension: "invaliddefault")! |
63 | | - XCTAssertThrowsError(try NetrcAuthorizationProvider(netrcURL)) { error in |
64 | | - XCTAssertEqual(error as! NetrcError, NetrcError.invalidDefaultMachinePosition) |
| 67 | + #expect { try NetrcAuthorizationProvider(netrcURL) } throws: { error in |
| 68 | + error as! NetrcError == NetrcError.invalidDefaultMachinePosition |
65 | 69 | } |
66 | 70 | } |
67 | 71 |
|
68 | 72 | // If there are multiple entries for the same host, the last one wins |
69 | | - func testComplexNetrcOverriddenEntry() async throws { |
| 73 | + @Test func testComplexNetrcOverriddenEntry() async throws { |
70 | 74 | let netrcURL = Bundle.module.url(forResource: "netrc", withExtension: "default")! |
71 | 75 | let authProvider = try NetrcAuthorizationProvider(netrcURL) |
72 | 76 |
|
73 | 77 | guard let (user, password) = authProvider.authentication(for: URL(string: "https://hub.example.com")!) else { |
74 | | - return XCTFail("Expected to find a username and password") |
| 78 | + Issue.record("Expected to find a username and password") |
| 79 | + return |
75 | 80 | } |
76 | | - XCTAssertEqual(user, "swift2") |
77 | | - XCTAssertEqual(password, "password2") |
| 81 | + #expect(user == "swift2") |
| 82 | + #expect(password == "password2") |
78 | 83 | } |
79 | 84 |
|
80 | 85 | // A singleton entry in a netrc file with defaults and overriden entries continues to work as in the simple case |
81 | | - func testComplexNetrcSingletonEntry() async throws { |
| 86 | + @Test func testComplexNetrcSingletonEntry() async throws { |
82 | 87 | let netrcURL = Bundle.module.url(forResource: "netrc", withExtension: "default")! |
83 | 88 | let authProvider = try NetrcAuthorizationProvider(netrcURL) |
84 | 89 |
|
85 | 90 | guard let (user, password) = authProvider.authentication(for: URL(string: "https://another.example.com")!) |
86 | | - else { return XCTFail("Expected to find a username and password") } |
87 | | - XCTAssertEqual(user, "anotherlogin") |
88 | | - XCTAssertEqual(password, "anotherpassword") |
| 91 | + else { |
| 92 | + Issue.record("Expected to find a username and password") |
| 93 | + return |
| 94 | + } |
| 95 | + #expect(user == "anotherlogin") |
| 96 | + #expect(password == "anotherpassword") |
89 | 97 | } |
90 | 98 | } |
0 commit comments