Skip to content

Commit 251095c

Browse files
committed
Use kotlintest for table testing
1 parent 23ddb22 commit 251095c

File tree

13 files changed

+128
-141
lines changed

13 files changed

+128
-141
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ subprojects {
3030
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
3131

3232
testImplementation 'junit:junit:4.12'
33-
testImplementation 'io.kotlintest:kotlintest-assertions:3.1.6'
33+
testImplementation 'io.kotlintest:kotlintest-assertions:3.1.7'
3434
testImplementation 'com.github.stefanbirkner:system-rules:1.17.0'
3535
}
3636

clikt/src/test/kotlin/com/github/ajalt/clikt/core/CliktCommandTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package com.github.ajalt.clikt.core
33
import com.github.ajalt.clikt.parameters.arguments.argument
44
import com.github.ajalt.clikt.parameters.arguments.multiple
55
import com.github.ajalt.clikt.parameters.options.option
6-
import com.github.ajalt.clikt.testing.parameterized
7-
import com.github.ajalt.clikt.testing.row
86
import com.github.ajalt.clikt.testing.splitArgv
7+
import io.kotlintest.data.forall
98
import io.kotlintest.shouldBe
109
import io.kotlintest.shouldThrow
10+
import io.kotlintest.tables.row
1111
import org.junit.Test
1212

1313

@@ -78,14 +78,14 @@ class CliktCommandTest {
7878
}
7979

