Skip to content

Commit

Permalink
Customizable phases tests
Browse files Browse the repository at this point in the history
  • Loading branch information
borkaehw committed Oct 25, 2019
1 parent e33d1c6 commit 132606e
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/phase/BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
7 changes: 7 additions & 0 deletions test/phase/HelloBinary.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package scalarules.test.phase

object HelloBinary {
def main(args: Array[String]) {
println("You can customize binary phases!")
}
}
5 changes: 5 additions & 0 deletions test/phase/HelloLibrary.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package scalarules.test.phase

object HelloLibrary {
println("You can customize library phases!")
}
35 changes: 35 additions & 0 deletions test/phase/customizability_test.bzl
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions test/phase/phase_customizability_test.bzl
Original file line number Diff line number Diff line change
@@ -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")
19 changes: 19 additions & 0 deletions test/shell/test_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions test/shell/test_phase.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test_rules_scala.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 132606e

Please sign in to comment.