Skip to content

Split sh test #849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/shell/test_build_event_protocol.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# shellcheck source=./test_runner.sh
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
. "${dir}"/test_runner.sh
runner=$(get_test_runner "${1:-local}")

scala_binary_common_jar_is_exposed_in_build_event_protocol() {
local target=$1
set +e
bazel build test:$target --build_event_text_file=$target_bes.txt
cat $target_bes.txt | grep "test/$target.jar"
if [ $? -ne 0 ]; then
echo "test/$target.jar was not found in build event protocol:"
cat $target_bes.txt
rm $target_bes.txt
exit 1
fi

rm $target_bes.txt
set -e
}

scala_binary_jar_is_exposed_in_build_event_protocol() {
scala_binary_common_jar_is_exposed_in_build_event_protocol ScalaLibBinary
}

scala_test_jar_is_exposed_in_build_event_protocol() {
scala_binary_common_jar_is_exposed_in_build_event_protocol HelloLibTest
}

scala_junit_test_jar_is_exposed_in_build_event_protocol() {
scala_binary_common_jar_is_exposed_in_build_event_protocol JunitTestWithDeps
}

$runner scala_binary_jar_is_exposed_in_build_event_protocol
$runner scala_test_jar_is_exposed_in_build_event_protocol
$runner scala_junit_test_jar_is_exposed_in_build_event_protocol
31 changes: 31 additions & 0 deletions test/shell/test_compilation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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_compilation_succeeds_with_plus_one_deps_on() {
bazel build --extra_toolchains=//test_expect_failure/plus_one_deps:plus_one_deps //test_expect_failure/plus_one_deps/internal_deps:a
}

test_compilation_fails_with_plus_one_deps_undefined() {
action_should_fail build //test_expect_failure/plus_one_deps/internal_deps:a
}

test_compilation_succeeds_with_plus_one_deps_on_for_external_deps() {
bazel build --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps" //test_expect_failure/plus_one_deps/external_deps:a
}

test_compilation_succeeds_with_plus_one_deps_on_also_for_exports_of_deps() {
bazel build --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps" //test_expect_failure/plus_one_deps/exports_of_deps/...
}

test_compilation_succeeds_with_plus_one_deps_on_also_for_deps_of_exports() {
bazel build --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps" //test_expect_failure/plus_one_deps/deps_of_exports/...
}

$runner test_compilation_succeeds_with_plus_one_deps_on
$runner test_compilation_fails_with_plus_one_deps_undefined
$runner test_compilation_succeeds_with_plus_one_deps_on_for_external_deps
$runner test_compilation_succeeds_with_plus_one_deps_on_also_for_exports_of_deps
$runner test_compilation_succeeds_with_plus_one_deps_on_also_for_deps_of_exports
48 changes: 48 additions & 0 deletions test/shell/test_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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_scala_import_library_passes_labels_of_direct_deps() {
dependency_target='//test_expect_failure/scala_import:root_for_scala_import_passes_labels_of_direct_deps'
test_target='test_expect_failure/scala_import:leaf_for_scala_import_passes_labels_of_direct_deps'

test_scala_library_expect_failure_on_missing_direct_deps $dependency_target $test_target
}

test_plus_one_deps_only_works_for_java_info_targets() {
#for example doesn't break scala proto which depends on proto_library
bazel build --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps" //test/proto:test_proto
}

scala_pb_library_targets_do_not_have_host_deps() {
set -e
bazel build test/proto:test_binary_to_ensure_no_host_deps
set +e
find bazel-bin/test/proto/test_binary_to_ensure_no_host_deps.runfiles -name '*.jar' -exec readlink {} \; | grep 'bazel-out/host'
RET=$?
set -e
if [ "$RET" == "0" ]; then
echo "Host deps exist in output of target:"
echo "Possibly toolchains limitation?"
find bazel-bin/test/proto/test_binary_to_ensure_no_host_deps.runfiles -name '*.jar' -exec readlink {} \; | grep 'bazel-out/host'
exit 1
fi
}

test_scala_import_expect_failure_on_missing_direct_deps_warn_mode() {
dependency_target1='//test_expect_failure/scala_import:cats'
dependency_target2='//test_expect_failure/scala_import:guava'
test_target='test_expect_failure/scala_import:scala_import_propagates_compile_deps'

local expected_message1="buildozer 'add deps $dependency_target1' //$test_target"
local expected_message2="buildozer 'add deps $dependency_target2' //$test_target"

test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message1}" ${test_target} "--strict_java_deps=warn" "ne" "${expected_message2}"
}

