Skip to content

Commit e7cce69

Browse files
borkaehwittaiz
authored andcommitted
Split sh test (#849)
* Split shell ingetration tests * Fix test_repl no target from clean build
1 parent 548bce9 commit e7cce69

20 files changed

+1241
-1125
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# shellcheck source=./test_runner.sh
2+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
3+
. "${dir}"/test_runner.sh
4+
runner=$(get_test_runner "${1:-local}")
5+
6+
scala_binary_common_jar_is_exposed_in_build_event_protocol() {
7+
local target=$1
8+
set +e
9+
bazel build test:$target --build_event_text_file=$target_bes.txt
10+
cat $target_bes.txt | grep "test/$target.jar"
11+
if [ $? -ne 0 ]; then
12+
echo "test/$target.jar was not found in build event protocol:"
13+
cat $target_bes.txt
14+
rm $target_bes.txt
15+
exit 1
16+
fi
17+
18+
rm $target_bes.txt
19+
set -e
20+
}
21+
22+
scala_binary_jar_is_exposed_in_build_event_protocol() {
23+
scala_binary_common_jar_is_exposed_in_build_event_protocol ScalaLibBinary
24+
}
25+
26+
scala_test_jar_is_exposed_in_build_event_protocol() {
27+
scala_binary_common_jar_is_exposed_in_build_event_protocol HelloLibTest
28+
}
29+
30+
scala_junit_test_jar_is_exposed_in_build_event_protocol() {
31+
scala_binary_common_jar_is_exposed_in_build_event_protocol JunitTestWithDeps
32+
}
33+
34+
$runner scala_binary_jar_is_exposed_in_build_event_protocol
35+
$runner scala_test_jar_is_exposed_in_build_event_protocol
36+
$runner scala_junit_test_jar_is_exposed_in_build_event_protocol

test/shell/test_compilation.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# shellcheck source=./test_runner.sh
2+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
3+
. "${dir}"/test_runner.sh
4+
. "${dir}"/test_helper.sh
5+
runner=$(get_test_runner "${1:-local}")
6+
7+
test_compilation_succeeds_with_plus_one_deps_on() {
8+
bazel build --extra_toolchains=//test_expect_failure/plus_one_deps:plus_one_deps //test_expect_failure/plus_one_deps/internal_deps:a
9+
}
10+
11+
test_compilation_fails_with_plus_one_deps_undefined() {
12+
action_should_fail build //test_expect_failure/plus_one_deps/internal_deps:a
13+
}
14+
15+
test_compilation_succeeds_with_plus_one_deps_on_for_external_deps() {
16+
bazel build --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps" //test_expect_failure/plus_one_deps/external_deps:a
17+
}
18+
19+
test_compilation_succeeds_with_plus_one_deps_on_also_for_exports_of_deps() {
20+
bazel build --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps" //test_expect_failure/plus_one_deps/exports_of_deps/...
21+
}
22+
23+
test_compilation_succeeds_with_plus_one_deps_on_also_for_deps_of_exports() {
24+
bazel build --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps" //test_expect_failure/plus_one_deps/deps_of_exports/...
25+
}
26+
27+
$runner test_compilation_succeeds_with_plus_one_deps_on
28+
$runner test_compilation_fails_with_plus_one_deps_undefined
29+
$runner test_compilation_succeeds_with_plus_one_deps_on_for_external_deps
30+
$runner test_compilation_succeeds_with_plus_one_deps_on_also_for_exports_of_deps
31+
$runner test_compilation_succeeds_with_plus_one_deps_on_also_for_deps_of_exports

test/shell/test_deps.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# shellcheck source=./test_runner.sh
2+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
3+
. "${dir}"/test_runner.sh
4+
. "${dir}"/test_helper.sh
5+
runner=$(get_test_runner "${1:-local}")
6+
7+
test_scala_import_library_passes_labels_of_direct_deps() {
8+
dependency_target='//test_expect_failure/scala_import:root_for_scala_import_passes_labels_of_direct_deps'
9+
test_target='test_expect_failure/scala_import:leaf_for_scala_import_passes_labels_of_direct_deps'
10+
11+
test_scala_library_expect_failure_on_missing_direct_deps $dependency_target $test_target
12+
}
13+
14+
test_plus_one_deps_only_works_for_java_info_targets() {
15+
#for example doesn't break scala proto which depends on proto_library
16+
bazel build --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps" //test/proto:test_proto
17+
}
18+
19+
scala_pb_library_targets_do_not_have_host_deps() {
20+
set -e
21+
bazel build test/proto:test_binary_to_ensure_no_host_deps
22+
set +e
23+
find bazel-bin/test/proto/test_binary_to_ensure_no_host_deps.runfiles -name '*.jar' -exec readlink {} \; | grep 'bazel-out/host'
24+
RET=$?
25+
set -e
26+
if [ "$RET" == "0" ]; then
27+
echo "Host deps exist in output of target:"
28+
echo "Possibly toolchains limitation?"
29+
find bazel-bin/test/proto/test_binary_to_ensure_no_host_deps.runfiles -name '*.jar' -exec readlink {} \; | grep 'bazel-out/host'
30+
exit 1
31+
fi
32+
}
33+
34+
test_scala_import_expect_failure_on_missing_direct_deps_warn_mode() {
35+
dependency_target1='//test_expect_failure/scala_import:cats'
36+
dependency_target2='//test_expect_failure/scala_import:guava'
37+
test_target='test_expect_failure/scala_import:scala_import_propagates_compile_deps'
38+
39+
local expected_message1="buildozer 'add deps $dependency_target1' //$test_target"
40+
local expected_message2="buildozer 'add deps $dependency_target2' //$test_target"
41+
42+
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message1}" ${test_target} "--strict_java_deps=warn" "ne" "${expected_message2}"
43+
}
44+
45+
$runner test_scala_import_library_passes_labels_of_direct_deps
46+
$runner test_plus_one_deps_only_works_for_java_info_targets
47+
$runner scala_pb_library_targets_do_not_have_host_deps
48+
$runner test_scala_import_expect_failure_on_missing_direct_deps_warn_mode

