Bail if `cargo clippy` or `cargo fmt` fails (#65)

* Bail out if 'cargo fmt' fails

* Bail out if 'cargo clippy' fails

* Move install_rustfmt_clippy.sh from before script to install

* Use loose pattern for nightly toolchain

The name of the nightly toolchain on Travis server is `nightly
(default)` instead of `night-*`.
This commit is contained in:
Chun-Min Chang 2020-03-25 15:38:33 -07:00 коммит произвёл GitHub
Родитель 3860bb3f95
Коммит ab319780de
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 29 добавлений и 6 удалений

Просмотреть файл

@ -7,10 +7,11 @@ os:
- osx
env:
- RUST_BACKTRACE=1
install:
- sh install_rustfmt_clippy.sh
before_script:
- rustc --version
- cargo --version
- sh install_rustfmt_clippy.sh
script:
- cargo build --verbose
- sh run_tests.sh

Просмотреть файл

@ -6,7 +6,7 @@
toolchain=$(rustup default)
echo "\nUse Rust toolchain: $toolchain"
if [[ $toolchain != nightly-* ]]; then
if [[ $toolchain != nightly* ]]; then
echo "The sanitizer is only available on Rust Nightly only. Skip."
exit
fi

Просмотреть файл

@ -6,6 +6,28 @@ if [[ -z "${RUST_BACKTRACE}" ]]; then
fi
echo "RUST_BACKTRACE is set to ${RUST_BACKTRACE}\n"
format_check() {
cargo fmt --all -- --check
local result=$?
if [[ $result -ne 0 ]]; then
echo "Please format the code with 'cargo fmt' (version $(cargo fmt -- --version))"
fi
return $result
}
lints_check() {
if [[ -n "$1" ]]; then
cargo clippy -p $1 -- -D warnings
else
cargo clippy -- -D warnings
fi
local result=$?
if [[ $result -ne 0 ]]; then
echo "Please fix errors with 'cargo clippy' (version $(cargo clippy -- --version))"
fi
return $result
}
# Run tests in the sub crate
# Run the tests by `cargo * -p <SUB_CRATE>` if it's possible. By doing so, the duplicate compiling
# between this crate and the <SUB_CRATE> can be saved. The compiling for <SUB_CRATE> can be reused
@ -17,11 +39,11 @@ SUB_CRATE="coreaudio-sys-utils"
# `cargo fmt -p *` is only usable in workspaces, so a workaround is to enter to the sub crate
# and then exit from it.
cd $SUB_CRATE
cargo fmt --all -- --check
format_check || exit $?
cd ..
# Lints check
cargo clippy -p $SUB_CRATE -- -D warnings
(lints_check $SUB_CRATE) || exit $?
# Regular Tests
cargo test -p $SUB_CRATE
@ -29,10 +51,10 @@ cargo test -p $SUB_CRATE
# Run tests in the main crate
# -------------------------------------------------------------------------------------------------
# Format check
cargo fmt --all -- --check
format_check || exit $?
# Lints check
cargo clippy -- -D warnings
lints_check || exit $?
# Regular Tests
cargo test --verbose