Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for lenses #38

Closed
wants to merge 25 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dd909a5
Progress on pipes.
nedtwigg Sep 18, 2023
d1f68d2
Merge branch 'main' into feat/pipes
nedtwigg Oct 13, 2023
edad89f
Rename SelfieConfig to SnapshotFileLayout.
nedtwigg Nov 3, 2023
55b9594
Settle on the `SelfieSettings` name.
nedtwigg Nov 3, 2023
a2dcd55
Put the layout and settings fields into the `Progress` class, and mak…
nedtwigg Nov 3, 2023
eb03066
Better javadoc.
nedtwigg Nov 3, 2023
b1a7538
Bump CI action versions to try to fix Windows CI.
nedtwigg Nov 3, 2023
5f52676
Snapshots are now routed through the pipeline infrastructure.
nedtwigg Nov 3, 2023
46bf863
Merge branch 'main' into feat/pipes
nedtwigg Nov 21, 2023
b6356aa
Misc progress.
nedtwigg Dec 12, 2023
3abc144
Merge branch 'main' into feat/pipes
nedtwigg Dec 12, 2023
2bf9cf1
Fix Selfie API to be usable from Java.
nedtwigg Dec 16, 2023
d8cb0e4
Add the implicit pipeline into SelfieSettings.
nedtwigg Dec 16, 2023
496a6b8
Add error-checking for invalid stale snapshots.
nedtwigg Dec 16, 2023
fd3127c
If a class has any method (inherited or not) with a `Test` annotation…
nedtwigg Dec 16, 2023
74e18fa
Rename `SelfieSettings.kt` to `SelfieSettingsAPI.kt`.
nedtwigg Dec 16, 2023
de09cf9
Fix SelfieGC.classExistsAndHasTests for JUnit4.
nedtwigg Dec 16, 2023
16bd4de
spotlessApply
nedtwigg Dec 16, 2023
74ac2ee
Improve our callstack capture.
nedtwigg Dec 16, 2023
80305fd
Fix Gradle deprecation warnings.
nedtwigg Dec 16, 2023
d26c9dd
Handle the `selfie` -> `Selfie` name change.
nedtwigg Dec 16, 2023
05ab49a
Close the unclosed AutoCloseable in the UnderTest harness.
nedtwigg Dec 17, 2023
79cca66
Make the UT match their final state at the end of the test.
nedtwigg Dec 17, 2023
57245ec
The snapshots are both output and input, for the test harness best if…
nedtwigg Dec 17, 2023
cc28cdf
The undertest-junit5 files are an input to selfie-runner-junit5
nedtwigg Dec 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Put the layout and settings fields into the Progress class, and mak…
…e it available to `ClassProgress` instances too.
  • Loading branch information
nedtwigg committed Nov 3, 2023
commit a2dcd55bb807c066c95efd3c346fab5d7c7448c1
Original file line number Diff line number Diff line change
@@ -28,9 +28,6 @@ import org.junit.platform.launcher.TestPlan

/** Routes between `toMatchDisk()` calls and the snapshot file / pruning machinery. */
internal object Router {
private val settings = SelfieSettingsAPI.initialize()
internal val layout = SnapshotFileLayout.initialize(settings)

private class ClassMethod(val clazz: ClassProgress, val method: String)
private val threadCtx = ThreadLocal<ClassMethod?>()
fun readOrWriteOrKeep(snapshot: Snapshot?, subOrKeepAll: String?): Snapshot? {
@@ -74,13 +71,10 @@ internal object Router {
}
threadCtx.set(null)
}
fun fileLocationFor(className: String): Path {
return layout.snapshotPathForClass(className)
}
}

/** Tracks the progress of test runs within a single class, so that snapshots can be pruned. */
internal class ClassProgress(val className: String) {
internal class ClassProgress(val parent: Progress, val className: String) {
companion object {
val TERMINATED =
ArrayMap.empty<String, MethodSnapshotGC>().plus(" ~ f!n1shed ~ ", MethodSnapshotGC())
@@ -111,7 +105,7 @@ internal class ClassProgress(val className: String) {
MethodSnapshotGC.findStaleSnapshotsWithin(className, file!!.snapshots, methods)
if (staleSnapshotIndices.isNotEmpty() || file!!.wasSetAtTestTime) {
file!!.removeAllIndices(staleSnapshotIndices)
val snapshotPath = Router.fileLocationFor(className)
val snapshotPath = parent.layout.snapshotPathForClass(className)
if (file!!.snapshots.isEmpty()) {
deleteFileAndParentDirIfEmpty(snapshotPath)
} else {
@@ -125,7 +119,7 @@ internal class ClassProgress(val className: String) {
// we never read or wrote to the file
val isStale = MethodSnapshotGC.isUnusedSnapshotFileStale(className, methods, success)
if (isStale) {
val snapshotFile = Router.fileLocationFor(className)
val snapshotFile = parent.layout.snapshotPathForClass(className)
deleteFileAndParentDirIfEmpty(snapshotFile)
}
}
@@ -150,10 +144,7 @@ internal class ClassProgress(val className: String) {
methods[method]!!.keepSuffix(suffix)
read().setAtTestTime(key, snapshot)
}
@Synchronized fun read(
method: String,
suffix: String,
): Snapshot? {
@Synchronized fun read(method: String, suffix: String): Snapshot? {
assertNotTerminated()
val snapshot = read().snapshots["$method$suffix"]
if (snapshot != null) {
@@ -163,13 +154,13 @@ internal class ClassProgress(val className: String) {
}
private fun read(): SnapshotFile {
if (file == null) {
val snapshotPath = Router.fileLocationFor(className)
val snapshotPath = parent.layout.snapshotPathForClass(className)
file =
if (Files.exists(snapshotPath) && Files.isRegularFile(snapshotPath)) {
val content = Files.readAllBytes(snapshotPath)
SnapshotFile.parse(SnapshotValueReader.of(content))
} else {
SnapshotFile.createEmptyWithUnixNewlines(Router.layout.unixNewlines)
SnapshotFile.createEmptyWithUnixNewlines(parent.layout.unixNewlines)
}
}
return file!!
@@ -181,14 +172,17 @@ internal class ClassProgress(val className: String) {
* - pruning unused snapshot files
*/
internal class Progress {
val settings = SelfieSettingsAPI.initialize()
val layout = SnapshotFileLayout.initialize(settings)

private var progressPerClass = ArrayMap.empty<String, ClassProgress>()
private fun forClass(className: String) = synchronized(this) { progressPerClass[className]!! }

// TestExecutionListener
fun start(className: String, method: String?) {
if (method == null) {
synchronized(this) {
progressPerClass = progressPerClass.plus(className, ClassProgress(className))
progressPerClass = progressPerClass.plus(className, ClassProgress(this, className))
}
} else {
forClass(className).startMethod(method)
@@ -212,10 +206,8 @@ internal class Progress {
}
}
fun finishedAllTests() {
Router.layout?.let { layout ->
for (stale in findStaleSnapshotFiles(layout)) {
deleteFileAndParentDirIfEmpty(layout.snapshotPathForClass(stale))
}
for (stale in findStaleSnapshotFiles(layout)) {
deleteFileAndParentDirIfEmpty(layout.snapshotPathForClass(stale))
}
}
}
Loading