From 80d7b574b35710bbdbda7f903e6a4f0a9c4073e8 Mon Sep 17 00:00:00 2001 From: Pawel Pasterz Date: Mon, 12 Oct 2020 14:54:22 +0200 Subject: [PATCH] Fix withClassName filter --- .../src/main/kotlin/ftl/filter/TestFilters.kt | 20 +++++++---- .../test/kotlin/ftl/filter/TestFiltersTest.kt | 36 +++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/filter/TestFilters.kt b/test_runner/src/main/kotlin/ftl/filter/TestFilters.kt index 772f316d70..209c8e80a9 100644 --- a/test_runner/src/main/kotlin/ftl/filter/TestFilters.kt +++ b/test_runner/src/main/kotlin/ftl/filter/TestFilters.kt @@ -150,12 +150,20 @@ object TestFilters { } ) - private fun withClassName(classNames: List): TestFilter = TestFilter( - describe = "withClassName (${classNames.joinToString(", ")})", - shouldRun = { testMethod -> - withPackageName(classNames).shouldRun(testMethod) - } - ) + private fun withClassName(classNames: List): TestFilter { + val splittedClassNames = classNames.map { it.split("#") } + return TestFilter( + describe = "withClassName (${classNames.joinToString(", ")})", + shouldRun = { testMethod -> + val splittedName = testMethod.testName.split("#") + splittedClassNames.any { className -> + // className.size == 1 => foo.bar.TestClass1 + // className.size != 1 => foo.bar.TestClass1#testMethod1 + splittedName[0] == className[0] && (className.size == 1 || splittedName[1] == className[1]) + } + } + ) + } private fun withAnnotation(annotations: List): TestFilter = TestFilter( describe = "withAnnotation (${annotations.joinToString(", ")})", diff --git a/test_runner/src/test/kotlin/ftl/filter/TestFiltersTest.kt b/test_runner/src/test/kotlin/ftl/filter/TestFiltersTest.kt index 6173266a34..b5c382b594 100644 --- a/test_runner/src/test/kotlin/ftl/filter/TestFiltersTest.kt +++ b/test_runner/src/test/kotlin/ftl/filter/TestFiltersTest.kt @@ -358,6 +358,42 @@ class TestFiltersTest { assertThat(filter.shouldRun(BAR_PACKAGE)).isFalse() assertThat(filter.shouldRun(BAR_CLASSNAME)).isTrue() } + + @Test + fun `withClassName should correctly filter classes with similar name`() { + // test-targets: + // - class foo.bar.Class1 + // should filter foo.bar.Class11, foo.bar.Class101 ... + // the same is applicable for methods + + val filter = fromTestTargets( + listOf( + "class anyPackage_1.anyClass_1", + "class anyPackage_3.anyClass_3#anyMethod_3" + ) + ) + + val tests = listOf( + TargetsHelper(pack = "anyPackage_1", cl = "anyClass_1", m = "anyMethod_1", annotation = "Foo"), + TargetsHelper(pack = "anyPackage_1", cl = "anyClass_1", m = "anyMethod_2", annotation = "Foo"), + TargetsHelper(pack = "anyPackage_1", cl = "anyClass_12", m = "anyMethod_1", annotation = "Bar"), + TargetsHelper(pack = "anyPackage_1", cl = "anyClass_12", m = "anyMethod_12", annotation = "Bar"), + TargetsHelper(pack = "anyPackage_3", cl = "anyClass_3", m = "anyMethod_3", annotation = "Bar"), + TargetsHelper(pack = "anyPackage_3", cl = "anyClass_3", m = "anyMethod_32", annotation = "Bar"), + TargetsHelper(pack = "anyPackage_3", cl = "anyClass_32", m = "anyMethod_3", annotation = "Bar"), + TargetsHelper(pack = "anyPackage_3", cl = "anyClass_32", m = "anyMethod_32", annotation = "Bar") + ).map { getDefaultTestMethod(it.fullView, it.annotation) } + + val expected = listOf( + "anyPackage_1.anyClass_1#anyMethod_1", + "anyPackage_1.anyClass_1#anyMethod_2", + "anyPackage_3.anyClass_3#anyMethod_3" + ) + + val result = tests.withFilter(filter) + + assertThat(result).isEqualTo(expected) + } } private fun getDefaultTestMethod(testName: String, annotation: String) =