test/shell/test_helper.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Test helper functions for rules_scala integration tests.
4+
5+
action_should_fail() {
6+
# runs the tests locally
7+
set +e
8+
TEST_ARG=$@
9+
DUMMY=$(bazel $TEST_ARG)
10+
RESPONSE_CODE=$?
11+
if [ $RESPONSE_CODE -eq 0 ]; then
12+
echo -e "${RED} \"bazel $TEST_ARG\" should have failed but passed. $NC"
13+
exit -1
14+
else
15+
exit 0
16+
fi
17+
}
18+
19+
test_expect_failure_with_message() {
20+
set +e
21+
22+
expected_message=$1
23+
test_filter=$2
24+
test_command=$3
25+
26+
command="bazel test --nocache_test_results --test_output=streamed ${test_filter} ${test_command}"
27+
output=$(${command} 2>&1)
28+
29+
echo ${output} | grep "$expected_message"
30+
if [ $? -ne 0 ]; then
31+
echo "'bazel test ${test_command}' should have logged \"${expected_message}\"."
32+
exit 1
33+
fi
34+
if [ "${additional_expected_message}" != "" ]; then
35+
echo ${output} | grep "$additional_expected_message"
36+
if [ $? -ne 0 ]; then
37+
echo "'bazel test ${test_command}' should have logged \"${additional_expected_message}\"."
38+
exit 1
39+
fi
40+
fi
41+
42+
set -e
43+
}
44+
45+
action_should_fail_with_message() {
46+
set +e
47+
MSG=$1
48+
TEST_ARG=${@:2}
49+
RES=$(bazel $TEST_ARG 2>&1)
50+
RESPONSE_CODE=$?
51+
echo $RES | grep -- "$MSG"
52+
GREP_RES=$?
53+
if [ $RESPONSE_CODE -eq 0 ]; then
54+
echo -e "${RED} \"bazel $TEST_ARG\" should have failed but passed. $NC"
55+
exit 1
56+
elif [ $GREP_RES -ne 0 ]; then
57+
echo -e "${RED} \"bazel $TEST_ARG\" should have failed with message \"$MSG\" but did not. $NC"
58+
else
59+
exit 0
60+
fi
61+
}
62+
63+
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message() {
64+
set +e
65+
66+
expected_message=$1
67+
test_target=$2
68+
strict_deps_mode=$3
69+
operator=${4:-"eq"}
70+
additional_expected_message=${5:-""}
71+
72+
if [ "${operator}" = "eq" ]; then
73+
error_message="bazel build of scala_library with missing direct deps should have failed."
74+
else
75+
error_message="bazel build of scala_library with missing direct deps should not have failed."
76+
fi
77+
78+
command="bazel build ${test_target} ${strict_deps_mode}"
79+
80+
output=$(${command} 2>&1)
81+
status_code=$?
82+
83+
echo "$output"
84+
if [ ${status_code} -${operator} 0 ]; then
85+
echo ${error_message}
86+
exit 1
87+
fi
88+
89+
echo ${output} | grep "$expected_message"
90+
if [ $? -ne 0 ]; then
91+
echo "'bazel build ${test_target}' should have logged \"${expected_message}\"."
92+
exit 1
93+
fi
94+
if [ "${additional_expected_message}" != "" ]; then
95+
echo ${output} | grep "$additional_expected_message"
96+
if [ $? -ne 0 ]; then
97+
echo "'bazel build ${test_target}' should have logged \"${additional_expected_message}\"."
98+
exit 1
99+
fi
100+
fi
101+
102+
set -e
103+
}
104+
105+
test_scala_library_expect_failure_on_missing_direct_deps() {
106+
dependenecy_target=$1
107+
test_target=$2
108+
109+
local expected_message="buildozer 'add deps $dependenecy_target' //$test_target"
110+
111+
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" $test_target "--strict_java_deps=error"
112+
}

