Skip to content

Commit

Permalink
add support for rule customization scala test color and stack trace o… (
Browse files Browse the repository at this point in the history
#268)

* add support for rule customization scala test color and stack trace output

* factor out scala test flags func and use developer friendly test defaults
  • Loading branch information
softprops authored and johnynek committed Aug 30, 2017
1 parent dffcc54 commit 3f0b442
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions scala/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,17 @@ trap finish EXIT

return _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels)

def _scala_test_flags(ctx):
# output report test duration
flags = "-oD"
if ctx.attr.full_stacktraces:
flags += "F"
else:
flags += "S"
if not ctx.attr.colors:
flags += "W"
return flags

def _scala_test_impl(ctx):
if len(ctx.attr.suites) != 0:
print(
Expand All @@ -684,7 +695,7 @@ def _scala_test_impl(ctx):

args = " ".join([
"-R \"{path}\"".format(path=ctx.outputs.jar.short_path),
"-oWDS",
_scala_test_flags(ctx),
"-C io.bazel.rules.scala.JUnitXmlReporter ",
])
# main_class almost has to be "org.scalatest.tools.Runner" due to args....
Expand Down Expand Up @@ -852,6 +863,8 @@ scala_test = rule(
attrs={
"main_class": attr.string(default="io.bazel.rulesscala.scala_test.Runner"),
"suites": attr.string_list(),
"colors": attr.bool(default=True),
"full_stacktraces": attr.bool(default=True),
"_scalatest": attr.label(default=Label("//external:io_bazel_rules_scala/dependency/scalatest/scalatest"), allow_files=True),
"_scalatest_runner": attr.label(executable=True, cfg="host", default=Label("//src/java/io/bazel/rulesscala/scala_test:runner.jar"), allow_files=True),
"_scalatest_reporter": attr.label(default=Label("//scala/support:test_reporter")),
Expand Down Expand Up @@ -987,11 +1000,12 @@ def _sanitize_string_for_usage(s):
# This auto-generates a test suite based on the passed set of targets
# we will add a root test_suite with the name of the passed name
def scala_test_suite(name, srcs = [], deps = [], runtime_deps = [], data = [], resources = [],
scalacopts = [], jvm_flags = [], visibility = None, size = None):
scalacopts = [], jvm_flags = [], visibility = None, size = None,
colors=True, full_stacktraces=True):
ts = []
for test_file in srcs:
n = "%s_test_suite_%s" % (name, _sanitize_string_for_usage(test_file))
scala_test(name = n, srcs = [test_file], deps = deps, runtime_deps = runtime_deps, resources=resources, scalacopts=scalacopts, jvm_flags=jvm_flags, visibility=visibility, size=size)
scala_test(name = n, srcs = [test_file], deps = deps, runtime_deps = runtime_deps, resources=resources, scalacopts=scalacopts, jvm_flags=jvm_flags, visibility=visibility, size=size, colors=colors, full_stacktraces=full_stacktraces)
ts.append(n)
native.test_suite(name = name, tests = ts, visibility = visibility)

Expand Down

0 comments on commit 3f0b442

Please sign in to comment.