Skip to content

Commit 917411d

Browse files
committed
Extend the Travis build matrix to allow IntelliJ aspect to run under the timeout
- Split the test_runner into its own file. - Run the IntelliJ aspect in separate rows in the build matrix.
1 parent 048c032 commit 917411d

File tree

6 files changed

+135
-100
lines changed

6 files changed

+135
-100
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ env:
1414
# we want to test the most recent few releases
1515
- V=0.7.0
1616
- V=0.8.1
17+
- TEST_SCRIPT=test_rules_scala.sh
18+
- TEST_SCRIPT=test_intellij_aspect.sh
1719

1820
before_install:
1921
- |
@@ -40,5 +42,5 @@ before_install:
4042
- git clone --depth 1 https://github.com/bazelbuild/intellij.git
4143

4244
script:
43-
- bash test_run.sh ci
45+
- bash $TEST_SCRIPT ci
4446

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ Note: Currently strict-deps is protected by a feature toggle but we're strongly
570570
## Building from source
571571
Test & Build:
572572
```
573-
bash test_run.sh
573+
bash test_all.sh
574574
```
575575
This doesn't currently pass on OS X (see #136 for details) and so you can also use:
576576

test_all.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
6+
"${dir}"/test_rules_scala.sh
7+
"${dir}"/test_intellij_aspect.sh

test_intellij_aspect.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
#
3+
# Test the IntelliJ aspect. Override intellij's rules_scala with this one for an
4+
# integration test. See https://github.com/bazelbuild/rules_scala/issues/308.
5+
6+
set -euo pipefail
7+
8+
test_intellij_aspect() {
9+
local test_env=$1
10+
local intellij_git_tag=$2
11+
local -r rules_scala_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
12+
13+
if [[ "${test_env}" == "ci" ]]; then
14+
# ci: intellij is checked out in `.travis.yaml`
15+
cd intellij || exit 1
16+
else
17+
# local: update or checkout a sibling dir.
18+
cd "${rules_scala_dir}/../" || exit 1
19+
test -d "intellij/.git" || git clone [email protected]:bazelbuild/intellij.git
20+
cd intellij && git fetch && git pull
21+
fi
22+
git checkout "${intellij_git_tag}"
23+
bazel test --test_output=errors --override_repository io_bazel_rules_scala="${rules_scala_dir}" //aspect/testing/tests/src/com/google/idea/blaze/aspect/scala/...
24+
}
25+
26+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
27+
test_env="${1:-local}"
28+
29+
# shellcheck source=./test_runner.sh
30+
. "${dir}"/test_runner.sh
31+
runner=$(get_test_runner "$test_env")
32+
33+
$runner test_intellij_aspect "$test_env" master

test_run.sh renamed to test_rules_scala.sh

Lines changed: 5 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -237,79 +237,7 @@ test_multi_service_manifest() {
237237
exit $RESPONSE_CODE
238238
}
239239

240-
NC='\033[0m'
241-
GREEN='\033[0;32m'
242-
RED='\033[0;31m'
243-
TIMOUT=60
244-
245-
run_test_ci() {
246-
# spawns the test to new process
247-
local TEST_ARG=$@
248-
local log_file=output_$$.log
249-
echo "running test $TEST_ARG"
250-
$TEST_ARG &>$log_file &
251-
local test_pid=$!
252-
SECONDS=0
253-
test_pulse_printer $! $TIMOUT $TEST_ARG &
254-
local pulse_printer_pid=$!
255-
local result
256-
257-
{
258-
wait $test_pid 2>/dev/null
259-
result=$?
260-
kill $pulse_printer_pid && wait $pulse_printer_pid 2>/dev/null || true
261-
} || return 1
262-
263-
DURATION=$SECONDS
264-
if [ $result -eq 0 ]; then
265-
echo -e "\n${GREEN}Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
266-
else
267-
echo -e "\nLog:\n"
268-
cat $log_file
269-
echo -e "\n${RED}Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
270-
fi
271-
return $result
272-
}
273-
274-
test_pulse_printer() {
275-
# makes sure something is printed to stdout while test is running
276-
local test_pid=$1
277-
shift
278-
local timeout=$1 # in minutes
279-
shift
280-
local count=0
281240

282-
# clear the line
283-
echo -e "\n"
284-
285-
while [ $count -lt $timeout ]; do
286-
count=$(($count + 1))
287-
echo -ne "Still running: \"$@\"\r"
288-
sleep 60
289-
done
290-
291-
echo -e "\n${RED}Timeout (${timeout} minutes) reached. Terminating \"$@\"${NC}\n"
292-
kill -9 $test_pid
293-
}
294-
295-
run_test_local() {
296-
# runs the tests locally
297-
set +e
298-
SECONDS=0
299-
TEST_ARG=$@
300-
echo "running test $TEST_ARG"
301-
RES=$($TEST_ARG 2>&1)
302-
RESPONSE_CODE=$?
303-
DURATION=$SECONDS
304-
if [ $RESPONSE_CODE -eq 0 ]; then
305-
echo -e "${GREEN} Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
306-
else
307-
echo -e "\nLog:\n"
308-
echo "$RES"
309-
echo -e "${RED} Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
310-
exit $RESPONSE_CODE
311-
fi
312-
}
313241

