Skip to content

Commit

Permalink
Add a test for junit-vintage, failing.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Dec 19, 2023
1 parent 1f8920e commit 538fe50
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.junitvintage

import com.diffplug.selfie.junit5.Harness
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 ReadWriteVintageTest : Harness("undertest-junit-vintage") {
@Test @Order(1)
fun noSelfie() {
ut_snapshot().deleteIfExists()
ut_snapshot().assertDoesNotExist()
}

@Test @Order(2)
fun writeApple() {
ut_mirror().lineWith("apple").uncomment()
ut_mirror().lineWith("orange").commentOut()
gradleWriteSS()
ut_snapshot()
.assertContent(
"""
╔═ selfie ═╗
apple
╔═ [end of file] ═╗
"""
.trimIndent())
}

@Test @Order(3)
fun assertApplePasses() {
gradleReadSS()
}

@Test @Order(4)
fun assertOrangeFails() {
ut_mirror().lineWith("apple").commentOut()
ut_mirror().lineWith("orange").uncomment()
gradleReadSSFail()
ut_snapshot()
.assertContent(
"""
╔═ selfie ═╗
apple
╔═ [end of file] ═╗
"""
.trimIndent())
}

@Test @Order(5)
fun writeOrange() {
gradleWriteSS()
ut_snapshot()
.assertContent(
"""
╔═ selfie ═╗
orange
╔═ [end of file] ═╗
"""
.trimIndent())
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ blowdryerSetup {
include 'selfie-lib'
include 'selfie-runner-junit5'
include 'undertest-junit5'
include 'undertest-junit-vintage'
rootProject.name = 'selfie'
48 changes: 48 additions & 0 deletions undertest-junit-vintage/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
}
repositories {
mavenCentral()
}
apply plugin: 'com.diffplug.spotless'
spotless {
kotlin {
target 'src/**/*.kt'
toggleOffOn()
licenseHeader ''
ktfmt()
replaceRegex("test one-liner", "@Test\n(\\s*)fun ", "@Test fun ")
replaceRegex("test harness comments", "\n(\\s)*//", "\n//")
}
}

dependencies {
testImplementation project(':selfie-runner-junit5')
testCompileOnly "junit:junit:4.13.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:${ver_JUNIT_USE}"
testImplementation "org.junit.vintage:junit-vintage-engine:${ver_JUNIT_USE}"
}
// this project is just a test environment for a different project
test {
enabled = false
}
tasks.register('underTest', Test) {
useJUnitPlatform()
testClassesDirs = testing.suites.test.sources.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath
testLogging.showStandardStreams = true
// the snapshots are both output and input, for this harness best if the test just always runs
outputs.upToDateWhen { false }
// defaults to 'write'
systemProperty 'selfie', findProperty('selfie')
}
tasks.register('underTestRead', Test) {
useJUnitPlatform()
testClassesDirs = testing.suites.test.sources.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath
testLogging.showStandardStreams = true
// the snapshots are both output and input, for this harness best if the test just always runs
outputs.upToDateWhen { false }
// read-only
systemProperty 'selfie', 'read'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package undertest.junit5

import com.diffplug.selfie.Selfie.expectSelfie
import org.junit.Test

class UT_ReadWriteVintageTest {
@Test fun selfie() {
// expectSelfie("apple").toMatchDisk()
expectSelfie("orange").toMatchDisk()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
╔═ selfie ═╗
orange
╔═ [end of file] ═╗
2 changes: 2 additions & 0 deletions undertest-junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tasks.register('underTest', Test) {
useJUnitPlatform()
testClassesDirs = testing.suites.test.sources.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath
testLogging.showStandardStreams = true
// the snapshots are both output and input, for this harness best if the test just always runs
outputs.upToDateWhen { false }
// defaults to 'write'
Expand All @@ -38,6 +39,7 @@ tasks.register('underTestRead', Test) {
useJUnitPlatform()
testClassesDirs = testing.suites.test.sources.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath
testLogging.showStandardStreams = true
// the snapshots are both output and input, for this harness best if the test just always runs
outputs.upToDateWhen { false }
// read-only
Expand Down

0 comments on commit 538fe50

Please sign in to comment.