test/shell/test_javac_jvm_flags.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# shellcheck source=./test_runner.sh
2+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
3+
. "${dir}"/test_runner.sh
4+
. "${dir}"/test_helper.sh
5+
runner=$(get_test_runner "${1:-local}")
6+
7+
javac_jvm_flags_are_configured(){
8+
action_should_fail build //test_expect_failure/compilers_jvm_flags:can_configure_jvm_flags_for_javac
9+
}
10+
11+
javac_jvm_flags_via_javacopts_are_configured(){
12+
action_should_fail build //test_expect_failure/compilers_jvm_flags:can_configure_jvm_flags_for_javac_via_javacopts
13+
}
14+
15+
javac_jvm_flags_are_expanded(){
16+
action_should_fail_with_message \
17+
"invalid flag: test_expect_failure/compilers_jvm_flags/args.txt" \
18+
build --verbose_failures //test_expect_failure/compilers_jvm_flags:can_expand_jvm_flags_for_javac
19+
}
20+
21+
javac_jvm_flags_via_javacopts_are_expanded(){
22+
action_should_fail_with_message \
23+
"invalid flag: test_expect_failure/compilers_jvm_flags/args.txt" \
24+
build --verbose_failures //test_expect_failure/compilers_jvm_flags:can_expand_jvm_flags_for_javac_via_javacopts
25+
}
26+
27+
$runner javac_jvm_flags_are_configured
28+
$runner javac_jvm_flags_via_javacopts_are_configured
29+
$runner javac_jvm_flags_are_expanded
30+
$runner javac_jvm_flags_via_javacopts_are_expanded