314242
action_should_fail() {
315243
# runs the tests locally
@@ -728,31 +656,6 @@ revert_change() {
728656
mv $1/$2.bak $1/$2
729657
}
730658

731-
test_intellij_aspect() {
732-
local test_env=$1
733-
local intellij_git_tag=$2
734-
local rules_scala_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
735-
736-
if [[ "${test_env}" == "ci" ]]; then
737-
# ci: intellij is checked out in `.travis.yaml`
738-
cd intellij
739-
else
740-
# local: update or checkout a sibling dir.
741-
cd "${rules_scala_dir}/../"
742-
test -d "intellij/.git" || git clone [email protected]:bazelbuild/intellij.git
743-
cd intellij && git fetch && git pull
744-
fi
745-
git checkout "${intellij_git_tag}"
746-
bazel test --test_output=errors --override_repository io_bazel_rules_scala="${rules_scala_dir}" //aspect/testing/tests/src/com/google/idea/blaze/aspect/scala/...
747-
}
748-
749-
test_env="${1:-local}"
750-
if [[ "${test_env}" != "ci" && "${test_env}" != "local" ]]; then
751-
echo -e "${RED}test_env must be either 'local' or 'ci'"
752-
exit 1
753-
fi
754-
runner="run_test_${test_env}"
755-
756659
test_scala_import_expect_failure_on_missing_direct_deps_warn_mode() {
757660
dependency_target1='//test_expect_failure/scala_import:cats'
758661
dependency_target2='//test_expect_failure/scala_import:guava'
@@ -764,6 +667,11 @@ test_scala_import_expect_failure_on_missing_direct_deps_warn_mode() {
764667
test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message1}" ${test_target} "--strict_java_deps=warn" "ne" "${expected_message2}"
765668
}
766669

670+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
671+
# shellcheck source=./test_runner.sh
672+
. "${dir}"/test_runner.sh
673+
runner=$(get_test_runner "${1:-local}")
674+
767675
$runner bazel build test/...
768676
$runner bazel test test/...
769677
$runner bazel test third_party/...
@@ -827,4 +735,3 @@ $runner test_scala_library_expect_failure_on_missing_direct_deps_warn_mode_java
827735
$runner test_scala_library_expect_better_failure_message_on_missing_transitive_dependency_labels_from_other_jvm_rules
828736
$runner test_scala_import_expect_failure_on_missing_direct_deps_warn_mode
829737
$runner bazel build "test_expect_failure/missing_direct_deps/internal_deps/... --strict_java_deps=warn"
830-
$runner test_intellij_aspect "${test_env}" master # TODO(https://github.com/bazelbuild/intellij/issues/146): add test of release tag when fixed.

test_runner.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
#
3+
# Test runner functions for rules_scala integration tests.
4+
5+
NC='\033[0m'
6+
GREEN='\033[0;32m'
7+
RED='\033[0;31m'
8+
TIMOUT=60
9+
10+
run_test_ci() {
11+
# spawns the test to new process
12+
local TEST_ARG=$@
13+
local log_file=output_$$.log
14+
echo "running test $TEST_ARG"
15+
$TEST_ARG &>$log_file &
16+
local test_pid=$!
17+
SECONDS=0
18+
test_pulse_printer $! $TIMOUT $TEST_ARG &
19+
local pulse_printer_pid=$!
20+
local result
21+
22+
{
23+
wait $test_pid 2>/dev/null
24+
result=$?
25+
kill $pulse_printer_pid && wait $pulse_printer_pid 2>/dev/null || true
26+
} || return 1
27+
28+
DURATION=$SECONDS
29+
if [ $result -eq 0 ]; then
30+
echo -e "\n${GREEN}Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
31+
else
32+
echo -e "\nLog:\n"
33+
cat $log_file
34+
echo -e "\n${RED}Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
35+
fi
36+
return $result
37+
}
38+
39+
test_pulse_printer() {
40+
# makes sure something is printed to stdout while test is running
41+
local test_pid=$1
42+
shift
43+
local timeout=$1 # in minutes
44+
shift
45+
local count=0
46+
47+
# clear the line
48+
echo -e "\n"
49+
50+
while [ $count -lt $timeout ]; do
51+
count=$(($count + 1))
52+
echo -ne "Still running: \"$@\"\r"
53+
sleep 60
54+
done
55+
56+
echo -e "\n${RED}Timeout (${timeout} minutes) reached. Terminating \"$@\"${NC}\n"
57+
kill -9 $test_pid
58+
}
59+
60+
run_test_local() {
61+
# runs the tests locally
62+
set +e
63+
SECONDS=0
64+
TEST_ARG=$@
65+
echo "running test $TEST_ARG"
66+
RES=$($TEST_ARG 2>&1)
67+
RESPONSE_CODE=$?
68+
DURATION=$SECONDS
69+
if [ $RESPONSE_CODE -eq 0 ]; then
70+
echo -e "${GREEN} Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
71+
else
72+
echo -e "\nLog:\n"
73+
echo "$RES"
74+
echo -e "${RED} Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
75+
exit $RESPONSE_CODE
76+
fi
77+
}
78+
79+
get_test_runner() {
80+
test_env=$1
81+
if [[ "${test_env}" != "ci" && "${test_env}" != "local" ]]; then
82+
echo -e "${RED}test_env must be either 'local' or 'ci'"
83+
exit 1
84+
fi
85+
echo "run_test_${test_env}"
86+
}

0 commit comments

Comments
 (0)