From 8aabbc3477e684a72fa9dca456d8c28841ed655a Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Tue, 29 Jan 2019 10:38:59 -0500 Subject: [PATCH] Improve invalid iOS regex error message --- test_runner/src/main/kotlin/ftl/args/IosArgs.kt | 14 +++++++++----- .../src/test/kotlin/ftl/args/IosArgsTest.kt | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/args/IosArgs.kt b/test_runner/src/main/kotlin/ftl/args/IosArgs.kt index 504dbb1a95..be78773100 100644 --- a/test_runner/src/main/kotlin/ftl/args/IosArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/IosArgs.kt @@ -159,15 +159,19 @@ ${listToString(testTargets)} } } -fun filterTests(validTestMethods: List, testTargets: List): List { - if (testTargets.isEmpty()) { +fun filterTests(validTestMethods: List, testTargetsRgx: List): List { + if (testTargetsRgx.isEmpty()) { return validTestMethods } return validTestMethods.filter { test -> - testTargets.forEach { target -> - if (test.matches(target.toRegex())) { - return@filter true + testTargetsRgx.forEach { target -> + try { + if (test.matches(target.toRegex())) { + return@filter true + } + } catch (e: Exception) { + throw IllegalArgumentException("Invalid regex: $target", e) } } diff --git a/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt b/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt index 98873cab4e..b47860d132 100644 --- a/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt @@ -626,6 +626,11 @@ IosArgs "ClassFourTest/testFour" ) + @Test(expected = IllegalArgumentException::class) + fun `invalid regex filter throws custom exception`() { + filterTests(listOf("test"), testTargetsRgx = listOf("*.")) + } + @Test fun filterTests_emptyFilter() { val tests = getValidTestsSample()