From d7d87a373d2d66bf9445b0e17ed6c06ff5497a03 Mon Sep 17 00:00:00 2001 From: Brian Norman Date: Sun, 14 Mar 2021 16:23:15 -0500 Subject: [PATCH] Make samples actually integration tests --- .github/workflows/gradle.yml | 2 +- .../kotlin/com/bnorm/power/Person.kt | 3 +- .../kotlin/com/bnorm/power/PowerAssertTest.kt | 84 ++++++++++++++++--- .../com/bnorm/power/JsPowerAssertTest.kt | 18 +++- .../com/bnorm/power/JvmPowerAssertTest.kt | 18 +++- .../com/bnorm/power/NativePowerAssertTest.kt | 18 +++- 6 files changed, 128 insertions(+), 15 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 0926060012c..d0d22f7caee 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -17,4 +17,4 @@ jobs: java-version: 1.8 - run: ./gradlew build - - run: cd sample && ./gradlew build browserDistribution || cd .. + - run: cd sample && ./gradlew build diff --git a/sample/src/commonMain/kotlin/com/bnorm/power/Person.kt b/sample/src/commonMain/kotlin/com/bnorm/power/Person.kt index 09d10c4f0e0..48cbe9850b9 100644 --- a/sample/src/commonMain/kotlin/com/bnorm/power/Person.kt +++ b/sample/src/commonMain/kotlin/com/bnorm/power/Person.kt @@ -18,9 +18,10 @@ package com.bnorm.power data class Person( val firstName: String, - val lastName: String + val lastName: String, ) { companion object { val UNKNOWN = listOf(Person("John", "Doe"), Person("Jane", "Doe")) + override fun toString() = "Person.Companion" } } diff --git a/sample/src/commonTest/kotlin/com/bnorm/power/PowerAssertTest.kt b/sample/src/commonTest/kotlin/com/bnorm/power/PowerAssertTest.kt index f0d83266453..0d5d607acb5 100644 --- a/sample/src/commonTest/kotlin/com/bnorm/power/PowerAssertTest.kt +++ b/sample/src/commonTest/kotlin/com/bnorm/power/PowerAssertTest.kt @@ -17,17 +17,44 @@ package com.bnorm.power import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith import kotlin.test.assertTrue class PowerAssertTest { + @Test fun assertTrue() { - assertTrue(Person.UNKNOWN.size == 1) + val error = assertFailsWith { assertTrue(Person.UNKNOWN.size == 1) } + assertEquals( + actual = error.message, + expected = """ + Assertion failed + assertTrue(Person.UNKNOWN.size == 1) + | | | | + | | | false + | | 2 + | [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)] + Person.Companion + """.trimIndent() + ) } @Test fun require() { - require(Person.UNKNOWN.size == 1) + val error = assertFailsWith { require(Person.UNKNOWN.size == 1) } + assertEquals( + actual = error.message, + expected = """ + Assertion failed + require(Person.UNKNOWN.size == 1) + | | | | + | | | false + | | 2 + | [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)] + Person.Companion + """.trimIndent() + ) } @Test @@ -36,15 +63,52 @@ class PowerAssertTest { assert(unknown != null) assert(unknown.size == 2) - val jane: Person - val john: Person - assertSoftly { - jane = unknown[0] - assert(jane.firstName == "Jane") - assert(jane.lastName == "Doe") { "bad jane last name" } + val error = assertFailsWith { + val jane: Person + val john: Person + assertSoftly { + jane = unknown[0] + assert(jane.firstName == "Jane") + assert(jane.lastName == "Doe") { "bad jane last name" } - john = unknown[1] - assert(john.lastName == "Doe" && john.firstName == "John") { "bad john" } + john = unknown[1] + assert(john.lastName == "Doe" && john.firstName == "John") { "bad john" } + } } + assertEquals( + actual = error.message, + expected = """ + Multiple failed assertions + """.trimIndent(), + ) + assertEquals( + actual = error.suppressedExceptions.size, + expected = 2, + ) + assertEquals( + actual = error.suppressedExceptions[0].message, + expected = """ + Assertion failed + assert(jane.firstName == "Jane") + | | | + | | false + | John + Person(firstName=John, lastName=Doe) + """.trimIndent(), + ) + assertEquals( + actual = error.suppressedExceptions[1].message, + expected = """ + bad john + assert(john.lastName == "Doe" && john.firstName == "John") { "bad john" } + | | | | | | + | | | | | false + | | | | Jane + | | | Person(firstName=Jane, lastName=Doe) + | | true + | Doe + Person(firstName=Jane, lastName=Doe) + """.trimIndent(), + ) } } diff --git a/sample/src/jsTest/kotlin/com/bnorm/power/JsPowerAssertTest.kt b/sample/src/jsTest/kotlin/com/bnorm/power/JsPowerAssertTest.kt index 111d332d15c..4c496ae5933 100644 --- a/sample/src/jsTest/kotlin/com/bnorm/power/JsPowerAssertTest.kt +++ b/sample/src/jsTest/kotlin/com/bnorm/power/JsPowerAssertTest.kt @@ -17,10 +17,26 @@ package com.bnorm.power import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith class JsPowerAssertTest { @Test fun assert() { - require(Person.UNKNOWN.size == 1) { "unknown persons: ${Person.UNKNOWN}" } + val error = assertFailsWith { + require(Person.UNKNOWN.size == 1) { "unknown persons: ${Person.UNKNOWN}" } + } + assertEquals( + actual = error.message, + expected = """ + unknown persons: [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)] + require(Person.UNKNOWN.size == 1) { "unknown persons: ${"$"}{Person.UNKNOWN}" } + | | | | + | | | false + | | 2 + | [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)] + Person.Companion + """.trimIndent(), + ) } } diff --git a/sample/src/jvmTest/kotlin/com/bnorm/power/JvmPowerAssertTest.kt b/sample/src/jvmTest/kotlin/com/bnorm/power/JvmPowerAssertTest.kt index 2a0f2071f28..672123b4201 100644 --- a/sample/src/jvmTest/kotlin/com/bnorm/power/JvmPowerAssertTest.kt +++ b/sample/src/jvmTest/kotlin/com/bnorm/power/JvmPowerAssertTest.kt @@ -17,10 +17,26 @@ package com.bnorm.power import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith class JvmPowerAssertTest { @Test fun assert() { - assert(Person.UNKNOWN.size == 1) { "unknown persons: ${Person.UNKNOWN}" } + val error = assertFailsWith { + assert(Person.UNKNOWN.size == 1) { "unknown persons: ${Person.UNKNOWN}" } + } + assertEquals( + actual = error.message, + expected = """ + unknown persons: [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)] + assert(Person.UNKNOWN.size == 1) { "unknown persons: ${"$"}{Person.UNKNOWN}" } + | | | | + | | | false + | | 2 + | [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)] + Person.Companion + """.trimIndent(), + ) } } diff --git a/sample/src/nativeTest/kotlin/com/bnorm/power/NativePowerAssertTest.kt b/sample/src/nativeTest/kotlin/com/bnorm/power/NativePowerAssertTest.kt index 267dcbb0fd0..8d17b11cc34 100644 --- a/sample/src/nativeTest/kotlin/com/bnorm/power/NativePowerAssertTest.kt +++ b/sample/src/nativeTest/kotlin/com/bnorm/power/NativePowerAssertTest.kt @@ -17,10 +17,26 @@ package com.bnorm.power import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith class NativePowerAssertTest { @Test fun assert() { - assert(Person.UNKNOWN.size == 1) { "unknown persons: ${Person.UNKNOWN}" } + val error = assertFailsWith { + assert(Person.UNKNOWN.size == 1) { "unknown persons: ${Person.UNKNOWN}" } + } + assertEquals( + actual = error.message, + expected = """ + unknown persons: [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)] + assert(Person.UNKNOWN.size == 1) { "unknown persons: ${"$"}{Person.UNKNOWN}" } + | | | | + | | | false + | | 2 + | [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)] + Person.Companion + """.trimIndent(), + ) } }