Skip to content

Commit 35d715e

Browse files
Improve invalid iOS regex error message (#479)
1 parent 9d84156 commit 35d715e

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

test_runner/src/main/kotlin/ftl/args/IosArgs.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,19 @@ ${listToString(testTargets)}
159159
}
160160
}
161161

162-
fun filterTests(validTestMethods: List<String>, testTargets: List<String>): List<String> {
163-
if (testTargets.isEmpty()) {
162+
fun filterTests(validTestMethods: List<String>, testTargetsRgx: List<String>): List<String> {
163+
if (testTargetsRgx.isEmpty()) {
164164
return validTestMethods
165165
}
166166

167167
return validTestMethods.filter { test ->
168-
testTargets.forEach { target ->
169-
if (test.matches(target.toRegex())) {
170-
return@filter true
168+
testTargetsRgx.forEach { target ->
169+
try {
170+
if (test.matches(target.toRegex())) {
171+
return@filter true
172+
}
173+
} catch (e: Exception) {
174+
throw IllegalArgumentException("Invalid regex: $target", e)
171175
}
172176
}
173177

test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,11 @@ IosArgs
626626
"ClassFourTest/testFour"
627627
)
628628

629+
@Test(expected = IllegalArgumentException::class)
630+
fun `invalid regex filter throws custom exception`() {
631+
filterTests(listOf("test"), testTargetsRgx = listOf("*."))
632+
}
633+
629634
@Test
630635
fun filterTests_emptyFilter() {
631636
val tests = getValidTestsSample()

0 commit comments

Comments
 (0)