]> git.lizzy.rs Git - rust.git/blob - ci/integration.sh
Merge pull request #2795 from jechase/issue-2794
[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 fmt --all -- --check` after formatting returns success
27 # * `cargo test -all` still passes (formatting did not break the build)
28 function check_fmt {
29     cargo test --all
30     if [[ $? != 0 ]]; then
31           return 0
32     fi
33     touch rustfmt.toml
34     cargo fmt --all -v |& tee rustfmt_output
35     if [[ ${PIPESTATUS[0]} != 0 ]]; then
36         cat rustfmt_output
37         return 1
38     fi
39     cat rustfmt_output
40     ! cat rustfmt_output | grep -q "internal error"
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     ! cat rustfmt_output | grep -q "Warning"
49     if [[ $? != 0 ]]; then
50         return 1
51     fi
52     cargo fmt --all -- --check |& tee rustfmt_check_output
53     if [[ ${PIPESTATUS[0]} != 0 ]]; then
54         cat rustfmt_check_output
55         return 1
56     fi
57     cargo test --all
58     if [[ $? != 0 ]]; then
59         return $?
60     fi
61 }
62
63 case ${INTEGRATION} in
64     cargo)
65         git clone --depth=1 https://github.com/rust-lang/${INTEGRATION}.git
66         cd ${INTEGRATION}
67         export CFG_DISABLE_CROSS_TESTS=1
68         check_fmt
69         cd -
70         ;;
71     failure)
72         git clone --depth=1 https://github.com/rust-lang-nursery/${INTEGRATION}.git
73         cd ${INTEGRATION}/failure-1.X
74         check_fmt
75         cd -
76         ;;
77     *)
78         git clone --depth=1 https://github.com/rust-lang-nursery/${INTEGRATION}.git
79         cd ${INTEGRATION}
80         check_fmt
81         cd -
82         ;;
83 esac