22
33set -ex
44
5- : ${INTEGRATION?" The INTEGRATION environment variable must be set." }
5+ : " ${INTEGRATION?' The INTEGRATION environment variable must be set.' } "
66
77# FIXME: this means we can get a stale cargo-fmt from a previous run.
88#
@@ -42,8 +42,12 @@ function check_fmt_with_lib_tests {
4242
4343function check_fmt_base {
4444 local test_args=" $1 "
45- local build=$( cargo test $test_args 2>&1 )
46- if [[ " $build " =~ " build failed" ]] || [[ " $build " =~ " test result: FAILED." ]]; then
45+ local build
46+ # shellcheck is complaining that `$test_args` can be interpreted as multiple arguments
47+ # in case it contains whitespace characters... which is exactly what we want.
48+ # shellcheck disable=SC2086
49+ build=$( cargo test $test_args 2>&1 )
50+ if [[ " $build " =~ " build failed" ]] || [[ " $build " =~ test\ result\:\ FAILED\. ]]; then
4751 return 0
4852 fi
4953 touch rustfmt.toml
@@ -53,67 +57,64 @@ function check_fmt_base {
5357 return 1
5458 fi
5559 cat rustfmt_output
56- ! cat rustfmt_output | grep -q " internal error"
57- if [[ $? != 0 ]]; then
58- return 1
59- fi
60- ! cat rustfmt_output | grep -q " warning"
61- if [[ $? != 0 ]]; then
62- return 1
63- fi
64- ! cat rustfmt_output | grep -q " Warning"
65- if [[ $? != 0 ]]; then
66- return 1
67- fi
60+ grep -q " internal error" < rustfmt_output && return 1
61+ grep -q " warning" < rustfmt_output && return 1
62+ grep -q " Warning" < rustfmt_output && return 1
63+
6864 cargo fmt --all -- --check | & tee rustfmt_check_output
6965 if [[ ${PIPESTATUS[0]} != 0 ]]; then
7066 cat rustfmt_check_output
7167 return 1
7268 fi
69+ # shellcheck is complaining that `$test_args` can be interpreted as multiple arguments
70+ # in case it contains whitespace characters... which is exactly what we want.
71+ # shellcheck disable=SC2086
7372 cargo test $test_args
74- if [[ $? != 0 ]]; then
75- return $?
73+ cargo_ret=$?
74+ if [[ $cargo_ret != 0 ]]; then
75+ return $cargo_ret
7676 fi
7777}
7878
7979function show_head {
80- local head=$( git rev-parse HEAD)
80+ local head
81+ head=$( git rev-parse HEAD)
8182 echo " Head commit of ${INTEGRATION} : $head "
8283}
8384
8485case ${INTEGRATION} in
8586 cargo)
86- git clone --depth=1 https://github.com/rust-lang/${INTEGRATION} .git
87- cd ${INTEGRATION}
87+ git clone --depth=1 " https://github.com/rust-lang/${INTEGRATION} .git"
88+ cd " ${INTEGRATION} "
8889 show_head
8990 export CFG_DISABLE_CROSS_TESTS=1
9091 check_fmt_with_all_tests
9192 cd -
9293 ;;
9394 crater)
94- git clone --depth=1 https://github.com/rust-lang/${INTEGRATION} .git
95- cd ${INTEGRATION}
95+ git clone --depth=1 " https://github.com/rust-lang/${INTEGRATION} .git"
96+ cd " ${INTEGRATION} "
9697 show_head
9798 check_fmt_with_lib_tests
9899 cd -
99100 ;;
100101 bitflags)
101- git clone --depth=1 https://github.com/bitflags/${INTEGRATION} .git
102- cd ${INTEGRATION}
102+ git clone --depth=1 " https://github.com/bitflags/${INTEGRATION} .git"
103+ cd " ${INTEGRATION} "
103104 show_head
104105 check_fmt_with_all_tests
105106 cd -
106107 ;;
107108 tempdir)
108- git clone --depth=1 https://github.com/rust-lang-deprecated/${INTEGRATION} .git
109- cd ${INTEGRATION}
109+ git clone --depth=1 " https://github.com/rust-lang-deprecated/${INTEGRATION} .git"
110+ cd " ${INTEGRATION} "
110111 show_head
111112 check_fmt_with_all_tests
112113 cd -
113114 ;;
114115 * )
115- git clone --depth=1 https://github.com/rust-lang/${INTEGRATION} .git
116- cd ${INTEGRATION}
116+ git clone --depth=1 " https://github.com/rust-lang/${INTEGRATION} .git"
117+ cd " ${INTEGRATION} "
117118 show_head
118119 check_fmt_with_all_tests
119120 cd -
0 commit comments