-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
load( | ||
"//test/phase:customizability_test.bzl", | ||
"add_phase_customizability_test_singleton", | ||
"customizability_test_scala_binary", | ||
"customizability_test_scala_library", | ||
"customizability_test_scala_test", | ||
) | ||
|
||
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"], | ||
custom_content = "This is custom content in library", | ||
) | ||
|
||
customizability_test_scala_test( | ||
name = "HelloTest", | ||
srcs = ["HelloTest.scala"], | ||
custom_content = "This is custom content in test", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) { | ||
val message = "You can customize binary phases!" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package scalarules.test.phase | ||
|
||
object HelloLibrary { | ||
val message = "You can customize library phases!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package scalarules.test.phase | ||
|
||
import org.scalatest._ | ||
|
||
class HelloTest extends FlatSpec { | ||
val message = "You can customize test phases!" | ||
"HelloTest" should "be able to customize test phases!" in { | ||
assert(message.equals("You can customize test phases!")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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", | ||
_make_scala_test = "make_scala_test", | ||
) | ||
|
||
ext_add_phase_customizability_test = { | ||
"attrs": { | ||
"custom_content": attr.string( | ||
default = "This is custom content", | ||
), | ||
}, | ||
"outputs": { | ||
"custom_output": "%{name}.custom-output" | ||
}, | ||
"phase_providers": [ | ||
"//test/phase:phase_customizability_test", | ||
], | ||
} | ||
|
||
def _add_phase_customizability_test_singleton_implementation(ctx): | ||
return [ | ||
_ScalaRulePhase( | ||
phases = [ | ||
("-", "final", "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) | ||
customizability_test_scala_test = _make_scala_test(ext_add_phase_customizability_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# | ||
# PHASE: customizability test | ||
# | ||
# A dummy test phase to make sure rules are customizable | ||
# | ||
def phase_customizability_test(ctx, p): | ||
ctx.actions.write( | ||
output = ctx.outputs.custom_output, | ||
content = ctx.attr.custom_content, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 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}") | ||
|
||
output_file_should_contain_message() { | ||
set +e | ||
MSG=$1 | ||
TEST_ARG=${@:2} | ||
OUTPUT_FILE=$(echo ${@:3} | sed 's#//#/#g;s#:#/#g') | ||
OUTPUT_PATH=$(bazel info bazel-bin)/$OUTPUT_FILE | ||
bazel $TEST_ARG | ||
RESPONSE_CODE=$? | ||
cat $OUTPUT_PATH | 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 \"$MSG\" in file \"$OUTPUT_FILE\" but did not. $NC" | ||
exit 1 | ||
else | ||
exit 0 | ||
fi | ||
} | ||
test_scala_binary_with_extra_phase() { | ||
output_file_should_contain_message \ | ||
"This is custom content" \ | ||
build //test/phase:HelloBinary.custom-output | ||
} | ||
|
||
test_scala_library_with_extra_phase_and_custom_content() { | ||
output_file_should_contain_message \ | ||
"This is custom content in library" \ | ||
build //test/phase:HelloLibrary.custom-output | ||
} | ||
|
||
test_scala_test_with_extra_phase_and_custom_content() { | ||
output_file_should_contain_message \ | ||
"This is custom content in test" \ | ||
build //test/phase:HelloTest.custom-output | ||
} | ||
|
||
$runner test_scala_binary_with_extra_phase | ||
$runner test_scala_library_with_extra_phase_and_custom_content | ||
$runner test_scala_test_with_extra_phase_and_custom_content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters