]> git.lizzy.rs Git - rust.git/blob - ci/integration.sh
test cargo fmt --all -- --check returns success after formatting
[rust.git] / ci / integration.sh
1 #!/usr/bin/env bash
2
3 set -ex
4
5 : ${INTEGRATION?"The INTEGRATION environment variable must be set."}
6
7 # FIXME: this means we can get a stale cargo-fmt from a previous run.
8 #
9 # `which rustfmt` fails if rustfmt is not found. Since we don't install
10 # `rustfmt` via `rustup`, this is the case unless we manually install it. Once
11 # that happens, `cargo install --force` will be called, which installs
12 # `rustfmt`, `cargo-fmt`, etc to `~/.cargo/bin`. This directory is cached by
13 # travis (see `.travis.yml`'s "cache" key), such that build-bots that arrive
14 # here after the first installation will find `rustfmt` and won't need to build
15 # it again.
16 #
17 #which cargo-fmt || cargo install --force
18 cargo install --force
19
20 echo "Integration tests for: ${INTEGRATION}"
21 cargo fmt -- --version
22
23 # Checks that:
24 #
25 # * `cargo fmt --all` succeeds without any warnings or errors
26 # * `cargo test -all` still passes (formatting did not break the build)
27 # * `cargo fmt --all -- --check` after formatting returns success
28 function check_fmt {
29     touch rustfmt.toml
30     cargo fmt --all -v 2>&1 | tee rustfmt_output
31     if [[ $? != 0 ]]; then
32         cat rustfmt_output
33         return 1
34     fi
35     cat rustfmt_output
36     ! cat rustfmt_output | grep -q "internal error"
37     if [[ $? != 0 ]]; then
38         return 1
39     fi
40     ! cat rustfmt_output | grep -q "warning"
41     if [[ $? != 0 ]]; then
42         return 1
43     fi
44     ! cat rustfmt_output | grep -q "Warning"
45     if [[ $? != 0 ]]; then
46         return 1
47     fi
48     cargo test --all
49     if [[ $? != 0 ]]; then
50         return $?
51     fi
52
53     cargo fmt --all -- --check 2>&1 | tee rustfmt_check_output
54     if [[ $? != 0 ]]; then
55         cat rustfmt_check_output
56         return 1
57     fi
58 }
59
60 case ${INTEGRATION} in
61     cargo)
62         git clone --depth=1 https://github.com/rust-lang/${INTEGRATION}.git
63         cd ${INTEGRATION}
64         export CFG_DISABLE_CROSS_TESTS=1
65         check_fmt
66         cd -
67         ;;
68     failure)
69         git clone --depth=1 https://github.com/rust-lang-nursery/${INTEGRATION}.git
70         cd ${INTEGRATION}/failure-1.X
71         check_fmt
72         cd -
73         ;;
74     *)
75         git clone --depth=1 https://github.com/rust-lang-nursery/${INTEGRATION}.git
76         cd ${INTEGRATION}
77         check_fmt
78         cd -
79         ;;
80 esac