@@ -389,23 +389,25 @@ extension XCTest {
389
389
test: StaticString = #function,
390
390
file: StaticString = #filePath,
391
391
line: UInt = #line
392
- ) throws -> String {
392
+ ) throws -> String ? {
393
393
let snapshotDirectoryURL = URL ( fileURLWithPath: " \( file) " )
394
394
. deletingLastPathComponent ( )
395
395
. appendingPathComponent ( " Snapshots " )
396
396
let snapshotFileURL = snapshotDirectoryURL
397
397
. appendingPathComponent ( " \( test) . \( `extension`) " )
398
398
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 {
400
403
let recordedValue = actual + " \n "
401
404
try FileManager . default. createDirectory (
402
405
at: snapshotDirectoryURL,
403
406
withIntermediateDirectories: true ,
404
407
attributes: nil )
405
408
try recordedValue. write ( to: snapshotFileURL, atomically: true , encoding: . utf8)
406
409
XCTFail ( " Recorded new baseline " , file: file, line: line)
407
- struct EarlyExit : Error { }
408
- throw EarlyExit ( )
410
+ return nil
409
411
} else {
410
412
let expected = try String ( contentsOf: snapshotFileURL, encoding: . utf8)
411
413
AssertEqualStrings (
@@ -513,6 +515,8 @@ extension XCTest {
513
515
file: file,
514
516
line: line)
515
517
518
+ guard let expected else { return }
519
+
516
520
try AssertJSONEqualFromString (
517
521
actual: actual,
518
522
expected: expected,
0 commit comments