]> git.lizzy.rs Git - rust.git/blob - src/tools/rustfmt/ci/integration.sh
Rollup merge of #97249 - GuillaumeGomez:details-summary-fixes, r=notriddle
[rust.git] / src / tools / rustfmt / 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 CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force --locked
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_with_all_tests {
29     check_fmt_base "--all"
30     return $?
31 }
32
33 # Checks that:
34 #
35 # * `cargo fmt --all` succeeds without any warnings or errors
36 # * `cargo fmt --all -- --check` after formatting returns success
37 # * `cargo test --lib` still passes (formatting did not break the build)
38 function check_fmt_with_lib_tests {
39     check_fmt_base "--lib"
40     return $?
41 }
42
43 function check_fmt_base {
44     local test_args="$1"
45     local build=$(cargo test $test_args 2>&1)
46     if [[ "$build" =~ "build failed" ]] || [[ "$build" =~ "test result: FAILED." ]]; then
47           return 0
48     fi
49     touch rustfmt.toml
50     cargo fmt --all -v |& tee rustfmt_output
51     if [[ ${PIPESTATUS[0]} != 0 ]]; then
52         cat rustfmt_output
53         return 1
54     fi
55     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
68     cargo fmt --all -- --check |& tee rustfmt_check_output
69     if [[ ${PIPESTATUS[0]} != 0 ]]; then
70         cat rustfmt_check_output
71         return 1
72     fi
73     cargo test $test_args
74     if [[ $? != 0 ]]; then
75         return $?
76     fi
77 }
78
79 function show_head {
80     local head=$(git rev-parse HEAD)
81     echo "Head commit of ${INTEGRATION}: $head"
82 }
83
84 case ${INTEGRATION} in
85     cargo)
86         git clone --depth=1 https://github.com/rust-lang/${INTEGRATION}.git
87         cd ${INTEGRATION}
88         show_head
89         export CFG_DISABLE_CROSS_TESTS=1
90         check_fmt_with_all_tests
91         cd -
92         ;;
93     crater)
94         git clone --depth=1 https://github.com/rust-lang-nursery/${INTEGRATION}.git
95         cd ${INTEGRATION}
96         show_head
97         check_fmt_with_lib_tests
98         cd -
99         ;;
100     *)
101         git clone --depth=1 https://github.com/rust-lang-nursery/${INTEGRATION}.git
102         cd ${INTEGRATION}
103         show_head
104         check_fmt_with_all_tests
105         cd -
106         ;;
107 esac