-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from diffplug/feat/gc-within-method
"Sub" snapshots.
- Loading branch information
Showing
3 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
selfie-runner-junit5/src/test/kotlin/com/diffplug/selfie/junit5/WithinMethodGCTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright (C) 2023 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.selfie.junit5 | ||
|
||
import kotlin.test.Test | ||
import org.junit.jupiter.api.MethodOrderer | ||
import org.junit.jupiter.api.Order | ||
import org.junit.jupiter.api.TestMethodOrder | ||
import org.junitpioneer.jupiter.DisableIfTestFails | ||
|
||
/** Write-only test which asserts adding and removing snapshots results in same-class GC. */ | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation::class) | ||
@DisableIfTestFails | ||
class WithinMethodGCTest : Harness("undertest-junit5") { | ||
@Test @Order(1) | ||
fun noSelfiesNoFile() { | ||
ut_snapshot().deleteIfExists() | ||
ut_snapshot().assertDoesNotExist() | ||
ut_mirror().linesFrom("UT_WithinMethodGC").toLast("}").shrinkByOne().commentOut() | ||
} | ||
|
||
@Test @Order(2) | ||
fun rootOnly() { | ||
ut_mirror().linesFrom("fun selfie()").toFirst("}").uncomment() | ||
ut_mirror().lineWith("maple").commentOut() | ||
gradleWriteSS() | ||
ut_snapshot() | ||
.assertContent( | ||
""" | ||
╔═ selfie ═╗ | ||
root | ||
╔═ [end of file] ═╗ | ||
""" | ||
.trimIndent()) | ||
} | ||
|
||
@Test @Order(3) | ||
fun rootAndLeaf() { | ||
ut_mirror().lineWith("maple").uncomment() | ||
gradleWriteSS() | ||
ut_snapshot() | ||
.assertContent( | ||
""" | ||
╔═ selfie ═╗ | ||
root | ||
╔═ selfie/leaf ═╗ | ||
maple | ||
╔═ [end of file] ═╗ | ||
""" | ||
.trimIndent()) | ||
} | ||
|
||
@Test @Order(4) | ||
fun leafOnly() { | ||
ut_mirror().lineWith("root").commentOut() | ||
gradleWriteSS() | ||
ut_snapshot() | ||
.assertContent( | ||
""" | ||
╔═ selfie/leaf ═╗ | ||
maple | ||
╔═ [end of file] ═╗ | ||
""" | ||
.trimIndent()) | ||
} | ||
|
||
@Test @Order(5) | ||
fun renameTheWholeMethod() { | ||
ut_mirror().lineWith("selfie2()").uncomment() | ||
ut_mirror().lineWith("selfie()").commentOut() | ||
gradleWriteSS() | ||
ut_snapshot() | ||
.assertContent( | ||
""" | ||
╔═ selfie2/leaf ═╗ | ||
maple | ||
╔═ [end of file] ═╗ | ||
""" | ||
.trimIndent()) | ||
} | ||
|
||
@Test @Order(6) | ||
fun resetUTMirror() { | ||
ut_mirror().lineWith("root").uncomment() | ||
ut_mirror().lineWith("selfie2()").commentOut() | ||
ut_mirror().lineWith("selfie()").uncomment() | ||
} | ||
|
||
@Test @Order(7) | ||
fun deleteSelfie() { | ||
ut_snapshot().deleteIfExists() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
undertest-junit5/src/test/kotlin/undertest/junit5/UT_WithinMethodGCTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.diffplug.selfie.junit5 | ||
// spotless:off | ||
import com.diffplug.selfie.expectSelfie | ||
import kotlin.test.Test | ||
|
||
// spotless:on | ||
|
||
class UT_WithinMethodGCTest { | ||
// @Test fun selfie2() { | ||
@Test fun selfie() { | ||
expectSelfie("root").toMatchDisk() | ||
expectSelfie("maple").toMatchDisk("leaf") | ||
} | ||
} |