Skip to content

Commit

Permalink
fix: Size annotations support (#994)
Browse files Browse the repository at this point in the history
* Add androidx size annotations support

* Update size samples to match all annotation generations
  • Loading branch information
pgreze authored Aug 21, 2020
1 parent 61aad57 commit bca93b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 13 additions & 3 deletions test_runner/src/main/kotlin/ftl/filter/TestFilters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object TestFilters {
Pattern.compile("""($pattern)\s+(.+)""")
}

private enum class Size(val annotation: String) {
private enum class Size(val annotationName: String) {
LARGE("LargeTest"),
MEDIUM("MediumTest"),
SMALL("SmallTest");
Expand Down Expand Up @@ -114,8 +114,18 @@ object TestFilters {
}
}

private fun withSize(args: List<String>): TestFilter =
withAnnotation(args.map { Size.from(it).annotation })
private fun withSize(args: List<String>): TestFilter = args.map { Size.from(it).annotationName }.let { annotationNames ->
TestFilter(
describe = "withSize (${annotationNames.joinToString(", ")})",
shouldRun = { testMethod ->
// Ensure that all annotation with a name matching this size are detected, like
// https://developer.android.com/reference/android/support/test/filters/LargeTest or
// https://developer.android.com/reference/androidx/test/filters/LargeTest
testMethod.annotationNames.any { it.split(".").last() in annotationNames }
},
isAnnotation = true
)
}

private fun fromTestFile(args: List<String>): TestFilter {
require(args.size == 1) { "Invalid file path" }
Expand Down
8 changes: 5 additions & 3 deletions test_runner/src/test/kotlin/ftl/filter/TestFiltersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ val WITH_FOO_ANNOTATION = TestMethod("whatever.Foo#testName", listOf(TestAnnotat
val WITH_BAR_ANNOTATION = TestMethod("whatever.Foo#testName", listOf(TestAnnotation("Bar", emptyMap(), false)))
val WITHOUT_FOO_ANNOTATION = TestMethod("whatever.Foo#testName", emptyList())
val WITH_FOO_ANNOTATION_AND_PACKAGE = TestMethod("foo.Bar#testName", listOf(TestAnnotation("Foo", emptyMap(), false)))
val WITH_LARGE_ANNOTATION = TestMethod("whatever.Foo#testName", listOf(TestAnnotation("LargeTest", emptyMap(), false)))
val WITH_LARGE_ANNOTATION =
TestMethod("whatever.Foo#testName", listOf(TestAnnotation("android.test.suitebuilder.annotation.LargeTest", emptyMap(), false)))
val WITH_MEDIUM_ANNOTATION =
TestMethod("whatever.Foo#testName", listOf(TestAnnotation("MediumTest", emptyMap(), false)))
val WITH_SMALL_ANNOTATION = TestMethod("whatever.Foo#testName", listOf(TestAnnotation("SmallTest", emptyMap(), false)))
TestMethod("whatever.Foo#testName", listOf(TestAnnotation("android.support.test.filters.MediumTest", emptyMap(), false)))
val WITH_SMALL_ANNOTATION =
TestMethod("whatever.Foo#testName", listOf(TestAnnotation("androidx.test.filters.SmallTest", emptyMap(), false)))
val WITHOUT_LARGE_ANNOTATION = TestMethod("whatever.Foo#testName", emptyList())
val WITHOUT_MEDIUM_ANNOTATION = TestMethod("whatever.Foo#testName", emptyList())
val WITHOUT_SMALL_ANNOTATION = TestMethod("whatever.Foo#testName", emptyList())
Expand Down

0 comments on commit bca93b4

Please sign in to comment.