test/shell/test_junit.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# shellcheck source=./test_runner.sh
2+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
3+
. "${dir}"/test_runner.sh
4+
. "${dir}"/test_helper.sh
5+
runner=$(get_test_runner "${1:-local}")
6+
7+
multiple_junit_suffixes() {
8+
bazel test //test:JunitMultipleSuffixes
9+
10+
matches=$(grep -c -e 'Discovered classes' -e 'scalarules.test.junit.JunitSuffixIT' -e 'scalarules.test.junit.JunitSuffixE2E' ./bazel-testlogs/test/JunitMultipleSuffixes/test.log)
11+
if [ $matches -eq 3 ]; then
12+
return 0
13+
else
14+
return 1
15+
fi
16+
}
17+
18+
multiple_junit_prefixes() {
19+
bazel test //test:JunitMultiplePrefixes
20+
21+
matches=$(grep -c -e 'Discovered classes' -e 'scalarules.test.junit.TestJunitCustomPrefix' -e 'scalarules.test.junit.OtherCustomPrefixJunit' ./bazel-testlogs/test/JunitMultiplePrefixes/test.log)
22+
if [ $matches -eq 3 ]; then
23+
return 0
24+
else
25+
return 1
26+
fi
27+
}
28+
29+
multiple_junit_patterns() {
30+
bazel test //test:JunitPrefixesAndSuffixes
31+
matches=$(grep -c -e 'Discovered classes' -e 'scalarules.test.junit.TestJunitCustomPrefix' -e 'scalarules.test.junit.JunitSuffixE2E' ./bazel-testlogs/test/JunitPrefixesAndSuffixes/test.log)
32+
if [ $matches -eq 3 ]; then
33+
return 0
34+
else
35+
return 1
36+
fi
37+
}
38+
39+
test_scala_junit_test_can_fail() {
40+
action_should_fail test test_expect_failure/scala_junit_test:failing_test
41+
}
42+
43+
junit_generates_xml_logs() {
44+
bazel test //test:JunitTestWithDeps
45+
matches=$(grep -c -e "testcase name='hasCompileTimeDependencies'" -e "testcase name='hasRuntimeDependencies'" ./bazel-testlogs/test/JunitTestWithDeps/test.xml)
46+
if [ $matches -eq 2 ]; then
47+
return 0
48+
else
49+
return 1
50+
fi
51+
test -e
52+
}
53+
54+
test_junit_test_must_have_prefix_or_suffix() {
55+
action_should_fail test test_expect_failure/scala_junit_test:no_prefix_or_suffix
56+
}
57+
58+
test_junit_test_errors_when_no_tests_found() {
59+
action_should_fail test test_expect_failure/scala_junit_test:no_tests_found
60+
}
61+
62+
scala_junit_test_test_filter(){
63+
local output=$(bazel test \
64+
--nocache_test_results \
65+
--test_output=streamed \
66+
'--test_filter=scalarules.test.junit.FirstFilterTest#(method1|method2)$|scalarules.test.junit.SecondFilterTest#(method2|method3)$' \
67+
test:JunitFilterTest)
68+
local expected=(
69+
"scalarules.test.junit.FirstFilterTest#method1"
70+
"scalarules.test.junit.FirstFilterTest#method2"
71+
"scalarules.test.junit.SecondFilterTest#method2"
72+
"scalarules.test.junit.SecondFilterTest#method3")
73+
local unexpected=(
74+
"scalarules.test.junit.FirstFilterTest#method3"
75+
"scalarules.test.junit.SecondFilterTest#method1"
76+
"scalarules.test.junit.ThirdFilterTest#method1"
77+
"scalarules.test.junit.ThirdFilterTest#method2"
78+
"scalarules.test.junit.ThirdFilterTest#method3")
79+
for method in "${expected[@]}"; do
80+
if ! grep "$method" <<<$output; then
81+
echo "output:"
82+
echo "$output"
83+
echo "Expected $method in output, but was not found."
84+
exit 1
85+
fi
86+
done
87+
for method in "${unexpected[@]}"; do
88+
if grep "$method" <<<$output; then
89+
echo "output:"
90+
echo "$output"
91+
echo "Not expecting $method in output, but was found."
92+
exit 1
93+
fi
94+
done
95+
}
96+
97+
scala_junit_test_test_filter_custom_runner(){
98+
bazel test \
99+
--nocache_test_results \
100+
--test_output=streamed \
101+
'--test_filter=scalarules.test.junit.JunitCustomRunnerTest#' \
102+
test:JunitCustomRunner
103+
}
104+
105+
$runner multiple_junit_suffixes
106+
$runner multiple_junit_prefixes
107+
$runner multiple_junit_patterns
108+
$runner test_scala_junit_test_can_fail
109+
$runner junit_generates_xml_logs
110+
$runner test_junit_test_must_have_prefix_or_suffix
111+
$runner test_junit_test_errors_when_no_tests_found
112+
$runner scala_junit_test_test_filter
113+
$runner scala_junit_test_test_filter_custom_runner

0 commit comments

Comments
 (0)