$runner test_scala_import_library_passes_labels_of_direct_deps
$runner test_plus_one_deps_only_works_for_java_info_targets
$runner scala_pb_library_targets_do_not_have_host_deps
$runner test_scala_import_expect_failure_on_missing_direct_deps_warn_mode
112 changes: 112 additions & 0 deletions test/shell/test_helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env bash
#
# Test helper functions for rules_scala integration tests.

action_should_fail() {
# runs the tests locally
set +e
TEST_ARG=$@
DUMMY=$(bazel $TEST_ARG)
RESPONSE_CODE=$?
if [ $RESPONSE_CODE -eq 0 ]; then
echo -e "${RED} \"bazel $TEST_ARG\" should have failed but passed. $NC"
exit -1
else
exit 0
fi
}

test_expect_failure_with_message() {
set +e

expected_message=$1
test_filter=$2
test_command=$3

command="bazel test --nocache_test_results --test_output=streamed ${test_filter} ${test_command}"
output=$(${command} 2>&1)

echo ${output} | grep "$expected_message"
if [ $? -ne 0 ]; then
echo "'bazel test ${test_command}' should have logged \"${expected_message}\"."
exit 1
fi
if [ "${additional_expected_message}" != "" ]; then
echo ${output} | grep "$additional_expected_message"
if [ $? -ne 0 ]; then
echo "'bazel test ${test_command}' should have logged \"${additional_expected_message}\"."
exit 1
fi
fi

set -e
}

action_should_fail_with_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 -eq 0 ]; then
echo -e "${RED} \"bazel $TEST_ARG\" should have failed but passed. $NC"
exit 1
elif [ $GREP_RES -ne 0 ]; then
echo -e "${RED} \"bazel $TEST_ARG\" should have failed with message \"$MSG\" but did not. $NC"
else
exit 0
fi
}

test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message() {
set +e

expected_message=$1
test_target=$2
strict_deps_mode=$3
operator=${4:-"eq"}
additional_expected_message=${5:-""}

if [ "${operator}" = "eq" ]; then
error_message="bazel build of scala_library with missing direct deps should have failed."
else
error_message="bazel build of scala_library with missing direct deps should not have failed."
fi

command="bazel build ${test_target} ${strict_deps_mode}"

output=$(${command} 2>&1)
status_code=$?

echo "$output"
if [ ${status_code} -${operator} 0 ]; then
echo ${error_message}
exit 1
fi

echo ${output} | grep "$expected_message"
if [ $? -ne 0 ]; then
echo "'bazel build ${test_target}' should have logged \"${expected_message}\"."
exit 1
fi
if [ "${additional_expected_message}" != "" ]; then
echo ${output} | grep "$additional_expected_message"
if [ $? -ne 0 ]; then
echo "'bazel build ${test_target}' should have logged \"${additional_expected_message}\"."
exit 1
fi
fi

set -e
}

test_scala_library_expect_failure_on_missing_direct_deps() {
dependenecy_target=$1
test_target=$2

local expected_message="buildozer 'add deps $dependenecy_target' //$test_target"

test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" $test_target "--strict_java_deps=error"
}
30 changes: 30 additions & 0 deletions test/shell/test_javac_jvm_flags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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}")

javac_jvm_flags_are_configured(){
action_should_fail build //test_expect_failure/compilers_jvm_flags:can_configure_jvm_flags_for_javac
}

javac_jvm_flags_via_javacopts_are_configured(){
action_should_fail build //test_expect_failure/compilers_jvm_flags:can_configure_jvm_flags_for_javac_via_javacopts
}

javac_jvm_flags_are_expanded(){
action_should_fail_with_message \
"invalid flag: test_expect_failure/compilers_jvm_flags/args.txt" \
build --verbose_failures //test_expect_failure/compilers_jvm_flags:can_expand_jvm_flags_for_javac
}

javac_jvm_flags_via_javacopts_are_expanded(){
action_should_fail_with_message \
"invalid flag: test_expect_failure/compilers_jvm_flags/args.txt" \
build --verbose_failures //test_expect_failure/compilers_jvm_flags:can_expand_jvm_flags_for_javac_via_javacopts
}

