File tree Expand file tree Collapse file tree 14 files changed +434
-10
lines changed
main/kotlin/com/javiersc/kotlin/test
test/kotlin/com/javiersc/kotlin/test
main/kotlin/com/javiersc/kotlin/test
test/kotlin/com/javiersc/kotlin/test Expand file tree Collapse file tree 14 files changed +434
-10
lines changed Original file line number Diff line number Diff line change 4
4
5
5
### Added
6
6
7
+ - ` com.javiersc.kotlin:kotlin-test ` artifact
8
+ - ` Any ` assertions
9
+ - ` File ` assertions (only JVM)
10
+ - ` Iterable ` assertions
11
+ - ` String ` assertions
12
+
7
13
### Changed
8
14
9
15
### Deprecated
Original file line number Diff line number Diff line change @@ -82,16 +82,6 @@ hubdle {
82
82
nodejs()
83
83
}
84
84
}
85
-
86
- // TODO: Check if it can be removed with Kotlin 2.0.0+
87
- kotlin {
88
- sourceSets {
89
- wasmJs {
90
- browser { testTask { enabled = false } }
91
- nodejs { testTask { enabled = false } }
92
- }
93
- }
94
- }
95
85
}
96
86
}
97
87
}
Original file line number Diff line number Diff line change
1
+ public final class com/javiersc/kotlin/test/FailKt {
2
+ public static final fun fail (Ljava/lang/String;)Ljava/lang/Void;
3
+ }
4
+
5
+ public final class com/javiersc/kotlin/test/GenericMatchersKt {
6
+ public static final fun assertEquals (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;)V
7
+ public static synthetic fun assertEquals$default (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;ILjava/lang/Object;)V
8
+ public static final fun assertNotEquals (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;)V
9
+ public static synthetic fun assertNotEquals$default (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;ILjava/lang/Object;)V
10
+ }
11
+
12
+ public final class com/javiersc/kotlin/test/StringMatchersKt {
13
+ public static final fun assertNotBlank (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
14
+ public static synthetic fun assertNotBlank$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
15
+ public static final fun assertNotEmpty (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
16
+ public static synthetic fun assertNotEmpty$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
17
+ }
18
+
Original file line number Diff line number Diff line change
1
+ public final class com/javiersc/kotlin/test/FailKt {
2
+ public static final fun fail (Ljava/lang/String;)Ljava/lang/Void;
3
+ }
4
+
5
+ public final class com/javiersc/kotlin/test/FileMatchers_jvmKt {
6
+ public static final fun assertDirectory (Ljava/io/File;Ljava/lang/String;)Ljava/io/File;
7
+ public static synthetic fun assertDirectory$default (Ljava/io/File;Ljava/lang/String;ILjava/lang/Object;)Ljava/io/File;
8
+ public static final fun assertFile (Ljava/io/File;Ljava/lang/String;)Ljava/io/File;
9
+ public static synthetic fun assertFile$default (Ljava/io/File;Ljava/lang/String;ILjava/lang/Object;)Ljava/io/File;
10
+ }
11
+
12
+ public final class com/javiersc/kotlin/test/GenericMatchersKt {
13
+ public static final fun assertEquals (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;)V
14
+ public static synthetic fun assertEquals$default (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;ILjava/lang/Object;)V
15
+ public static final fun assertNotEquals (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;)V
16
+ public static synthetic fun assertNotEquals$default (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;ILjava/lang/Object;)V
17
+ }
18
+
19
+ public final class com/javiersc/kotlin/test/StringMatchersKt {
20
+ public static final fun assertNotBlank (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
21
+ public static synthetic fun assertNotBlank$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
22
+ public static final fun assertNotEmpty (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
23
+ public static synthetic fun assertNotEmpty$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
24
+ }
25
+
Original file line number Diff line number Diff line change
1
+ import com.javiersc.gradle.properties.extensions.getBooleanProperty
2
+
3
+ hubdle {
4
+ config {
5
+ analysis()
6
+ coverage()
7
+ documentation { //
8
+ api()
9
+ }
10
+ explicitApi()
11
+ publishing()
12
+ languageSettings { //
13
+ experimentalContracts()
14
+ }
15
+ }
16
+ kotlin {
17
+ multiplatform {
18
+ features {
19
+ extendedStdlib.isEnabled.set(false )
20
+ kotest.isEnabled.set(false )
21
+ }
22
+
23
+ common {
24
+ main {
25
+ dependencies { //
26
+ implementation(hubdle.jetbrains.kotlin.test)
27
+ implementation(projects.kotlinStdlib)
28
+ }
29
+ }
30
+ }
31
+ if (getBooleanProperty(" android.enabled" ).orElse(true ).get()) android()
32
+ androidNative {
33
+ androidNativeArm32()
34
+ androidNativeArm64()
35
+ androidNativeX86()
36
+ androidNativeX64()
37
+ }
38
+ apple {
39
+ ios {
40
+ iosArm64()
41
+ iosSimulatorArm64()
42
+ iosX64()
43
+ }
44
+ macos {
45
+ macosArm64()
46
+ macosX64()
47
+ }
48
+ tvos {
49
+ tvosArm64()
50
+ tvosSimulatorArm64()
51
+ tvosX64()
52
+ }
53
+ watchos {
54
+ watchosArm32()
55
+ watchosArm64()
56
+ watchosDeviceArm64()
57
+ watchosSimulatorArm64()
58
+ watchosX64()
59
+ }
60
+ }
61
+ jvm {
62
+ test {
63
+ dependencies { //
64
+ implementation(hubdle.junit.jupiter.junit.jupiter)
65
+ }
66
+ }
67
+ }
68
+ jvmAndAndroid()
69
+ js {
70
+ browser()
71
+ nodejs()
72
+ }
73
+ linux {
74
+ linuxArm64()
75
+ linuxX64()
76
+ }
77
+ mingw { //
78
+ mingwX64()
79
+ }
80
+ native()
81
+
82
+ wasm {
83
+ js {
84
+ browser()
85
+ d8()
86
+ nodejs()
87
+ }
88
+ wasi {
89
+ nodejs()
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
Original file line number Diff line number Diff line change
1
+ package com.javiersc.kotlin.test
2
+
3
+ import kotlin.test.asserter
4
+
5
+ @PublishedApi internal fun fail (message : String? ): Nothing = asserter.fail(message)
Original file line number Diff line number Diff line change
1
+ package com.javiersc.kotlin.test
2
+
3
+ import kotlin.test.assertEquals
4
+ import kotlin.test.assertIs
5
+ import kotlin.test.assertIsNot
6
+ import kotlin.test.assertNotEquals
7
+
8
+ public fun <T > T.assertEquals (actual : T , message : String? = null): Unit =
9
+ assertEquals(this , actual, message)
10
+
11
+ public fun <T > T.assertNotEquals (actual : T , message : String? = null): Unit =
12
+ assertNotEquals(this , actual, message)
13
+
14
+ public inline fun <reified T : Any > Any.assertIs (message : String? = null): T {
15
+ assertIs<T >(this , message)
16
+ return this
17
+ }
18
+
19
+ public inline fun <reified T : Any > Any.assertIsNot (message : String? = null) {
20
+ assertIsNot<T >(this , message)
21
+ }
22
+
23
+ public inline fun <reified I : Any , reified T : Any > I.assertIsNot (message : String? = null): I {
24
+ assertIsNot<I >(this , message)
25
+ return this
26
+ }
Original file line number Diff line number Diff line change
1
+ package com.javiersc.kotlin.test
2
+
3
+ public inline fun <reified I : Iterable <T >, reified T : Any > I.assertContains (
4
+ element : T ,
5
+ message : String? = null,
6
+ ): I {
7
+ if (element in this ) return this
8
+ fail(message ? : " Expected to contain $element but did not" )
9
+ }
10
+
11
+ public inline fun <reified I : Iterable <T >, reified T : Any > I.assertCount (
12
+ expectSize : Int ,
13
+ message : String? = null,
14
+ ): I = assertSize(expectSize = expectSize, message = message)
15
+
16
+ public inline fun <reified I : Iterable <T >, reified T : Any > I.assertSize (
17
+ expectSize : Int ,
18
+ message : String? = null,
19
+ ): I {
20
+ val actualSize: Int = count()
21
+ if (actualSize == expectSize) return this
22
+ fail(message ? : " Expected size $expectSize but was $actualSize " )
23
+ }
Original file line number Diff line number Diff line change
1
+ package com.javiersc.kotlin.test
2
+
3
+ import com.javiersc.kotlin.stdlib.isNotNullNorBlank
4
+ import com.javiersc.kotlin.stdlib.isNotNullNorEmpty
5
+ import kotlin.contracts.contract
6
+
7
+ public inline fun String?.assertNotBlank (message : String? = null): String {
8
+ contract { returns() implies (this @assertNotBlank != null ) }
9
+
10
+ if (this .isNotNullNorBlank()) return this
11
+
12
+ fail(message ? : " Expected not blank but was 'null' or blank" )
13
+ }
14
+
15
+ public inline fun String?.assertNotEmpty (message : String? = null): String {
16
+ contract { returns() implies (this @assertNotEmpty != null ) }
17
+
18
+ if (this .isNotNullNorEmpty()) return this
19
+
20
+ fail(message ? : " Expected not blank but was 'null' or empty" )
21
+ }
Original file line number Diff line number Diff line change
1
+ package com.javiersc.kotlin.test
2
+
3
+ import kotlin.test.Test
4
+ import kotlin.test.assertFailsWith
5
+ import kotlin.test.assertTrue
6
+
7
+ class GenericMatchersTest {
8
+
9
+ @Test
10
+ fun `assertInstance should pass for correct type` () {
11
+ val value: Any = " test"
12
+ val result: String = value.assertIs()
13
+ assertTrue(result == " test" )
14
+ }
15
+
16
+ @Test
17
+ fun `assertInstance should fail for incorrect type` () {
18
+ val value: Any = 123
19
+ assertFailsWith<AssertionError > { value.assertIs<String >() }
20
+ }
21
+
22
+ @Test
23
+ fun `assertInstance should fail with custom message` () {
24
+ val value: Any = 123
25
+ val message = " Custom error message"
26
+ val exception: AssertionError = assertFailsWith { value.assertIs<String >(message) }
27
+ assertTrue(exception.message == message)
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments