From ea63fe046f6488c333d8a4c33208a0331beb7d76 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 8 Jul 2024 15:34:59 -0400 Subject: [PATCH] more tests --- .../SnapshotsTraitTests.swift | 2 +- .../WithSnapshotTestingTests.swift | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 Tests/SnapshotTestingTests/WithSnapshotTestingTests.swift diff --git a/Tests/SnapshotTestingTests/SnapshotsTraitTests.swift b/Tests/SnapshotTestingTests/SnapshotsTraitTests.swift index 7eb35ebf..a3a7ad2f 100644 --- a/Tests/SnapshotTestingTests/SnapshotsTraitTests.swift +++ b/Tests/SnapshotTestingTests/SnapshotsTraitTests.swift @@ -36,7 +36,7 @@ struct SnapshotsTraitTests { #expect(SnapshotTestingConfiguration.current?.record == .all) } - @Suite(.snapshots(diffTool: "diff", record: .failed)) + @Suite(.snapshots(record: .failed, diffTool: "diff")) struct OverrideDiffToolAndRecord { @Test func config() { diff --git a/Tests/SnapshotTestingTests/WithSnapshotTestingTests.swift b/Tests/SnapshotTestingTests/WithSnapshotTestingTests.swift new file mode 100644 index 00000000..b6f6c6f5 --- /dev/null +++ b/Tests/SnapshotTestingTests/WithSnapshotTestingTests.swift @@ -0,0 +1,35 @@ +import XCTest + +@_spi(Internals) @testable import SnapshotTesting + +class WithSnapshotTestingTests: XCTestCase { + func testNesting() { + withSnapshotTesting(record: .all) { + XCTAssertEqual( + SnapshotTestingConfiguration.current? + .diffTool?(currentFilePath: "old.png", failedFilePath: "new.png"), + """ + @− + "file://old.png" + @+ + "file://new.png" + + To configure output for a custom diff tool, use 'withSnapshotTesting'. For example: + + withSnapshotTesting(diffTool: .ksdiff) { + // ... + } + """ + ) + XCTAssertEqual(SnapshotTestingConfiguration.current?.record, .all) + withSnapshotTesting(diffTool: "ksdiff") { + XCTAssertEqual( + SnapshotTestingConfiguration.current? + .diffTool?(currentFilePath: "old.png", failedFilePath: "new.png"), + "ksdiff old.png new.png" + ) + XCTAssertEqual(SnapshotTestingConfiguration.current?.record, .all) + } + } + } +}