Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Size annotations support #994

Merged
merged 2 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original implementation was reusing withAnnotation so isAnnotation was true + size is annotation based I figure. Please let me know if this make sense or this was supposed to only match (not)withAnnotation instructions.

)
}

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