base tests: make sure to fail CI if tests need formatting

This commit is contained in:
Matthias Krüger 2018-12-27 12:40:07 +01:00
parent bcc309f27d
commit 84ee884cc4

View File

@ -36,22 +36,31 @@ cd ..
cargo +nightly fmt --all -- --check cargo +nightly fmt --all -- --check
#avoid loop spam
set +x
# make sure tests are formatted # make sure tests are formatted
# some lints are sensitive to formatting, exclude some files # some lints are sensitive to formatting, exclude some files
needs_formatting=false tests_need_reformatting=false
# switch to nightly # switch to nightly
rustup default nightly rustup default nightly
for file in `find tests -not -path "tests/ui/methods.rs" -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do # avoid loop spam and allow cmds with exit status != 0
rustfmt ${file} --check || echo "${file} needs reformatting!" ; needs_formatting=true set +ex
done
# switch back to master
rustup default master
if [ "${needs_reformatting}" = true ] ; then for file in `find tests -not -path "tests/ui/methods.rs" -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
rustfmt ${file} --check
if [ $? -ne 0 ]; then
echo "${file} needs reformatting!"
tests_need_reformatting=true
fi
done
set -ex # reset
if [ ${tests_need_reformatting} ] ; then
echo "Tests need reformatting!" echo "Tests need reformatting!"
exit 2 exit 2
fi fi
set -x
# switch back to master
rustup default master