diff --git a/test/phase/BUILD b/test/phase/BUILD new file mode 100644 index 0000000000..f842eef4c8 --- /dev/null +++ b/test/phase/BUILD @@ -0,0 +1,22 @@ +load( + "//test/phase:customizability_test.bzl", + "add_phase_customizability_test_singleton", + "customizability_test_scala_binary", + "customizability_test_scala_library", +) + +add_phase_customizability_test_singleton( + name = "phase_customizability_test", + visibility = ["//visibility:public"], +) + +customizability_test_scala_binary( + name = "HelloBinary", + srcs = ["HelloBinary.scala"], + main_class = "scalarules.test.phase.HelloBinary", +) + +customizability_test_scala_library( + name = "HelloLibrary", + srcs = ["HelloLibrary.scala"], +) diff --git a/test/phase/HelloBinary.scala b/test/phase/HelloBinary.scala new file mode 100644 index 0000000000..3bc83a23e2 --- /dev/null +++ b/test/phase/HelloBinary.scala @@ -0,0 +1,7 @@ +package scalarules.test.phase + +object HelloBinary { + def main(args: Array[String]) { + println("You can customize binary phases!") + } +} diff --git a/test/phase/HelloLibrary.scala b/test/phase/HelloLibrary.scala new file mode 100644 index 0000000000..8b3855fe5c --- /dev/null +++ b/test/phase/HelloLibrary.scala @@ -0,0 +1,5 @@ +package scalarules.test.phase + +object HelloLibrary { + println("You can customize library phases!") +} diff --git a/test/phase/customizability_test.bzl b/test/phase/customizability_test.bzl new file mode 100644 index 0000000000..afd1b35830 --- /dev/null +++ b/test/phase/customizability_test.bzl @@ -0,0 +1,35 @@ +load( + "//scala:providers.bzl", + _ScalaRulePhase = "ScalaRulePhase", +) +load( + "//test/phase:phase_customizability_test.bzl", + _phase_customizability_test = "phase_customizability_test", +) +load( + "//scala:scala.bzl", + _make_scala_binary = "make_scala_binary", + _make_scala_library = "make_scala_library", +) + +ext_add_phase_customizability_test = { + "phase_providers": [ + "//test/phase:phase_customizability_test", + ], +} + +def _add_phase_customizability_test_singleton_implementation(ctx): + return [ + _ScalaRulePhase( + phases = [ + ("-", "coda", "customizability_test", _phase_customizability_test), + ], + ), + ] + +add_phase_customizability_test_singleton = rule( + implementation = _add_phase_customizability_test_singleton_implementation, +) + +customizability_test_scala_binary = _make_scala_binary(ext_add_phase_customizability_test) +customizability_test_scala_library = _make_scala_library(ext_add_phase_customizability_test) diff --git a/test/phase/phase_customizability_test.bzl b/test/phase/phase_customizability_test.bzl new file mode 100644 index 0000000000..ee95c10622 --- /dev/null +++ b/test/phase/phase_customizability_test.bzl @@ -0,0 +1,7 @@ +# +# PHASE: customizability test +# +# A dummy test phase to make sure rules are customizable +# +def phase_customizability_test(ctx, p): + print("customizable phase") diff --git a/test/shell/test_helper.sh b/test/shell/test_helper.sh index 7e5f1b9891..99e42eb1b2 100755 --- a/test/shell/test_helper.sh +++ b/test/shell/test_helper.sh @@ -60,6 +60,25 @@ action_should_fail_with_message() { fi } +action_should_contain_message() { + set +e + MSG=$1 + TEST_ARG=${@:2} + RES=$(bazel $TEST_ARG 2>&1) + RESPONSE_CODE=$? + echo $RES | grep -- "$MSG" + GREP_RES=$? + if [ $RESPONSE_CODE -ne 0 ]; then + echo -e "${RED} \"bazel $TEST_ARG\" should pass but failed. $NC" + exit 1 + elif [ $GREP_RES -ne 0 ]; then + echo -e "${RED} \"bazel $TEST_ARG\" should pass with message \"$MSG\" but did not. $NC" + exit 1 + else + exit 0 + fi +} + test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message() { set +e diff --git a/test/shell/test_phase.sh b/test/shell/test_phase.sh new file mode 100755 index 0000000000..016fdf060a --- /dev/null +++ b/test/shell/test_phase.sh @@ -0,0 +1,20 @@ +# shellcheck source=./test_runner.sh +dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +. "${dir}"/test_runner.sh +. "${dir}"/test_helper.sh +runner=$(get_test_runner "${1:-local}") + +test_binary_with_extra_phase() { + action_should_contain_message \ + "customizable phase" \ + build //test/phase:HelloBinary +} + +test_library_with_extra_phase() { + action_should_contain_message \ + "customizable phase" \ + build //test/phase:HelloLibrary +} + +$runner test_binary_with_extra_phase +$runner test_library_with_extra_phase diff --git a/test_rules_scala.sh b/test_rules_scala.sh index 04b1ced740..e8456fabfe 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -29,6 +29,7 @@ $runner bazel test //test/... --extra_toolchains="//test_expect_failure/plus_one . "${test_dir}"/test_javac_jvm_flags.sh . "${test_dir}"/test_junit.sh . "${test_dir}"/test_misc.sh +. "${test_dir}"/test_phase.sh . "${test_dir}"/test_scala_binary.sh . "${test_dir}"/test_scalac_jvm_flags.sh . "${test_dir}"/test_scala_classpath.sh