Skip to content

Commit

Permalink
Revert "Specs2 filtering runner now filters test cases according to f…
Browse files Browse the repository at this point in the history
…ilter. (#759)"

This reverts commit 300b436.
  • Loading branch information
ittaiz committed Jun 5, 2019
1 parent ccb913d commit eea3df4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 38 deletions.
31 changes: 10 additions & 21 deletions src/java/io/bazel/rulesscala/specs2/Specs2RunnerBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ object Specs2FilteringRunnerBuilder {
class FilteredSpecs2ClassRunner(testClass: Class[_], testFilter: Pattern)
extends org.specs2.runner.JUnitRunner(testClass) {

override def getDescription(env: Env): Description = {
val root = super.getDescription(env)
val filtered = flatten(root).filter(matchingFilter)

val flattenedRoot = root.childlessCopy()
filtered.foreach(flattenedRoot.addChild)
flattenedRoot
}

def matchesFilter: Boolean = {
val fqn = testClass.getName + "#"
val matcher = testFilter.matcher(fqn)
Expand Down Expand Up @@ -115,24 +106,22 @@ class FilteredSpecs2ClassRunner(testClass: Class[_], testFilter: Pattern)
*
* This function returns a flat list of the descriptions and their children, starting with the root.
*/
def flatten(root: Description): List[Description] = {
def flatten0(desc: Description, xs: List[Description]): List[Description] =
desc.childlessCopy() :: desc.getChildren.asScala.foldLeft(xs)((acc, x) => flatten0(x, acc))

flatten0(root, Nil)
}
private def flattenDescription(description: Description): List[Description] =
description.getChildren.asScala.toList.flatMap(d => d :: flattenDescription(d))

private def matchingFilter(desc: Description): Boolean = {
val testCase = desc.getClassName + "#" + desc.getMethodName
testFilter.toString.r.findAllIn(testCase).nonEmpty
private def matching(testFilter: Pattern): Description => Boolean = { d =>
val testCase = d.getClassName + "#" + d.getMethodName
testFilter.matcher(testCase).matches
}

private def specs2Examples(implicit ee: ExecutionEnv): List[String] =
flatten(getDescription).flatMap(toDisplayName(_))
private def specs2ExamplesMatching(testFilter: Pattern, junitDescription: Description)(implicit ee: ExecutionEnv): List[String] =
flattenDescription(junitDescription)
.filter(matching(testFilter))
.flatMap(toDisplayName(_))

override def runWithEnv(n: RunNotifier, env: Env): Action[Stats] = {
implicit val ee = env.executionEnv
val specs2MatchedExamplesRegex = specs2Examples.toRegexAlternation
val specs2MatchedExamplesRegex = specs2ExamplesMatching(testFilter, getDescription).toRegexAlternation

val newArgs = Arguments(select = Select(_ex = specs2MatchedExamplesRegex), commandLine = CommandLine.create(testClass.getName))
val newEnv = env.copy(arguments overrideWith newArgs)
Expand Down
17 changes: 0 additions & 17 deletions test_rules_scala.sh
Original file line number Diff line number Diff line change
Expand Up @@ -512,22 +512,6 @@ scala_specs2_junit_test_test_filter_one_test(){
fi
}

scala_specs2_only_filtered_test_shows_in_the_xml(){
bazel test \
--nocache_test_results \
--test_output=streamed \
'--test_filter=scalarules.test.junit.specs2.JunitSpecs2Test#specs2 tests should::run smoothly in bazel$' \
test:Specs2Tests
matches=$(grep -c -e "testcase name='specs2 tests should::run smoothly in bazel'" -e "testcase name='specs2 tests should::not run smoothly in bazel'" ./bazel-testlogs/test/Specs2Tests/test.xml)
if [ $matches -eq 1 ]; then
return 0
else
echo "Expecting only one result, found more than one. Please check 'bazel-testlogs/test/Specs2Tests/test.xml'"
return 1
fi
test -e
}

scala_specs2_junit_test_test_filter_exact_match(){
local output=$(bazel test \
--nocache_test_results \
Expand Down Expand Up @@ -1002,7 +986,6 @@ $runner scala_specs2_junit_test_test_filter_exact_match_escaped_and_sanitized
$runner scala_specs2_junit_test_test_filter_match_multiple_methods
$runner scala_specs2_exception_in_initializer_without_filter
$runner scala_specs2_exception_in_initializer_terminates_without_timeout
$runner scala_specs2_only_filtered_test_shows_in_the_xml
$runner scalac_jvm_flags_are_configured
$runner javac_jvm_flags_are_configured
$runner javac_jvm_flags_via_javacopts_are_configured
Expand Down

0 comments on commit eea3df4

Please sign in to comment.