-
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.
Add a test to make sure the prism train is running.
- Loading branch information
Showing
6 changed files
with
133 additions
and
23 deletions.
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
68 changes: 68 additions & 0 deletions
68
selfie-runner-junit5/src/test/kotlin/com/diffplug/selfie/junit5/PrismTrainTest.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,68 @@ | ||
/* | ||
* 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 | ||
|
||
/** Simplest test for verifying read/write of a snapshot. */ | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation::class) | ||
@DisableIfTestFails | ||
class PrismTrainTest : Harness("undertest-junit5", onlyRunThisTest = true) { | ||
@Test @Order(1) | ||
fun noSelfie() { | ||
ut_snapshot().deleteIfExists() | ||
ut_snapshot().assertDoesNotExist() | ||
} | ||
|
||
@Test @Order(2) | ||
fun noTrain() { | ||
gradleWriteSS() | ||
ut_snapshot() | ||
.assertContent( | ||
""" | ||
╔═ selfie ═╗ | ||
apple | ||
╔═ [end of file] ═╗ | ||
""" | ||
.trimIndent()) | ||
gradleReadSS() | ||
} | ||
|
||
@Test @Order(3) | ||
fun withTrain() { | ||
settings = "undertest.junit5.SettingsLensCount" | ||
gradleReadSSFail() | ||
// now let's write it | ||
gradleWriteSS() | ||
ut_snapshot() | ||
.assertContent( | ||
""" | ||
╔═ selfie ═╗ | ||
apple | ||
╔═ selfie[count] ═╗ | ||
5 | ||
╔═ [end of file] ═╗ | ||
""" | ||
.trimIndent()) | ||
gradleReadSS() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
undertest-junit5/src/test/kotlin/undertest/junit5/SettingsLensCount.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,21 @@ | ||
package undertest.junit5 | ||
|
||
import com.diffplug.selfie.CompoundPrism | ||
import com.diffplug.selfie.Snapshot | ||
import com.diffplug.selfie.SnapshotLens | ||
import com.diffplug.selfie.SnapshotValue | ||
import com.diffplug.selfie.junit5.StandardSelfieSettings | ||
|
||
class SettingsLensCount : StandardSelfieSettings() { | ||
override fun setupPrismTrain(prismTrain: CompoundPrism) { | ||
prismTrain | ||
.forEverySnapshot() | ||
.addLens( | ||
object : SnapshotLens { | ||
override val defaultLensName = "count" | ||
|
||
override fun transform(testClass: String, key: String, snapshot: Snapshot) = | ||
SnapshotValue.of(snapshot.value.valueString().count().toString()) | ||
}) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
undertest-junit5/src/test/kotlin/undertest/junit5/UT_PrismTrainTest.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,10 @@ | ||
package undertest.junit5 | ||
|
||
import com.diffplug.selfie.Selfie.expectSelfie | ||
import kotlin.test.Test | ||
|
||
class UT_PrismTrainTest { | ||
@Test fun selfie() { | ||
expectSelfie("apple").toMatchDisk() | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
undertest-junit5/src/test/kotlin/undertest/junit5/__snapshots__/UT_CarriageReturnTest.ss
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
undertest-junit5/src/test/kotlin/undertest/junit5/__snapshots__/UT_PrismTrainTest.ss
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,3 @@ | ||
╔═ selfie ═╗ | ||
apple | ||
╔═ [end of file] ═╗ |