Skip to content

Commit d3630e3

Browse files
authored
Move additional tests to snapshots (#700)
Moves some examples test to use snapshot files instead of inline multiline strings.
1 parent 45b5c74 commit d3630e3

File tree

5 files changed

+427
-435
lines changed

5 files changed

+427
-435
lines changed

Sources/ArgumentParserTestHelpers/TestHelpers.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,23 +389,25 @@ extension XCTest {
389389
test: StaticString = #function,
390390
file: StaticString = #filePath,
391391
line: UInt = #line
392-
) throws -> String {
392+
) throws -> String? {
393393
let snapshotDirectoryURL = URL(fileURLWithPath: "\(file)")
394394
.deletingLastPathComponent()
395395
.appendingPathComponent("Snapshots")
396396
let snapshotFileURL = snapshotDirectoryURL
397397
.appendingPathComponent("\(test).\(`extension`)")
398398

399-
if record || !FileManager.default.fileExists(atPath: snapshotFileURL.path) {
399+
let snapshotExists = FileManager.default.fileExists(atPath: snapshotFileURL.path)
400+
let recordEnvironment = ProcessInfo.processInfo.environment["RECORD_SNAPSHOTS"] != nil
401+
402+
if record || recordEnvironment || !snapshotExists {
400403
let recordedValue = actual + "\n"
401404
try FileManager.default.createDirectory(
402405
at: snapshotDirectoryURL,
403406
withIntermediateDirectories: true,
404407
attributes: nil)
405408
try recordedValue.write(to: snapshotFileURL, atomically: true, encoding: .utf8)
406409
XCTFail("Recorded new baseline", file: file, line: line)
407-
struct EarlyExit: Error {}
408-
throw EarlyExit()
410+
return nil
409411
} else {
410412
let expected = try String(contentsOf: snapshotFileURL, encoding: .utf8)
411413
AssertEqualStrings(
@@ -513,6 +515,8 @@ extension XCTest {
513515
file: file,
514516
line: line)
515517

518+
guard let expected else { return }
519+
516520
try AssertJSONEqualFromString(
517521
actual: actual,
518522
expected: expected,

0 commit comments

Comments
 (0)