Skip to content

Commit d289cb5

Browse files
committed
Convert some tests to Swift Testing
1 parent 83e1914 commit d289cb5

10 files changed

+522
-568
lines changed

Tests/NukeTests/ImageProcessorsTests/AnonymousTests.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,48 @@
22
//
33
// Copyright (c) 2015-2026 Alexander Grebenyuk (github.com/kean).
44

5-
import XCTest
5+
import Testing
66
@testable import Nuke
77

88
#if !os(macOS)
99
import UIKit
1010
#endif
1111

12-
class ImageProcessorsAnonymousTests: XCTestCase {
12+
@Suite struct ImageProcessorsAnonymousTests {
1313

14-
func testAnonymousProcessorsHaveDifferentIdentifiers() {
15-
XCTAssertEqual(
16-
ImageProcessors.Anonymous(id: "1", { $0 }).identifier,
14+
@Test func anonymousProcessorsHaveDifferentIdentifiers() {
15+
#expect(
16+
ImageProcessors.Anonymous(id: "1", { $0 }).identifier ==
1717
ImageProcessors.Anonymous(id: "1", { $0 }).identifier
1818
)
19-
XCTAssertNotEqual(
20-
ImageProcessors.Anonymous(id: "1", { $0 }).identifier,
19+
#expect(
20+
ImageProcessors.Anonymous(id: "1", { $0 }).identifier !=
2121
ImageProcessors.Anonymous(id: "2", { $0 }).identifier
2222
)
2323
}
2424

25-
func testAnonymousProcessorsHaveDifferentHashableIdentifiers() {
26-
XCTAssertEqual(
27-
ImageProcessors.Anonymous(id: "1", { $0 }).hashableIdentifier,
25+
@Test func anonymousProcessorsHaveDifferentHashableIdentifiers() {
26+
#expect(
27+
ImageProcessors.Anonymous(id: "1", { $0 }).hashableIdentifier ==
2828
ImageProcessors.Anonymous(id: "1", { $0 }).hashableIdentifier
2929
)
30-
XCTAssertNotEqual(
31-
ImageProcessors.Anonymous(id: "1", { $0 }).hashableIdentifier,
30+
#expect(
31+
ImageProcessors.Anonymous(id: "1", { $0 }).hashableIdentifier !=
3232
ImageProcessors.Anonymous(id: "2", { $0 }).hashableIdentifier
3333
)
3434
}
3535

36-
func testAnonymousProcessorIsApplied() throws {
36+
@Test func anonymousProcessorIsApplied() throws {
3737
// Given
3838
let processor = ImageProcessors.Anonymous(id: "1") {
3939
$0.nk_test_processorIDs = ["1"]
4040
return $0
4141
}
4242

4343
// When
44-
let image = try XCTUnwrap(processor.process(Test.image))
44+
let image = try #require(processor.process(Test.image))
4545

4646
// Then
47-
XCTAssertEqual(image.nk_test_processorIDs, ["1"])
47+
#expect(image.nk_test_processorIDs == ["1"])
4848
}
4949
}

Tests/NukeTests/ImageProcessorsTests/CircleTests.swift

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// Copyright (c) 2015-2026 Alexander Grebenyuk (github.com/kean).
44

5+
import Testing
56
import XCTest
67
@testable import Nuke
78

@@ -10,133 +11,131 @@ import XCTest
1011
#endif
1112

1213
#if os(iOS) || os(tvOS) || os(visionOS)
13-
class ImageProcessorsCircleTests: XCTestCase {
14+
@Suite struct ImageProcessorsCircleTests {
1415

15-
func _testThatImageIsCroppedToSquareAutomatically() throws {
16+
@Test(.disabled()) func thatImageIsCroppedToSquareAutomatically() throws {
1617
// Given
1718
let input = Test.image(named: "fixture-tiny.jpeg")
1819
let processor = ImageProcessors.Circle()
1920

2021
// When
21-
let output = try XCTUnwrap(processor.process(input), "Failed to process an image")
22+
let output = try #require(processor.process(input), "Failed to process an image")
2223

2324
// Then
24-
XCTAssertEqual(output.sizeInPixels, CGSize(width: 150, height: 150))
25+
#expect(output.sizeInPixels == CGSize(width: 150, height: 150))
2526
XCTAssertEqualImages(output, Test.image(named: "s-circle.png"))
2627
}
2728

28-
func _testThatBorderIsAdded() throws {
29+
@Test(.disabled()) func thatBorderIsAdded() throws {
2930
// Given
3031
let input = Test.image(named: "fixture-tiny.jpeg")
3132
let border = ImageProcessingOptions.Border(color: .red, width: 4, unit: .pixels)
3233
let processor = ImageProcessors.Circle(border: border)
3334

3435
// When
35-
let output = try XCTUnwrap(processor.process(input), "Failed to process an image")
36+
let output = try #require(processor.process(input), "Failed to process an image")
3637

3738
// Then
38-
XCTAssertEqual(output.sizeInPixels, CGSize(width: 150, height: 150))
39+
#expect(output.sizeInPixels == CGSize(width: 150, height: 150))
3940
XCTAssertEqualImages(output, Test.image(named: "s-circle-border.png"))
4041
}
4142

42-
func testExtendedColorSpaceSupport() throws {
43+
@Test func extendedColorSpaceSupport() throws {
4344
// Given
4445
let input = Test.image(named: "image-p3", extension: "jpg")
4546
let border = ImageProcessingOptions.Border(color: .red, width: 4, unit: .pixels)
4647
let processor = ImageProcessors.Circle(border: border)
4748

4849
// When
49-
let output = try XCTUnwrap(processor.process(input), "Failed to process an image")
50+
let output = try #require(processor.process(input), "Failed to process an image")
5051

5152
// Then image is resized but isn't cropped
52-
let colorSpace = try XCTUnwrap(output.cgImage?.colorSpace)
53-
XCTAssertTrue(colorSpace.isWideGamutRGB)
53+
let colorSpace = try #require(output.cgImage?.colorSpace)
54+
#expect(colorSpace.isWideGamutRGB)
5455
}
5556

56-
@MainActor
57-
func testIdentifierEqual() throws {
58-
XCTAssertEqual(
59-
ImageProcessors.Circle().identifier,
57+
@Test @MainActor func identifierEqual() throws {
58+
#expect(
59+
ImageProcessors.Circle().identifier ==
6060
ImageProcessors.Circle().identifier
6161
)
62-
XCTAssertEqual(
63-
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).identifier,
62+
#expect(
63+
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).identifier ==
6464
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).identifier
6565
)
66-
XCTAssertEqual(
67-
ImageProcessors.Circle(border: .init(color: .red, width: 4, unit: .pixels)).identifier,
66+
#expect(
67+
ImageProcessors.Circle(border: .init(color: .red, width: 4, unit: .pixels)).identifier ==
6868
ImageProcessors.Circle(border: .init(color: .red, width: 4 / Screen.scale, unit: .points)).identifier
6969
)
7070
}
7171

72-
func testIdentifierNotEqual() throws {
73-
XCTAssertNotEqual(
74-
ImageProcessors.Circle().identifier,
72+
@Test func identifierNotEqual() throws {
73+
#expect(
74+
ImageProcessors.Circle().identifier !=
7575
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).identifier
7676
)
77-
XCTAssertNotEqual(
78-
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).identifier,
77+
#expect(
78+
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).identifier !=
7979
ImageProcessors.Circle(border: .init(color: .red, width: 4, unit: .pixels)).identifier
8080
)
81-
XCTAssertNotEqual(
82-
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).identifier,
81+
#expect(
82+
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).identifier !=
8383
ImageProcessors.Circle(border: .init(color: .blue, width: 2, unit: .pixels)).identifier
8484
)
8585
}
8686

87-
@MainActor
88-
func testHashableIdentifierEqual() throws {
89-
XCTAssertEqual(
90-
ImageProcessors.Circle().hashableIdentifier,
87+
@Test @MainActor func hashableIdentifierEqual() throws {
88+
#expect(
89+
ImageProcessors.Circle().hashableIdentifier ==
9190
ImageProcessors.Circle().hashableIdentifier
9291
)
93-
XCTAssertEqual(
94-
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).hashableIdentifier,
92+
#expect(
93+
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).hashableIdentifier ==
9594
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).hashableIdentifier
9695
)
97-
XCTAssertEqual(
98-
ImageProcessors.Circle(border: .init(color: .red, width: 4, unit: .pixels)).hashableIdentifier,
96+
#expect(
97+
ImageProcessors.Circle(border: .init(color: .red, width: 4, unit: .pixels)).hashableIdentifier ==
9998
ImageProcessors.Circle(border: .init(color: .red, width: 4 / Screen.scale, unit: .points)).hashableIdentifier
10099
)
101100
}
102101

103-
func testHashableNotEqual() throws {
104-
XCTAssertNotEqual(
105-
ImageProcessors.Circle().identifier,
102+
@Test func hashableNotEqual() throws {
103+
#expect(
104+
AnyHashable(ImageProcessors.Circle().identifier) !=
106105
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).hashableIdentifier
107106
)
108-
XCTAssertNotEqual(
109-
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).hashableIdentifier,
107+
#expect(
108+
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).hashableIdentifier !=
110109
ImageProcessors.Circle(border: .init(color: .red, width: 4, unit: .pixels)).hashableIdentifier
111110
)
112-
XCTAssertNotEqual(
113-
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).hashableIdentifier,
111+
#expect(
112+
ImageProcessors.Circle(border: .init(color: .red, width: 2, unit: .pixels)).hashableIdentifier !=
114113
ImageProcessors.Circle(border: .init(color: .blue, width: 2, unit: .pixels)).hashableIdentifier
115114
)
116115
}
117116

118-
func testDescription() {
117+
@Test func description() {
119118
// Given
120119
let processor = ImageProcessors.Circle(border: .init(color: .blue, width: 2, unit: .pixels))
121120

122121
// Then
123-
XCTAssertEqual(processor.description, "Circle(border: Border(color: #0000FF, width: 2.0 pixels))")
122+
#expect(processor.description == "Circle(border: Border(color: #0000FF, width: 2.0 pixels))")
124123
}
125124

126-
func testDescriptionWithoutBorder() {
125+
@Test func descriptionWithoutBorder() {
127126
// Given
128127
let processor = ImageProcessors.Circle()
129128

130129
// Then
131-
XCTAssertEqual(processor.description, "Circle(border: nil)")
130+
#expect(processor.description == "Circle(border: nil)")
132131
}
133132

134-
func testColorToHex() {
133+
@Test func colorToHex() {
135134
// Given
136135
let color = UIColor.red
137136

138137
// Then
139-
XCTAssertEqual(color.hex, "#FF0000")
138+
#expect(color.hex == "#FF0000")
140139
}
141140
}
142141
#endif

0 commit comments

Comments
 (0)