Skip to content

Commit ef9bf32

Browse files
authored
Add .customDump strategy and deprecate .dump (#948)
* Add `.customDump` strategy and deprecate `.dump` * Bump tools version * wip * wip
1 parent 008509a commit ef9bf32

File tree

6 files changed

+117
-18
lines changed

6 files changed

+117
-18
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ jobs:
2929
strategy:
3030
matrix:
3131
swift:
32-
- "5.7"
32+
- '5.9'
3333

34-
name: Ubuntu (Swift ${{ matrix.swift }})
35-
runs-on: ubuntu-20.04
34+
container: swift:${{ matrix.swift }}
35+
name: Linux (Swift ${{ matrix.swift }})
36+
runs-on: ubuntu-latest
3637
steps:
37-
- uses: swift-actions/setup-swift@v1
38-
with:
39-
swift-version: ${{ matrix.swift }}
40-
- uses: actions/checkout@v3
38+
- uses: actions/checkout@v4
4139
- run: swift test
4240

4341
windows:

Package.resolved

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.9
22

33
import PackageDescription
44

@@ -19,18 +19,34 @@ let package = Package(
1919
name: "InlineSnapshotTesting",
2020
targets: ["InlineSnapshotTesting"]
2121
),
22+
.library(
23+
name: "SnapshotTestingCustomDump",
24+
targets: ["SnapshotTestingCustomDump"]
25+
),
2226
],
2327
dependencies: [
24-
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease")
28+
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"),
29+
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0"),
2530
],
2631
targets: [
2732
.target(
2833
name: "SnapshotTesting"
2934
),
35+
.testTarget(
36+
name: "SnapshotTestingTests",
37+
dependencies: [
38+
"SnapshotTesting",
39+
],
40+
exclude: [
41+
"__Fixtures__",
42+
"__Snapshots__",
43+
]
44+
),
3045
.target(
3146
name: "InlineSnapshotTesting",
3247
dependencies: [
3348
"SnapshotTesting",
49+
"SnapshotTestingCustomDump",
3450
.product(name: "SwiftParser", package: "swift-syntax"),
3551
.product(name: "SwiftSyntax", package: "swift-syntax"),
3652
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
@@ -42,14 +58,11 @@ let package = Package(
4258
"InlineSnapshotTesting"
4359
]
4460
),
45-
.testTarget(
46-
name: "SnapshotTestingTests",
61+
.target(
62+
name: "SnapshotTestingCustomDump",
4763
dependencies: [
48-
"SnapshotTesting"
49-
],
50-
exclude: [
51-
"__Fixtures__",
52-
"__Snapshots__",
64+
"SnapshotTesting",
65+
.product(name: "CustomDump", package: "swift-custom-dump"),
5366
]
5467
),
5568
]

Sources/SnapshotTesting/Snapshotting/Any.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ extension Snapshotting where Format == String {
4141
/// - id: 1
4242
/// - name: "Blobby"
4343
/// ```
44+
@available(
45+
iOS,
46+
deprecated: 9999,
47+
message: "Use '.customDump' from the 'SnapshotTestingCustomDump' module, instead."
48+
)
49+
@available(
50+
macOS,
51+
deprecated: 9999,
52+
message: "Use '.customDump' from the 'SnapshotTestingCustomDump' module, instead."
53+
)
54+
@available(
55+
tvOS,
56+
deprecated: 9999,
57+
message: "Use '.customDump' from the 'SnapshotTestingCustomDump' module, instead."
58+
)
59+
@available(
60+
watchOS,
61+
deprecated: 9999,
62+
message: "Use '.customDump' from the 'SnapshotTestingCustomDump' module, instead."
63+
)
4464
public static var dump: Snapshotting {
4565
return SimplySnapshotting.lines.pullback { snap($0) }
4666
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import CustomDump
2+
import SnapshotTesting
3+
4+
extension Snapshotting where Format == String {
5+
/// A snapshot strategy for comparing any structure based on a
6+
/// [custom dump](https://github.com/pointfreeco/swift-custom-dump).
7+
///
8+
/// ```swift
9+
/// assertSnapshot(of: user, as: .customDump)
10+
/// ```
11+
///
12+
/// Records:
13+
///
14+
/// ```
15+
/// User(
16+
/// bio: "Blobbed around the world.",
17+
/// id: 1,
18+
/// name: "Blobby"
19+
/// )
20+
/// ```
21+
public static var customDump: Snapshotting {
22+
SimplySnapshotting.lines.pullback(String.init(customDumping:))
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if canImport(Testing)
2+
import Testing
3+
import InlineSnapshotTesting
4+
import SnapshotTestingCustomDump
5+
6+
@Suite(
7+
.snapshots(
8+
record: .missing
9+
)
10+
)
11+
struct CustomDumpSnapshotTests {
12+
@Test func basics() {
13+
struct User { let id: Int, name: String, bio: String }
14+
let user = User(id: 1, name: "Blobby", bio: "Blobbed around the world.")
15+
assertInlineSnapshot(of: user, as: .customDump) {
16+
"""
17+
CustomDumpSnapshotTests.User(
18+
id: 1,
19+
name: "Blobby",
20+
bio: "Blobbed around the world."
21+
)
22+
"""
23+
}
24+
}
25+
}
26+
#endif

0 commit comments

Comments
 (0)