8080
@Test
81-
fun `aliases`() = parameterized(
81+
fun `aliases`() = forall(
8282
row("-xx", "x", emptyList()),
8383
row("a", "a", listOf("b")),
8484
row("a", "a", listOf("b")),
8585
row("b", null, listOf("-xa")),
8686
row("recurse", null, listOf("recurse")),
8787
row("recurse2", "foo", listOf("recurse", "recurse2"))
88-
) { (argv, ex, ey) ->
88+
) { argv, ex, ey ->
8989
class C : CliktCommand() {
9090
val x by option("-x", "--xx")
9191
val y by argument().multiple()

clikt/src/test/kotlin/com/github/ajalt/clikt/output/TextExtensionsTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.github.ajalt.clikt.output
22

3-
import com.github.ajalt.clikt.testing.parameterized
4-
import com.github.ajalt.clikt.testing.row
3+
import io.kotlintest.data.forall
54
import io.kotlintest.shouldBe
5+
import io.kotlintest.tables.row
66
import org.junit.Test
77

88
class TextExtensionsTest {
99
@Test
10-
fun `wrapText`() = parameterized(
10+
fun `wrapText`() = forall(
1111
row("abc".wrapText(), "abc"),
1212
row("abc\n".wrapText(), "abc"),
1313
row("abc\n".wrapText(width = 2), "abc"),
@@ -23,18 +23,18 @@ class TextExtensionsTest {
2323
row("a b c\n\nd e f".wrapText(width = 4, initialIndent = "=",
2424
subsequentIndent = "-", preserveParagraph = true), "=a b\n-c\n\n-d e\n-f"),
2525
row("".wrapText(), "")
26-
) { (actual, expected) ->
26+
) { actual, expected ->
2727
actual shouldBe expected
2828
}
2929

3030
@Test
31-
fun `appendRepeat`() = parameterized(
31+
fun `appendRepeat`() = forall(
3232
row("a", 0, ""),
3333
row("a", 1, "a"),
3434
row("a", 2, "aa"),
3535
row("a", 3, "aaa"),
3636
row("ab", 2, "abab")
37-
) { (text, repeat, expected) ->
37+
) { text, repeat, expected ->
3838
StringBuilder().appendRepeat(text, repeat).toString() shouldBe expected
3939
}
4040
}

clikt/src/test/kotlin/com/github/ajalt/clikt/parameters/ArgumentTest.kt

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ import com.github.ajalt.clikt.parameters.arguments.validate
2121
import com.github.ajalt.clikt.parameters.options.counted
2222
import com.github.ajalt.clikt.parameters.options.option
2323
import com.github.ajalt.clikt.testing.NeverCalledCliktCommand
24-
import com.github.ajalt.clikt.testing.parameterized
25-
import com.github.ajalt.clikt.testing.row
2624
import com.github.ajalt.clikt.testing.splitArgv
25+
import io.kotlintest.data.forall
2726
import io.kotlintest.matchers.string.contain
2827
import io.kotlintest.should
2928
import io.kotlintest.shouldBe
3029
import io.kotlintest.shouldNotBe
3130
import io.kotlintest.shouldThrow
31+
import io.kotlintest.tables.row
3232
import org.junit.Assert.assertFalse
3333
import org.junit.Assert.assertTrue
3434
import org.junit.Test
3535

36+
@Suppress("unused")
3637
class ArgumentTest {
3738
@Test
3839
fun `one required argument`() {
@@ -45,9 +46,9 @@ class ArgumentTest {
4546
}
4647

4748
@Test
48-
fun `one optional argument`() = parameterized(
49+
fun `one optional argument`() = forall(
4950
row("", null)
50-
) { (argv, expected) ->
51+
) { argv, expected ->
5152
class C : CliktCommand() {
5253
val x by argument().optional()
5354
override fun run() {
@@ -59,9 +60,9 @@ class ArgumentTest {
5960
}
6061

6162
@Test
62-
fun `one default argument`() = parameterized(
63+
fun `one default argument`() = forall(
6364
row("", "def")
64-
) { (argv, expected) ->
65+
) { argv, expected ->
6566
class C : CliktCommand() {
6667
val x by argument().default("def")
6768
override fun run() {
@@ -73,9 +74,9 @@ class ArgumentTest {
7374
}
7475

7576
@Test
76-
fun `defaultLazy argument`() = parameterized(
77+
fun `defaultLazy argument`() = forall(
7778
row("", "default", true)
78-
) { (argv, expected, ec) ->
79+
) { argv, expected, ec ->
7980
var called = false
8081

8182
class C : CliktCommand() {
@@ -106,9 +107,9 @@ class ArgumentTest {
106107
}
107108

108109
@Test
109-
fun `one optional argument nvalues=2`() = parameterized(
110+
fun `one optional argument nvalues=2`() = forall(
110111
row("", null)
111-
) { (argv, expected) ->
112+
) { argv, expected ->
112113
class C : CliktCommand() {
113114
val x by argument().pair().optional()
114115
override fun run() {
@@ -120,9 +121,9 @@ class ArgumentTest {
120121
}
121122

122123
@Test
123-
fun `one optional argument nvalues=3`() = parameterized(
124+
fun `one optional argument nvalues=3`() = forall(
124125
row("", null)
125-
) { (argv, expected) ->
126+
) { argv, expected ->
126127
class C : CliktCommand() {
127128
val x by argument().triple().optional()
128129
override fun run() {
@@ -160,11 +161,11 @@ class ArgumentTest {
160161
}
161162

162163
@Test
163-
fun `one argument nvalues=-1`() = parameterized(
164+
fun `one argument nvalues=-1`() = forall(
164165
row("", emptyList()),
165166
row("foo bar", listOf("foo", "bar")),
166167
row("foo bar baz", listOf("foo", "bar", "baz"))
167-
) { (argv, expected) ->
168+
) { argv, expected ->
168169
class C : CliktCommand() {
169170
val x by argument().multiple()
170171
override fun run() {
@@ -176,10 +177,10 @@ class ArgumentTest {
176177
}
177178

178179
@Test
179-
fun `two arguments nvalues=-1,1`() = parameterized(
180+
fun `two arguments nvalues=-1,1`() = forall(
180181
row("foo", emptyList(), "foo"),
181182
row("foo bar baz", listOf("foo", "bar"), "baz")
182-
) { (argv, ex, ey) ->
183+
) { argv, ex, ey ->
183184
class C : CliktCommand() {
184185
val foo by argument().multiple()
185186
val bar by argument()
@@ -204,11 +205,11 @@ class ArgumentTest {
204205
}
205206

206207
@Test
207-
fun `two arguments nvalues=1,-1`() = parameterized(
208-
row("", null, emptyList<String>()),
208+
fun `two arguments nvalues=1,-1`() = forall(
209+
row("", null, emptyList()),
209210
row("foo bar", "foo", listOf("bar")),
210211
row("foo bar baz", "foo", listOf("bar", "baz"))
211-
) { (argv, ex, ey) ->
212+
) { argv, ex, ey ->
212213
class C : CliktCommand() {
213214
val foo by argument().optional()
214215
val bar by argument().multiple()
@@ -233,9 +234,9 @@ class ArgumentTest {
233234
}
234235

235236
@Test
236-
fun `value -- with argument`() = parameterized(
237+
fun `value -- with argument`() = forall(
237238
row("--xx --xx -- --xx", "--xx", "--xx")
238-
) { (argv, ex, ey) ->
239+
) { argv, ex, ey ->
239240
class C : CliktCommand() {
240241
val x by option("-x", "--xx")
241242
val y by argument()
@@ -356,9 +357,9 @@ class ArgumentTest {
356357
}
357358

358359
@Test
359-
fun `punctuation in arg prefix unix style`() = parameterized(
360+
fun `punctuation in arg prefix unix style`() = forall(
360361
row("/foo")
361-
) { (argv) ->
362+
) { argv ->
362363
class C : CliktCommand() {
363364
val x by argument()
364365
override fun run() {
@@ -378,10 +379,10 @@ class ArgumentTest {
378379
}
379380

380381
@Test
381-
fun `punctuation in arg prefix windows style`() = parameterized(
382+
fun `punctuation in arg prefix windows style`() = forall(
382383
row("-foo"),
383384
row("--foo")
384-
) { (argv) ->
385+
) { argv ->
385386
class C : CliktCommand() {
386387
init {
387388
context { helpOptionNames = setOf("/help") }

clikt/src/test/kotlin/com/github/ajalt/clikt/parameters/EnvvarOptionsTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import com.github.ajalt.clikt.parameters.options.option
1111
import com.github.ajalt.clikt.parameters.options.validate
1212
import com.github.ajalt.clikt.parameters.types.file
1313
import com.github.ajalt.clikt.parameters.types.int
14-
import com.github.ajalt.clikt.testing.parameterized
15-
import com.github.ajalt.clikt.testing.row
1614
import com.github.ajalt.clikt.testing.splitArgv
15+
import io.kotlintest.data.forall
1716
import io.kotlintest.shouldBe
17+
import io.kotlintest.tables.row
1818
import org.junit.Rule
1919
import org.junit.Test
2020
import org.junit.contrib.java.lang.system.EnvironmentVariables
@@ -137,10 +137,12 @@ class EnvvarOptionsTest {
137137
}
138138

139139
@Test
140-
fun `flag envvars`() = parameterized(
140+
fun `flag envvars`() = forall(
141141
row(null, null, false, 0),
142142
row("YES", "3", true, 3),
143-
row("false", "5", false, 5)) { (fv, bv, ef, eb) ->
143+
row("false", "5", false, 5)
144+
) { fv, bv, ef, eb ->
145+
144146
env["FOO"] = fv
145147
env["BAR"] = bv
146148

0 commit comments

Comments
 (0)