Skip to content

Latest commit

 

History

History
127 lines (90 loc) · 3.91 KB

scala.md

File metadata and controls

127 lines (90 loc) · 3.91 KB

Core usage

Workers

To run JVM processes as persistent workers,

--strategy=ScalaCheckDeps=worker
--strategy=ScalaCompile=worker
--strategy=SingleJar=worker

You may pass additional flags to worker JVMs:

--worker_extra_flag=ScalaCompile=--jvm_flag=-Xmx=1g
--worker_extra_flag=ScalaCompile=--jvm_flag=-XX:SoftRefLRUPolicyMSPerMB=50

The directory is resolved relative to bazel info execution_root. It should be relative, so as to be scoped to the workspace. (It is not safe for use by multiple Bazel instances.) Stateful compilation is currently not compatible with --worker_sandboxing.

Strict & unused deps

This feature shares concepts with Java strict and unused deps. The default toolchain uses two defines (--define=scala_deps_x=y):

  • scala_deps_direct - Require that direct usages of libraries come only from immediately declared deps.
  • scala_deps_used - Require that any immediate deps are deps are directly used.

Each define may have a value of:

  • error - Check before creating the jar. (default)
  • off - Do not check.

Failed checks emit suggested buildozer commands.

You may also toggle deps check via configure_zinc_scala:

  • deps_direct - Work the same as scala_deps_direct.
  • deps_used - Work the same as scala_deps_used.

Tests

scala_test supports

Example Commands

Run tests

$ bazel test :mytest

Pass arguments to underlying test framework

$ bazel test --test_arg=--framework_args='-oDF -l org.scalatest.tags.Slow' :mytest

Debug JVM on port 5005

$ bazel test --test_arg=--debug=5005 :mytest

Limit heap space to 1GB

$ bazel test --test_arg=--jvm_arg='-Xmx 1G' :mytest

Don't use ANSI color codes

$ bazel test --test_arg=--color=false

Reduce logs

$ bazel test --test_arg=--verbosity=LOW

Generate local script to run tests

$ bazel run --script_path=script :mytest

Run tests one at a time and see output as the tests run

$ bazel test --test_output=streamed :mytest

Stop tests from being cached

$ bazel test --nocache_test_results :mytest

Run tests multiple times to test stability

$ bazel test --runs_per_test=100 :mytest

Isolation

The isolation parameter determines how tests are isolated from each other.

  • "none" (default) - Tests in a shard are run in the same JVM process. This is fastest.
  • "classloader" - Each test is run in a separate classloader. This protects against most global state. Any deps listed shared_deps do not have their classes reloaded.
  • "process" - Each test runs in a new JVM process. This protects against global state and memory leaks. jvm_flags applies to both the parent process and the subprocess. JVM flags added via --test_arg= apply only to the parent, unless --test_arg=--subprocess_arg= is used, e.g. --test_arg=--subprocess_arg=--debug=5005.