@@ -17,13 +17,15 @@ package com.diffplug.selfie.junit5
17
17
18
18
import com.diffplug.selfie.*
19
19
import com.diffplug.selfie.guts.CallStack
20
+ import com.diffplug.selfie.guts.CommentTracker
20
21
import com.diffplug.selfie.guts.DiskWriteTracker
21
22
import com.diffplug.selfie.guts.FS
22
23
import com.diffplug.selfie.guts.InlineWriteTracker
23
24
import com.diffplug.selfie.guts.LiteralValue
24
25
import com.diffplug.selfie.guts.Path
25
26
import com.diffplug.selfie.guts.SnapshotFileLayout
26
27
import com.diffplug.selfie.guts.SnapshotStorage
28
+ import com.diffplug.selfie.guts.SourceFile
27
29
import java.nio.charset.StandardCharsets
28
30
import java.nio.file.Files
29
31
import java.util.concurrent.ConcurrentSkipListSet
@@ -75,16 +77,17 @@ internal object SnapshotStorageJUnit5 : SnapshotStorage {
75
77
@JvmStatic fun initStorage (): SnapshotStorage = this
76
78
override val fs = FSJava
77
79
override val mode = calcMode()
78
- override fun sourceFileHasWritableComment (call : CallStack ): Boolean {
79
- TODO (" Not yet implemented" )
80
- }
81
80
82
81
private class ClassMethod (val clazz : ClassProgress , val method : String )
83
82
private val threadCtx = ThreadLocal <ClassMethod ?>()
84
83
private fun classAndMethod () =
85
84
threadCtx.get()
86
85
? : throw AssertionError (
87
86
" Selfie `toMatchDisk` must be called only on the original thread." )
87
+ override fun sourceFileHasWritableComment (call : CallStack ): Boolean {
88
+ val cm = classAndMethod()
89
+ return cm.clazz.parent.commentTracker!! .hasWritableComment(call, cm.clazz.parent.layout)
90
+ }
88
91
private fun suffix (sub : String ) = if (sub == " " ) " " else " /$sub "
89
92
override fun readDisk (sub : String , call : CallStack ): Snapshot ? {
90
93
val cm = classAndMethod()
@@ -245,6 +248,7 @@ internal class ClassProgress(val parent: Progress, val className: String) {
245
248
internal class Progress {
246
249
val settings = SelfieSettingsAPI .initialize()
247
250
val layout = SnapshotFileLayoutJUnit5 (settings, SnapshotStorageJUnit5 .fs)
251
+ var commentTracker: CommentTracker ? = CommentTracker ()
248
252
249
253
private var progressPerClass = ArrayMap .empty<String , ClassProgress >()
250
254
private fun forClass (className : String ) = synchronized(this ) { progressPerClass[className]!! }
@@ -286,6 +290,14 @@ internal class Progress {
286
290
written.add(path)
287
291
}
288
292
fun finishedAllTests () {
293
+ val paths = commentTracker!! .pathsWithOnce()
294
+ commentTracker = null
295
+ for (path in paths) {
296
+ val source = SourceFile (layout.fs.name(path), layout.fs.fileRead(path))
297
+ source.removeSelfieOnceComments()
298
+ layout.fs.fileWrite(path, source.asString)
299
+ }
300
+
289
301
val written =
290
302
checkForInvalidStale.getAndSet(null )
291
303
? : throw AssertionError (" finishedAllTests() was called more than once." )
0 commit comments