-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
173 additions
and
18 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
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
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,40 @@ | ||
package de.joshuagleitze.testfiles.kotest | ||
|
||
import de.joshuagleitze.testfiles.DefaultTestFiles | ||
import io.kotest.core.listeners.TestListener | ||
import io.kotest.core.spec.AutoScan | ||
import io.kotest.core.spec.Spec | ||
import io.kotest.core.test.TestCase | ||
import io.kotest.core.test.TestResult | ||
import io.kotest.core.test.TestStatus.Error | ||
import io.kotest.core.test.TestStatus.Failure | ||
import io.kotest.core.test.TestStatus.Ignored | ||
import io.kotest.core.test.TestStatus.Success | ||
import kotlin.reflect.KClass | ||
|
||
@AutoScan | ||
internal object KotestTestFilesAdapter: TestListener { | ||
override val name: String get() = "testfiles" | ||
|
||
override suspend fun prepareSpec(kclass: KClass<out Spec>) { | ||
internalTestFiles.enterScope(kclass.qualifiedName ?: "<anonymous spec>") | ||
} | ||
|
||
override suspend fun finalizeSpec(kclass: KClass<out Spec>, results: Map<TestCase, TestResult>) { | ||
internalTestFiles.leaveScope(results.values.map { convert(it) }.reduce { left, right -> left.combineWith(right) }) | ||
} | ||
|
||
override suspend fun beforeAny(testCase: TestCase) { | ||
internalTestFiles.enterScope(testCase.displayName) | ||
} | ||
|
||
override suspend fun afterAny(testCase: TestCase, result: TestResult) { | ||
internalTestFiles.leaveScope(convert(result)) | ||
} | ||
|
||
private fun convert(result: TestResult) = when (result.status) { | ||
Success -> DefaultTestFiles.TestResult.SUCCESS | ||
Error, Failure -> DefaultTestFiles.TestResult.FAILURE | ||
Ignored -> error("contact breach: kotest should not have called us!") | ||
} | ||
} |
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,13 @@ | ||
package de.joshuagleitze.testfiles.kotest | ||
|
||
import de.joshuagleitze.testfiles.DefaultTestFiles | ||
import de.joshuagleitze.testfiles.TestFiles | ||
|
||
internal val internalTestFiles: DefaultTestFiles = DefaultTestFiles() | ||
|
||
/** | ||
* A [TestFiles] instance that will use the structure of the Kotest tests in this project to create files. | ||
* | ||
* @sample de.joshuagleitze.testfiles.kotest.samples.ExampleSpek | ||
*/ | ||
public val testFiles: TestFiles get() = internalTestFiles |
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,39 @@ | ||
package de.joshuagleitze.testfiles.kotest | ||
|
||
import ch.tutteli.atrium.api.fluent.en_GB.isDirectory | ||
import ch.tutteli.atrium.api.fluent.en_GB.isReadable | ||
import ch.tutteli.atrium.api.fluent.en_GB.isRegularFile | ||
import ch.tutteli.atrium.api.fluent.en_GB.isWritable | ||
import ch.tutteli.atrium.api.fluent.en_GB.parent | ||
import ch.tutteli.atrium.api.fluent.en_GB.toBe | ||
import ch.tutteli.atrium.api.verbs.expect | ||
import ch.tutteli.atrium.core.polyfills.fullName | ||
import de.joshuagleitze.testfiles.DefaultTestFiles | ||
import io.kotest.core.spec.style.DescribeSpec | ||
import kotlin.io.path.div | ||
|
||
class KotestTestFilesIntegrationSpec: DescribeSpec({ | ||
val fileRoot = DefaultTestFiles.determineTestFilesRootDirectory() | ||
|
||
describe("testFiles") { | ||
val expectedGroupFolder = fileRoot / "[${KotestTestFilesIntegrationSpec::class.fullName}]" / "[testFiles]" | ||
|
||
it("creates a test file with the appropriate name") { | ||
expect(testFiles.createFile()) { | ||
isRegularFile() | ||
isReadable() | ||
isWritable() | ||
parent.toBe(expectedGroupFolder / "[creates a test file with the appropriate name]") | ||
} | ||
} | ||
|
||
it("creates a test directory with the appropriate name") { | ||
expect(testFiles.createDirectory()) { | ||
isDirectory() | ||
isReadable() | ||
isWritable() | ||
parent.toBe(expectedGroupFolder / "[creates a test directory with the appropriate name]") | ||
} | ||
} | ||
} | ||
}) |
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,22 @@ | ||
package de.joshuagleitze.testfiles.kotest.samples | ||
|
||
import de.joshuagleitze.testfiles.DeletionMode.ALWAYS | ||
import de.joshuagleitze.testfiles.DeletionMode.IF_SUCCESSFUL | ||
import de.joshuagleitze.testfiles.DeletionMode.NEVER | ||
import de.joshuagleitze.testfiles.kotest.testFiles | ||
import io.kotest.core.spec.style.DescribeSpec | ||
|
||
class ExampleSpek: DescribeSpec({ | ||
describe("using test files") { | ||
it("generates file names") { | ||
testFiles.createFile() | ||
testFiles.createDirectory() | ||
} | ||
|
||
it("cleans up files") { | ||
testFiles.createFile("irrelevant", delete = ALWAYS) | ||
testFiles.createFile("default mode", delete = IF_SUCCESSFUL) | ||
testFiles.createFile("output", delete = NEVER) | ||
} | ||
} | ||
}) |
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
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
3 changes: 2 additions & 1 deletion
3
spek/src/test/kotlin/ExampleSpek.kt → spek/src/test/kotlin/samples/ExampleSpek.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
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