Skip to content

Commit bb78546

Browse files
authored
Updates from PackageDSLKit (#89)
1 parent 61fb486 commit bb78546

File tree

12 files changed

+158
-92
lines changed

12 files changed

+158
-92
lines changed

Macros/Options/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.7.1
1+
// swift-tools-version: 6.0
22

33
// swiftlint:disable explicit_top_level_acl
44
// swiftlint:disable prefixed_toplevel_constant

Macros/Options/Tests/OptionsTests/EnumSetTests.swift

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,63 +28,69 @@
2828
//
2929

3030
@testable import Options
31-
import XCTest
31+
import Testing
3232

33-
internal final class EnumSetTests: XCTestCase {
33+
@Suite
34+
internal struct EnumSetTests {
3435
private static let text = "[\"a\",\"b\",\"c\"]"
3536

36-
internal func testDecoder() {
37+
@Test
38+
internal func decoder() {
3739
// swiftlint:disable:next force_unwrapping
3840
let data = Self.text.data(using: .utf8)!
3941
let decoder = JSONDecoder()
4042
let actual: EnumSet<MockCollectionEnum>
4143
do {
4244
actual = try decoder.decode(EnumSet<MockCollectionEnum>.self, from: data)
4345
} catch {
44-
XCTAssertNil(error)
46+
Issue.record("Unexpected error: \(error)")
4547
return
4648
}
47-
XCTAssertEqual(actual.rawValue, 7)
49+
#expect(actual.rawValue == 7)
4850
}
4951

50-
internal func testEncoder() {
52+
@Test
53+
internal func encoder() {
5154
let enumSet = EnumSet<MockCollectionEnum>(values: [.a, .b, .c])
5255
let encoder = JSONEncoder()
5356
let data: Data
5457
do {
5558
data = try encoder.encode(enumSet)
5659
} catch {
57-
XCTAssertNil(error)
60+
Issue.record("Unexpected error: \(error)")
5861
return
5962
}
6063

6164
let dataText = String(bytes: data, encoding: .utf8)
6265

6366
guard let text = dataText else {
64-
XCTAssertNotNil(dataText)
67+
Issue.record("Failed to convert data to string")
6568
return
6669
}
6770

68-
XCTAssertEqual(text, Self.text)
71+
#expect(text == Self.text)
6972
}
7073

71-
internal func testInitValue() {
74+
@Test
75+
internal func initValue() {
7276
let set = EnumSet<MockCollectionEnum>(rawValue: 7)
73-
XCTAssertEqual(set.rawValue, 7)
77+
#expect(set.rawValue == 7)
7478
}
7579

76-
internal func testInitValues() {
80+
@Test
81+
internal func initValues() {
7782
let values: [MockCollectionEnum] = [.a, .b, .c]
7883
let setA = EnumSet(values: values)
79-
XCTAssertEqual(setA.rawValue, 7)
84+
#expect(setA.rawValue == 7)
8085
let setB: MockCollectionEnumSet = [.a, .b, .c]
81-
XCTAssertEqual(setB.rawValue, 7)
86+
#expect(setB.rawValue == 7)
8287
}
8388

84-
internal func testArray() {
89+
@Test
90+
internal func array() {
8591
let expected: [MockCollectionEnum] = [.b, .d]
8692
let enumSet = EnumSet<MockCollectionEnum>(values: expected)
8793
let actual = enumSet.array()
88-
XCTAssertEqual(actual, expected)
94+
#expect(actual == expected)
8995
}
9096
}

Macros/Options/Tests/OptionsTests/MappedEnumTests.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,46 @@
2828
//
2929

3030
@testable import Options
31-
import XCTest
31+
import Testing
3232

33-
internal final class MappedEnumTests: XCTestCase {
33+
@Suite
34+
internal struct MappedEnumTests {
3435
private static let text = "\"a\""
35-
internal func testDecoder() throws {
36+
37+
@Test
38+
internal func decoder() throws {
3639
// swiftlint:disable:next force_unwrapping
3740
let data = Self.text.data(using: .utf8)!
3841
let decoder = JSONDecoder()
3942
let actual: MappedEnum<MockCollectionEnum>
4043
do {
4144
actual = try decoder.decode(MappedEnum<MockCollectionEnum>.self, from: data)
4245
} catch {
43-
XCTAssertNil(error)
46+
Issue.record("Unexpected error: \(error)")
4447
return
4548
}
46-
XCTAssertEqual(actual.value, .a)
49+
#expect(actual.value == .a)
4750
}
4851

49-
internal func testEncoder() throws {
52+
@Test
53+
internal func encoder() throws {
5054
let encoder = JSONEncoder()
5155
let describedEnum: MappedEnum<MockCollectionEnum> = .init(value: .a)
5256
let data: Data
5357
do {
5458
data = try encoder.encode(describedEnum)
5559
} catch {
56-
XCTAssertNil(error)
60+
Issue.record("Unexpected error: \(error)")
5761
return
5862
}
5963

6064
let dataText = String(bytes: data, encoding: .utf8)
6165

6266
guard let text = dataText else {
63-
XCTAssertNotNil(dataText)
67+
Issue.record("Failed to convert data to string")
6468
return
6569
}
6670

67-
XCTAssertEqual(text, Self.text)
71+
#expect(text == Self.text)
6872
}
6973
}

Macros/Options/Tests/OptionsTests/MappedValueCollectionRepresentedTests.swift

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,65 @@
2828
//
2929

3030
@testable import Options
31-
import XCTest
32-
33-
internal final class MappedValueCollectionRepresentedTests: XCTestCase {
34-
internal func testRawValue() {
35-
try XCTAssertEqual(MockCollectionEnum.rawValue(basedOn: "a"), 0)
36-
try XCTAssertEqual(MockCollectionEnum.rawValue(basedOn: "b"), 1)
37-
try XCTAssertEqual(MockCollectionEnum.rawValue(basedOn: "c"), 2)
38-
try XCTAssertEqual(MockCollectionEnum.rawValue(basedOn: "d"), 3)
31+
import Testing
32+
33+
@Suite
34+
internal struct MappedValueCollectionRepresentedTests {
35+
@Test
36+
internal func rawValue() throws {
37+
#expect(try MockCollectionEnum.rawValue(basedOn: "a") == 0)
38+
#expect(try MockCollectionEnum.rawValue(basedOn: "b") == 1)
39+
#expect(try MockCollectionEnum.rawValue(basedOn: "c") == 2)
40+
#expect(try MockCollectionEnum.rawValue(basedOn: "d") == 3)
3941
}
4042

41-
internal func testString() {
42-
try XCTAssertEqual(MockCollectionEnum.mappedValue(basedOn: 0), "a")
43-
try XCTAssertEqual(MockCollectionEnum.mappedValue(basedOn: 1), "b")
44-
try XCTAssertEqual(MockCollectionEnum.mappedValue(basedOn: 2), "c")
45-
try XCTAssertEqual(MockCollectionEnum.mappedValue(basedOn: 3), "d")
43+
@Test
44+
internal func string() throws {
45+
#expect(try MockCollectionEnum.mappedValue(basedOn: 0) == "a")
46+
#expect(try MockCollectionEnum.mappedValue(basedOn: 1) == "b")
47+
#expect(try MockCollectionEnum.mappedValue(basedOn: 2) == "c")
48+
#expect(try MockCollectionEnum.mappedValue(basedOn: 3) == "d")
4649
}
4750

48-
internal func testRawValueFailure() {
51+
@Test
52+
internal func rawValueFailure() {
4953
let caughtError: MappedValueRepresentableError?
5054
do {
5155
_ = try MockCollectionEnum.rawValue(basedOn: "e")
5256
caughtError = nil
5357
} catch let error as MappedValueRepresentableError {
5458
caughtError = error
5559
} catch {
56-
XCTAssertNil(error)
60+
Issue.record("Unexpected error: \(error)")
5761
caughtError = nil
5862
}
5963

60-
XCTAssertEqual(caughtError, .valueNotFound)
64+
#expect(caughtError == .valueNotFound)
6165
}
6266

63-
internal func testStringFailure() {
67+
@Test
68+
internal func stringFailure() {
6469
let caughtError: MappedValueRepresentableError?
6570
do {
6671
_ = try MockCollectionEnum.mappedValue(basedOn: .max)
6772
caughtError = nil
6873
} catch let error as MappedValueRepresentableError {
6974
caughtError = error
7075
} catch {
71-
XCTAssertNil(error)
76+
Issue.record("Unexpected error: \(error)")
7277
caughtError = nil
7378
}
7479

75-
XCTAssertEqual(caughtError, .valueNotFound)
80+
#expect(caughtError == .valueNotFound)
7681
}
7782

78-
internal func testCodingOptions() {
79-
XCTAssertEqual(MockDictionaryEnum.codingOptions, .default)
83+
@Test
84+
internal func codingOptions() {
85+
#expect(MockDictionaryEnum.codingOptions == .default)
8086
}
8187

82-
internal func testInvalidRaw() throws {
88+
@Test
89+
internal func invalidRaw() throws {
8390
let rawValue = Int.random(in: 5 ... 1_000)
8491

8592
let rawValueJSON = "\(rawValue)"
@@ -89,16 +96,18 @@ internal final class MappedValueCollectionRepresentedTests: XCTestCase {
8996
let decodingError: DecodingError
9097
do {
9198
let value = try Self.decoder.decode(MockCollectionEnum.self, from: rawValueJSONData)
92-
XCTAssertNil(value)
99+
Issue.record("Expected decoding to fail but got value: \(value)")
93100
return
94101
} catch let error as DecodingError {
95102
decodingError = error
96103
}
97104

98-
XCTAssertNotNil(decodingError)
105+
// Expect that we caught a decoding error (test passes if we reach here)
106+
_ = decodingError
99107
}
100108

101-
internal func testCodable() throws {
109+
@Test
110+
internal func codable() throws {
102111
let argumentSets = MockCollectionEnum.allCases.flatMap {
103112
[($0, true), ($0, false)]
104113
}.flatMap {
@@ -143,15 +152,15 @@ internal final class MappedValueCollectionRepresentedTests: XCTestCase {
143152

144153
switch (allowMappedValue, mappedDecodeResult) {
145154
case (true, let .success(actualMappedDecodedValue)):
146-
XCTAssertEqual(actualMappedDecodedValue, value)
155+
#expect(actualMappedDecodedValue == value)
147156
case (false, let .failure(error)):
148-
XCTAssert(error is DecodingError)
157+
#expect(error is DecodingError)
149158
default:
150-
XCTFail("Unmatched situation \(allowMappedValue): \(mappedDecodeResult)")
159+
Issue.record("Unmatched situation \(allowMappedValue): \(mappedDecodeResult)")
151160
}
152161

153-
XCTAssertEqual(actualRawValueDecoded, value)
162+
#expect(actualRawValueDecoded == value)
154163

155-
XCTAssertEqual(actualEncodedJSON, encodeAsMappedValue ? mappedValueJSONData : rawValueJSONData)
164+
#expect(actualEncodedJSON == (encodeAsMappedValue ? mappedValueJSONData : rawValueJSONData))
156165
}
157166
}

Macros/Options/Tests/OptionsTests/MappedValueDictionaryRepresentedTests.swift

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,50 +28,55 @@
2828
//
2929

3030
@testable import Options
31-
import XCTest
31+
import Testing
3232

33-
internal final class MappedValueDictionaryRepresentedTests: XCTestCase {
34-
internal func testRawValue() {
35-
try XCTAssertEqual(MockDictionaryEnum.rawValue(basedOn: "a"), 2)
36-
try XCTAssertEqual(MockDictionaryEnum.rawValue(basedOn: "b"), 5)
37-
try XCTAssertEqual(MockDictionaryEnum.rawValue(basedOn: "c"), 6)
38-
try XCTAssertEqual(MockDictionaryEnum.rawValue(basedOn: "d"), 12)
33+
@Suite
34+
internal struct MappedValueDictionaryRepresentedTests {
35+
@Test
36+
internal func rawValue() throws {
37+
#expect(try MockDictionaryEnum.rawValue(basedOn: "a") == 2)
38+
#expect(try MockDictionaryEnum.rawValue(basedOn: "b") == 5)
39+
#expect(try MockDictionaryEnum.rawValue(basedOn: "c") == 6)
40+
#expect(try MockDictionaryEnum.rawValue(basedOn: "d") == 12)
3941
}
4042

41-
internal func testString() {
42-
try XCTAssertEqual(MockDictionaryEnum.mappedValue(basedOn: 2), "a")
43-
try XCTAssertEqual(MockDictionaryEnum.mappedValue(basedOn: 5), "b")
44-
try XCTAssertEqual(MockDictionaryEnum.mappedValue(basedOn: 6), "c")
45-
try XCTAssertEqual(MockDictionaryEnum.mappedValue(basedOn: 12), "d")
43+
@Test
44+
internal func string() throws {
45+
#expect(try MockDictionaryEnum.mappedValue(basedOn: 2) == "a")
46+
#expect(try MockDictionaryEnum.mappedValue(basedOn: 5) == "b")
47+
#expect(try MockDictionaryEnum.mappedValue(basedOn: 6) == "c")
48+
#expect(try MockDictionaryEnum.mappedValue(basedOn: 12) == "d")
4649
}
4750

48-
internal func testRawValueFailure() {
51+
@Test
52+
internal func rawValueFailure() {
4953
let caughtError: MappedValueRepresentableError?
5054
do {
5155
_ = try MockDictionaryEnum.rawValue(basedOn: "e")
5256
caughtError = nil
5357
} catch let error as MappedValueRepresentableError {
5458
caughtError = error
5559
} catch {
56-
XCTAssertNil(error)
60+
Issue.record("Unexpected error: \(error)")
5761
caughtError = nil
5862
}
5963

60-
XCTAssertEqual(caughtError, .valueNotFound)
64+
#expect(caughtError == .valueNotFound)
6165
}
6266

63-
internal func testStringFailure() {
67+
@Test
68+
internal func stringFailure() {
6469
let caughtError: MappedValueRepresentableError?
6570
do {
6671
_ = try MockDictionaryEnum.mappedValue(basedOn: 0)
6772
caughtError = nil
6873
} catch let error as MappedValueRepresentableError {
6974
caughtError = error
7075
} catch {
71-
XCTAssertNil(error)
76+
Issue.record("Unexpected error: \(error)")
7277
caughtError = nil
7378
}
7479

75-
XCTAssertEqual(caughtError, .valueNotFound)
80+
#expect(caughtError == .valueNotFound)
7681
}
7782
}

Macros/Options/Tests/OptionsTests/MappedValueRepresentableTests.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
//
2929

3030
@testable import Options
31-
import XCTest
31+
import Testing
3232

33-
internal final class MappedValueRepresentableTests: XCTestCase {
34-
internal func testStringValue() {
35-
try XCTAssertEqual(MockCollectionEnum.a.mappedValue(), "a")
36-
try XCTAssertEqual(MockCollectionEnum.b.mappedValue(), "b")
37-
try XCTAssertEqual(MockCollectionEnum.c.mappedValue(), "c")
38-
try XCTAssertEqual(MockCollectionEnum.d.mappedValue(), "d")
33+
@Suite
34+
internal struct MappedValueRepresentableTests {
35+
@Test
36+
internal func stringValue() throws {
37+
#expect(try MockCollectionEnum.a.mappedValue() == "a")
38+
#expect(try MockCollectionEnum.b.mappedValue() == "b")
39+
#expect(try MockCollectionEnum.c.mappedValue() == "c")
40+
#expect(try MockCollectionEnum.d.mappedValue() == "d")
3941
}
4042
}

0 commit comments

Comments
 (0)