Skip to content

Commit b3458b1

Browse files
authored
Support for Swift 6.1 TestScoping. (#965)
* Support for Swift 6.1 TestScoping. * wip * wip * clean up * Disable windows ci for now.
1 parent 0a18d39 commit b3458b1

18 files changed

+243
-151
lines changed

.github/workflows/ci.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,29 @@ jobs:
3838
- uses: actions/checkout@v4
3939
- run: swift test
4040

41-
windows:
42-
strategy:
43-
matrix:
44-
swift:
45-
- "5.9.1"
41+
# windows:
42+
# strategy:
43+
# matrix:
44+
# swift:
45+
# - "5.9.1"
4646

47-
name: Windows (Swift ${{ matrix.swift }})
48-
runs-on: windows-latest
47+
# name: Windows (Swift ${{ matrix.swift }})
48+
# runs-on: windows-latest
4949

50-
steps:
51-
- uses: compnerd/gha-setup-swift@main
52-
with:
53-
branch: swift-${{ matrix.swift }}-release
54-
tag: ${{ matrix.swift }}-RELEASE
50+
# steps:
51+
# - uses: compnerd/gha-setup-swift@main
52+
# with:
53+
# branch: swift-${{ matrix.swift }}-release
54+
# tag: ${{ matrix.swift }}-RELEASE
5555

56-
- name: Set git to use LF
57-
run: |
58-
git config --global core.autocrlf false
59-
git config --global core.eol lf
56+
# - name: Set git to use LF
57+
# run: |
58+
# git config --global core.autocrlf false
59+
# git config --global core.eol lf
6060

61-
- uses: actions/checkout@v4
62-
- run: swift build
63-
- run: swift test
61+
# - uses: actions/checkout@v4
62+
# - run: swift build
63+
# - run: swift test
6464

6565
android:
6666
strategy:

[email protected]

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// swift-tools-version:6.0
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-snapshot-testing",
7+
platforms: [
8+
.iOS(.v13),
9+
.macOS(.v10_15),
10+
.tvOS(.v13),
11+
.watchOS(.v6),
12+
],
13+
products: [
14+
.library(
15+
name: "SnapshotTesting",
16+
targets: ["SnapshotTesting"]
17+
),
18+
.library(
19+
name: "InlineSnapshotTesting",
20+
targets: ["InlineSnapshotTesting"]
21+
),
22+
.library(
23+
name: "SnapshotTestingCustomDump",
24+
targets: ["SnapshotTestingCustomDump"]
25+
),
26+
],
27+
dependencies: [
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"),
30+
],
31+
targets: [
32+
.target(
33+
name: "SnapshotTesting"
34+
),
35+
.testTarget(
36+
name: "SnapshotTestingTests",
37+
dependencies: [
38+
"SnapshotTesting"
39+
],
40+
exclude: [
41+
"__Fixtures__",
42+
"__Snapshots__",
43+
]
44+
),
45+
.target(
46+
name: "InlineSnapshotTesting",
47+
dependencies: [
48+
"SnapshotTesting",
49+
"SnapshotTestingCustomDump",
50+
.product(name: "SwiftParser", package: "swift-syntax"),
51+
.product(name: "SwiftSyntax", package: "swift-syntax"),
52+
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
53+
]
54+
),
55+
.testTarget(
56+
name: "InlineSnapshotTestingTests",
57+
dependencies: [
58+
"InlineSnapshotTesting"
59+
]
60+
),
61+
.target(
62+
name: "SnapshotTestingCustomDump",
63+
dependencies: [
64+
"SnapshotTesting",
65+
.product(name: "CustomDump", package: "swift-custom-dump"),
66+
]
67+
),
68+
],
69+
swiftLanguageModes: [.v5]
70+
)

Sources/SnapshotTesting/SnapshotsTestTrait.swift

+22-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#if canImport(Testing)
22
import Testing
33

4+
/// A type representing the configuration of snapshot testing.
5+
public struct _SnapshotsTestTrait: SuiteTrait, TestTrait {
6+
public let isRecursive = true
7+
let configuration: SnapshotTestingConfiguration
8+
}
9+
410
extension Trait where Self == _SnapshotsTestTrait {
511
/// Configure snapshot testing in a suite or test.
612
///
@@ -29,22 +35,20 @@
2935
}
3036
}
3137

32-
/// A type representing the configuration of snapshot testing.
33-
public struct _SnapshotsTestTrait: SuiteTrait, TestTrait {
34-
public let isRecursive = true
35-
let configuration: SnapshotTestingConfiguration
36-
37-
// public func execute(
38-
// _ function: @escaping () async throws -> Void,
39-
// for test: Test,
40-
// testCase: Test.Case?
41-
// ) async throws {
42-
// try await withSnapshotTesting(
43-
// record: configuration.record,
44-
// diffTool: configuration.diffTool
45-
// ) {
46-
// try await function()
47-
// }
48-
// }
49-
}
38+
#if compiler(>=6.1)
39+
extension _SnapshotsTestTrait: TestScoping {
40+
public func provideScope(
41+
for test: Test,
42+
testCase: Test.Case?,
43+
performing function: () async throws -> Void
44+
) async throws {
45+
try await withSnapshotTesting(
46+
record: configuration.record,
47+
diffTool: configuration.diffTool
48+
) {
49+
try await function()
50+
}
51+
}
52+
}
53+
#endif
5054
#endif

0 commit comments

Comments
 (0)