Skip to content

Commit f50405a

Browse files
authored
Do not remove stale snapshot files when readonly is true (#367)
2 parents 187cc70 + 87a6678 commit f50405a

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

jvm/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/SnapshotSystemJUnit5.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ internal object SnapshotSystemJUnit5 : SnapshotSystem {
111111
if (inlineWriteTracker.hasWrites()) {
112112
inlineWriteTracker.persistWrites(layout)
113113
}
114-
}
115-
for (stale in findStaleSnapshotFiles(layout)) {
116-
val staleFile = layout.snapshotPathForClass(stale)
117-
if (snapshotsFilesWrittenToDisk.contains(staleFile)) {
118-
throw AssertionError(
119-
"Selfie wrote a snapshot and then marked it stale for deletion in the same run: $staleFile\nSelfie will delete this snapshot on the next run, which is bad! Why is Selfie marking this snapshot as stale?")
120-
} else {
121-
deleteFileAndParentDirIfEmpty(staleFile)
114+
for (stale in findStaleSnapshotFiles(layout)) {
115+
val staleFile = layout.snapshotPathForClass(stale)
116+
if (snapshotsFilesWrittenToDisk.contains(staleFile)) {
117+
throw AssertionError(
118+
"Selfie wrote a snapshot and then marked it stale for deletion in the same run: $staleFile\nSelfie will delete this snapshot on the next run, which is bad! Why is Selfie marking this snapshot as stale?")
119+
} else {
120+
deleteFileAndParentDirIfEmpty(staleFile)
121+
}
122122
}
123123
}
124124
}

jvm/selfie-runner-kotest/src/commonMain/kotlin/com/diffplug/selfie/kotest/SnapshotSystemKotest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ internal class SnapshotSystemKotest(settings: SelfieSettingsAPI) : SnapshotSyste
9595
if (inlineWriteTracker.hasWrites()) {
9696
inlineWriteTracker.persistWrites(layout)
9797
}
98-
}
99-
for (stale in findStaleSnapshotFiles(layout)) {
100-
val staleFile = layout.snapshotPathForClassOrFilename(stale)
101-
if (snapshotsFilesWrittenToDisk.contains(staleFile)) {
102-
throw AssertionError(
103-
"Selfie wrote a snapshot and then marked it stale for deletion in the same run: $staleFile\nSelfie will delete this snapshot on the next run, which is bad! Why is Selfie marking this snapshot as stale?")
104-
} else {
105-
deleteFileAndParentDirIfEmpty(staleFile)
98+
for (stale in findStaleSnapshotFiles(layout)) {
99+
val staleFile = layout.snapshotPathForClassOrFilename(stale)
100+
if (snapshotsFilesWrittenToDisk.contains(staleFile)) {
101+
throw AssertionError(
102+
"Selfie wrote a snapshot and then marked it stale for deletion in the same run: $staleFile\nSelfie will delete this snapshot on the next run, which is bad! Why is Selfie marking this snapshot as stale?")
103+
} else {
104+
deleteFileAndParentDirIfEmpty(staleFile)
105+
}
106106
}
107107
}
108108
}

0 commit comments

Comments
 (0)