$runner javac_jvm_flags_are_configured
$runner javac_jvm_flags_via_javacopts_are_configured
$runner javac_jvm_flags_are_expanded
$runner javac_jvm_flags_via_javacopts_are_expanded
113 changes: 113 additions & 0 deletions test/shell/test_junit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# 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}")

multiple_junit_suffixes() {
bazel test //test:JunitMultipleSuffixes

matches=$(grep -c -e 'Discovered classes' -e 'scalarules.test.junit.JunitSuffixIT' -e 'scalarules.test.junit.JunitSuffixE2E' ./bazel-testlogs/test/JunitMultipleSuffixes/test.log)
if [ $matches -eq 3 ]; then
return 0
else
return 1
fi
}

multiple_junit_prefixes() {
bazel test //test:JunitMultiplePrefixes

matches=$(grep -c -e 'Discovered classes' -e 'scalarules.test.junit.TestJunitCustomPrefix' -e 'scalarules.test.junit.OtherCustomPrefixJunit' ./bazel-testlogs/test/JunitMultiplePrefixes/test.log)
if [ $matches -eq 3 ]; then
return 0
else
return 1
fi
}

multiple_junit_patterns() {
bazel test //test:JunitPrefixesAndSuffixes
matches=$(grep -c -e 'Discovered classes' -e 'scalarules.test.junit.TestJunitCustomPrefix' -e 'scalarules.test.junit.JunitSuffixE2E' ./bazel-testlogs/test/JunitPrefixesAndSuffixes/test.log)
if [ $matches -eq 3 ]; then
return 0
else
return 1
fi
}

test_scala_junit_test_can_fail() {
action_should_fail test test_expect_failure/scala_junit_test:failing_test
}

junit_generates_xml_logs() {
bazel test //test:JunitTestWithDeps
matches=$(grep -c -e "testcase name='hasCompileTimeDependencies'" -e "testcase name='hasRuntimeDependencies'" ./bazel-testlogs/test/JunitTestWithDeps/test.xml)
if [ $matches -eq 2 ]; then
return 0
else
return 1
fi
test -e
}

test_junit_test_must_have_prefix_or_suffix() {
action_should_fail test test_expect_failure/scala_junit_test:no_prefix_or_suffix
}

test_junit_test_errors_when_no_tests_found() {
action_should_fail test test_expect_failure/scala_junit_test:no_tests_found
}

scala_junit_test_test_filter(){
local output=$(bazel test \
--nocache_test_results \
--test_output=streamed \
'--test_filter=scalarules.test.junit.FirstFilterTest#(method1|method2)$|scalarules.test.junit.SecondFilterTest#(method2|method3)$' \
test:JunitFilterTest)
local expected=(
"scalarules.test.junit.FirstFilterTest#method1"
"scalarules.test.junit.FirstFilterTest#method2"
"scalarules.test.junit.SecondFilterTest#method2"
"scalarules.test.junit.SecondFilterTest#method3")
local unexpected=(
"scalarules.test.junit.FirstFilterTest#method3"
"scalarules.test.junit.SecondFilterTest#method1"
"scalarules.test.junit.ThirdFilterTest#method1"
"scalarules.test.junit.ThirdFilterTest#method2"
"scalarules.test.junit.ThirdFilterTest#method3")
for method in "${expected[@]}"; do
if ! grep "$method" <<<$output; then
echo "output:"
echo "$output"
echo "Expected $method in output, but was not found."
exit 1
fi
done
for method in "${unexpected[@]}"; do
if grep "$method" <<<$output; then
echo "output:"
echo "$output"
echo "Not expecting $method in output, but was found."
exit 1
fi
done
}

scala_junit_test_test_filter_custom_runner(){
bazel test \
--nocache_test_results \
--test_output=streamed \
'--test_filter=scalarules.test.junit.JunitCustomRunnerTest#' \
test:JunitCustomRunner
}

$runner multiple_junit_suffixes
$runner multiple_junit_prefixes
$runner multiple_junit_patterns
$runner test_scala_junit_test_can_fail
$runner junit_generates_xml_logs
$runner test_junit_test_must_have_prefix_or_suffix
$runner test_junit_test_errors_when_no_tests_found
$runner scala_junit_test_test_filter
$runner scala_junit_test_test_filter_custom_runner
Loading