diff --git a/progress/build.gradle.kts b/progress/build.gradle.kts index 92f6044..ebf926e 100644 --- a/progress/build.gradle.kts +++ b/progress/build.gradle.kts @@ -17,6 +17,7 @@ plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) + alias(libsCommon.plugins.testBalloon) } kotlin { @@ -46,7 +47,9 @@ kotlin { } sourceSets.commonTest.dependencies { - implementation(libs.bundles.prepared) + implementation(libsCommon.opensavvy.prepared.testBalloon) + implementation(libsCommon.opensavvy.prepared.parameterize) + implementation(libsCommon.kotlin.test) } } diff --git a/progress/src/commonTest/kotlin/DoneTest.kt b/progress/src/commonTest/kotlin/DoneTest.kt index c3337f1..4ec52ea 100644 --- a/progress/src/commonTest/kotlin/DoneTest.kt +++ b/progress/src/commonTest/kotlin/DoneTest.kt @@ -16,12 +16,11 @@ package opensavvy.progress -import io.kotest.matchers.shouldBe -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite @Suppress("unused") -class DoneTest : PreparedSpec({ - test("String representation") { - done().toString() shouldBe "Done" - } -}) +val DoneTest by preparedSuite { + test("String representation") { + check(done().toString() == "Done") + } +} diff --git a/progress/src/commonTest/kotlin/ProgressiveTest.kt b/progress/src/commonTest/kotlin/ProgressiveTest.kt index 8661dcb..476e27d 100644 --- a/progress/src/commonTest/kotlin/ProgressiveTest.kt +++ b/progress/src/commonTest/kotlin/ProgressiveTest.kt @@ -16,24 +16,25 @@ package opensavvy.progress -import io.kotest.assertions.assertSoftly -import io.kotest.matchers.shouldBe -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite @OptIn(ExperimentalProgressApi::class) -class ProgressiveTest : PreparedSpec({ +val ProgressiveTest by preparedSuite { - test("toString") { - assertSoftly { - Progressive(5, loading(0.2)).toString() shouldBe "5 Loading(20%)" + test("toString with progress") { + check(Progressive(5, loading(0.2)).toString() == "5 Loading(20%)") + } + + test("toString with text") { + check(Progressive("foo", done()).toString() == "foo Done") + } - Progressive("foo", done()).toString() shouldBe "foo Done" + test("toString with decimal and progress") { + check(Progressive(5.2, loading(0.1)).toString() == "5.2 Loading(10%)") + } - listOf( - Progressive(5.2, loading(0.1)), - Progressive(true, loading(0.9)), - ).toString() shouldBe "[5.2 Loading(10%), true Loading(90%)]" - } + test("toString with boolean and progress") { + check(Progressive(true, loading(0.9)).toString() == "true Loading(90%)") } -}) +} diff --git a/progress/src/commonTest/kotlin/SimpleLoadingImplementationTest.kt b/progress/src/commonTest/kotlin/SimpleLoadingImplementationTest.kt index adc6e4c..6a1388e 100644 --- a/progress/src/commonTest/kotlin/SimpleLoadingImplementationTest.kt +++ b/progress/src/commonTest/kotlin/SimpleLoadingImplementationTest.kt @@ -18,90 +18,87 @@ package opensavvy.progress import com.benwoodworth.parameterize.parameterOf import com.benwoodworth.parameterize.parameterize -import io.kotest.assertions.throwables.shouldThrow -import io.kotest.matchers.shouldBe -import io.kotest.matchers.shouldNotBe -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.prepared.suite.assertions.checkThrows @Suppress("unused") -class SimpleLoadingImplementationTest : PreparedSpec({ - suite("Constructor range validation") { - parameterize { - val legal by parameterOf(0.0, 0.1, 0.00001, 0.33, 1.0) +val SimpleLoadingImplementationTest by preparedSuite { + suite("Constructor range validation") { + parameterize { + val legal by parameterOf(0.0, 0.1, 0.00001, 0.33, 1.0) - test("The loading constructor should accept the value $legal") { - loading(legal).normalized shouldBe legal - } - } + test("The loading constructor should accept the value $legal") { + check(loading(legal).normalized == legal) + } + } - parameterize { - val illegal by parameterOf(-1.0, 1.01, 1.000001, -0.000001, Double.MAX_VALUE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) + parameterize { + val illegal by parameterOf(-1.0, 1.01, 1.000001, -0.000001, Double.MAX_VALUE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) - test("The loading constructor should not accept the value $illegal") { - shouldThrow { loading(illegal) } - } - } - } + test("The loading constructor should not accept the value $illegal") { + checkThrows { loading(illegal) } + } + } + } - suite("Conversion to integer percent") { - parameterize { - val value by parameterOf( - 0.0 to 0, - 0.33 to 33, - 1.0 to 100, - 0.01 to 1, - 0.001 to 0, - 0.4597 to 45, - ) - val (input, expected) = value + suite("Conversion to integer percent") { + parameterize { + val value by parameterOf( + 0.0 to 0, + 0.33 to 33, + 1.0 to 100, + 0.01 to 1, + 0.001 to 0, + 0.4597 to 45, + ) + val (input, expected) = value - test("Converting $input should give $expected") { - loading(input).percent shouldBe expected - } - } - } + test("Converting $input should give $expected") { + check(loading(input).percent == expected) + } + } + } - suite("String conversion") { - parameterize { - val value by parameterOf( - 0.0 to "Loading(0%)", - 0.2 to "Loading(20%)", - 0.99 to "Loading(99%)", - 1.0 to "Loading(100%)", - ) - val (input, expected) = value + suite("String conversion") { + parameterize { + val value by parameterOf( + 0.0 to "Loading(0%)", + 0.2 to "Loading(20%)", + 0.99 to "Loading(99%)", + 1.0 to "Loading(100%)", + ) + val (input, expected) = value - test("loading($input) should be represented by the string $expected") { - loading(input).toString() shouldBe expected - } - } - } + test("loading($input) should be represented by the string $expected") { + check(loading(input).toString() == expected) + } + } + } - test("The hashCode implementation is correct") { - val set = hashSetOf( - done(), - loading(0.0), - loading(0.7), - loading(0.9), - loading(1.0), - ) + test("The hashCode implementation is correct") { + val set = hashSetOf( + done(), + loading(0.0), + loading(0.7), + loading(0.9), + loading(1.0), + ) - check(done() in set) - check(loading(0.0) in set) - check(loading(0.7) in set) - check(loading(0.9) in set) - check(loading(1.0) in set) - } + check(done() in set) + check(loading(0.0) in set) + check(loading(0.7) in set) + check(loading(0.9) in set) + check(loading(1.0) in set) + } - suite("Equality") { - test("Equal") { - loading(0.0) shouldBe loading(0.0) - } + suite("Equality") { + test("Equal") { + check(loading(0.0) == loading(0.0)) + } - test("Not equal") { - loading(0.0) shouldNotBe loading(0.7) - loading(0.0) shouldNotBe Unit - loading(0.0) shouldNotBe null - } - } -}) + test("Not equal") { + check(loading(0.0) != loading(0.7)) + check(loading(0.0) != Unit) + } + } +} diff --git a/progress/src/commonTest/kotlin/UnquantifiedLoadingTest.kt b/progress/src/commonTest/kotlin/UnquantifiedLoadingTest.kt index ddf9e62..1e9f4bb 100644 --- a/progress/src/commonTest/kotlin/UnquantifiedLoadingTest.kt +++ b/progress/src/commonTest/kotlin/UnquantifiedLoadingTest.kt @@ -16,12 +16,11 @@ package opensavvy.progress -import io.kotest.matchers.shouldBe -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite @Suppress("unused") -class UnquantifiedLoadingTest : PreparedSpec({ - test("String representation") { - loading().toString() shouldBe "Loading" - } -}) +val UnquantifiedLoadingTest by preparedSuite { + test("String representation") { + check(loading().toString() == "Loading") + } +} diff --git a/progress/src/commonTest/kotlin/report/IntervalReduceProgressReporterTest.kt b/progress/src/commonTest/kotlin/report/IntervalReduceProgressReporterTest.kt index da55db2..aa3d3be 100644 --- a/progress/src/commonTest/kotlin/report/IntervalReduceProgressReporterTest.kt +++ b/progress/src/commonTest/kotlin/report/IntervalReduceProgressReporterTest.kt @@ -16,78 +16,77 @@ package opensavvy.progress.report -import io.kotest.assertions.throwables.shouldThrow -import io.kotest.matchers.shouldBe -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.prepared.suite.assertions.checkThrows import opensavvy.progress.Progress import opensavvy.progress.done import opensavvy.progress.loading @Suppress("unused") -class IntervalReduceProgressReporterTest : PreparedSpec({ - test("Cannot create an invalid range") { - shouldThrow { - emptyProgressReporter().reduceToInterval(0.7, 0.2) - } - } +val IntervalReduceProgressReporterTest by preparedSuite { + test("Cannot create an invalid range") { + checkThrows { + emptyProgressReporter().reduceToInterval(0.7, 0.2) + } + } - test("Reduce with the range syntax") { - var value: Progress? = null + test("Reduce with the range syntax") { + var value: Progress? = null - val reporter = ProgressReporter { value = it } - .reduceToInterval(0.2..0.4) + val reporter = ProgressReporter { value = it } + .reduceToInterval(0.2..0.4) - reporter.report(loading(0.1)) - value shouldBe loading(0.22) - } + reporter.report(loading(0.1)) + check(value == loading(0.22)) + } - test("Reduce with the min-max syntax") { - var value: Progress? = null + test("Reduce with the min-max syntax") { + var value: Progress? = null - val reporter = ProgressReporter { value = it } - .reduceToInterval(0.2, 0.4) + val reporter = ProgressReporter { value = it } + .reduceToInterval(0.2, 0.4) - reporter.report(loading(0.1)) - value shouldBe loading(0.22) - } + reporter.report(loading(0.1)) + check(value == loading(0.22)) + } - test("Reducing the 'done' event should return the range maximum") { - var value: Progress? = null + test("Reducing the 'done' event should return the range maximum") { + var value: Progress? = null - val reporter = ProgressReporter { value = it } - .reduceToInterval(0.2..0.4) + val reporter = ProgressReporter { value = it } + .reduceToInterval(0.2..0.4) - reporter.report(done()) - value shouldBe loading(0.4) - } + reporter.report(done()) + check(value == loading(0.4)) + } - test("Reducing an unquantified loading event should return the range middle") { - var value: Progress? = null + test("Reducing an unquantified loading event should return the range middle") { + var value: Progress? = null - val reporter = ProgressReporter { value = it } - .reduceToInterval(0.2..0.4) + val reporter = ProgressReporter { value = it } + .reduceToInterval(0.2..0.4) - reporter.report(loading()) - value shouldBe loading(0.3) - } + reporter.report(loading()) + check(value == loading(0.3)) + } - test("Reducing 0 should give the range minimum") { - var value: Progress? = null + test("Reducing 0 should give the range minimum") { + var value: Progress? = null - val reporter = ProgressReporter { value = it } - .reduceToInterval(0.2..0.4) + val reporter = ProgressReporter { value = it } + .reduceToInterval(0.2..0.4) - reporter.report(loading(0.0)) - value shouldBe loading(0.2) - } + reporter.report(loading(0.0)) + check(value == loading(0.2)) + } - test("Reducing 1 should give the range maximum") { - var value: Progress? = null + test("Reducing 1 should give the range maximum") { + var value: Progress? = null - val reporter = ProgressReporter { value = it } - .reduceToInterval(0.2..0.4) + val reporter = ProgressReporter { value = it } + .reduceToInterval(0.2..0.4) - reporter.report(loading(1.0)) - value shouldBe loading(0.4) - } -}) + reporter.report(loading(1.0)) + check(value == loading(0.4)) + } +} diff --git a/progress/src/commonTest/kotlin/report/MapProgressReporterTest.kt b/progress/src/commonTest/kotlin/report/MapProgressReporterTest.kt index 5aa38c7..8a16fd7 100644 --- a/progress/src/commonTest/kotlin/report/MapProgressReporterTest.kt +++ b/progress/src/commonTest/kotlin/report/MapProgressReporterTest.kt @@ -16,40 +16,39 @@ package opensavvy.progress.report -import io.kotest.matchers.shouldBe -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite import opensavvy.progress.Progress import opensavvy.progress.done import opensavvy.progress.loading @Suppress("unused") -class MapProgressReporterTest : PreparedSpec({ +val MapProgressReporterTest by preparedSuite { - test("Should intercept reported values and transform them (replacing by done)") { - var value: Progress? = null + test("Should intercept reported values and transform them (replacing by done)") { + var value: Progress? = null - val reporter = ProgressReporter { value = it } - .map { done() } + val reporter = ProgressReporter { value = it } + .map { done() } - reporter.report(loading(0.5)) - value shouldBe done() - } + reporter.report(loading(0.5)) + check(value == done()) + } - test("Should intercept reported values and transform them (increasing the value)") { - var value: Progress? = null + test("Should intercept reported values and transform them (increasing the value)") { + var value: Progress? = null - val reporter = ProgressReporter { value = it } - .map { it as Progress.Loading.Quantified; loading(it.normalized + 0.2) } + val reporter = ProgressReporter { value = it } + .map { it as Progress.Loading.Quantified; loading(it.normalized + 0.2) } - reporter.report(loading(0.2)) - value shouldBe loading(0.4) - } + reporter.report(loading(0.2)) + check(value == loading(0.4)) + } - test("String representation") { - val reporter = emptyProgressReporter() - .reduceToInterval(0.1, 0.2) - .map { it } + test("String representation") { + val reporter = emptyProgressReporter() + .reduceToInterval(0.1, 0.2) + .map { it } - check(reporter.toString() == "NoOpProgressReporter.reduceToInterval(0.1..0.2).map()") - } -}) + check(reporter.toString() == "NoOpProgressReporter.reduceToInterval(0.1..0.2).map()") + } +} diff --git a/progress/src/commonTest/kotlin/report/NoOpProgressReporterTest.kt b/progress/src/commonTest/kotlin/report/NoOpProgressReporterTest.kt index 421fa84..3524784 100644 --- a/progress/src/commonTest/kotlin/report/NoOpProgressReporterTest.kt +++ b/progress/src/commonTest/kotlin/report/NoOpProgressReporterTest.kt @@ -16,13 +16,13 @@ package opensavvy.progress.report -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite import opensavvy.progress.loading @Suppress("unused") -class NoOpProgressReporterTest : PreparedSpec({ +val NoOpProgressReporterTest by preparedSuite { test("No-op") { // it does nothing anyway… emptyProgressReporter().report(loading(0.5)) } -}) +}