* Download the latest available nightly for running cargo clippy and fmt

* Make local test easier

Using the a test script to run tests both remotely and locally is an
easier way to make sure the local test results meet the same test
requirements on the Travis CI server.

* Run tests with sanitizers
This commit is contained in:
Chun-Min Chang 2020-03-02 09:56:31 -08:00 коммит произвёл GitHub
Родитель 51d8d48009
Коммит 98cd68a602
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 74 добавлений и 5 удалений

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

@ -12,13 +12,11 @@ env:
before_script: before_script:
- rustc --version - rustc --version
- cargo --version - cargo --version
- rustup component add rustfmt - sh install_rustfmt_clippy.sh
- rustup component add clippy
script: script:
- cargo fmt --all -- --check
- cargo clippy --all-targets --all-features -- -D warnings
- cargo build --verbose --all - cargo build --verbose --all
- cargo test --verbose --all - sh run_tests.sh
- sh run_sanitizers.sh
jobs: jobs:
allow_failures: allow_failures:
- rust: nightly - rust: nightly

17
install_rustfmt_clippy.sh Normal file
Просмотреть файл

@ -0,0 +1,17 @@
# https://github.com/rust-lang/rustup-components-history/blob/master/README.md
# https://github.com/rust-lang/rust-clippy/blob/27acea0a1baac6cf3ac6debfdbce04f91e15d772/.travis.yml#L40-L46
if ! rustup component add rustfmt; then
TARGET=$(rustc -Vv | awk '/host/{print $2}')
NIGHTLY=$(curl -s "https://rust-lang.github.io/rustup-components-history/${TARGET}/rustfmt")
curl -sSL "https://static.rust-lang.org/dist/${NIGHTLY}/rustfmt-nightly-${TARGET}.tar.xz" | \
tar -xJf - --strip-components=3 -C ~/.cargo/bin
rm -rf ~/.cargo/bin/doc
fi
if ! rustup component add clippy; then
TARGET=$(rustc -Vv | awk '/host/{print $2}')
NIGHTLY=$(curl -s "https://rust-lang.github.io/rustup-components-history/${TARGET}/clippy")
rustup default nightly-${NIGHTLY}
rustup component add rustfmt
rustup component add clippy
fi

40
run_sanitizers.sh Normal file
Просмотреть файл

@ -0,0 +1,40 @@
# The option `Z` is only accepted on the nightly compiler
# so changing to nightly toolchain by `rustup default nightly` is required.
# See: https://github.com/rust-lang/rust/issues/39699 for more sanitizer support.
toolchain=$(rustup default)
echo "\nUse Rust toolchain: $toolchain"
NIGHTLY_PREFIX="nightly-"
if [ ! -z "${toolchain##$NIGHTLY_PREFIX*}" ]; then
echo "The sanitizer is only available on Rust Nightly only. Skip."
exit
fi
# Display verbose backtrace for debugging if backtrace is unset
if [ -z "${RUST_BACKTRACE}" ]; then
export RUST_BACKTRACE=1
fi
echo "RUST_BACKTRACE is set to ${RUST_BACKTRACE}\n"
# {Address, Thread}Sanitizer cannot build with `criterion` crate, so `criterion` will be removed
# from the `Cargo.toml` temporarily during the sanitizer tests.
ORIGINAL_MANIFEST="Cargo_ori.toml"
mv Cargo.toml $ORIGINAL_MANIFEST
# Delete lines that contain a `criterion` from Cargo.toml.
sed '/criterion/d' $ORIGINAL_MANIFEST > Cargo.toml
sanitizers=("address" "leak" "memory" "thread")
for san in "${sanitizers[@]}"
do
San="$(tr '[:lower:]' '[:upper:]' <<< ${san:0:1})${san:1}"
echo "\n\nRun ${San}Sanitizer\n------------------------------"
if [ $san = "leak" ]; then
echo "Skip the test that panics. Leaking memory when the program drops out abnormally is ok."
options="-- --Z unstable-options --exclude-should-panic"
fi
RUSTFLAGS="-Z sanitizer=${san}" cargo test $options
done
mv $ORIGINAL_MANIFEST Cargo.toml

14
run_tests.sh Normal file
Просмотреть файл

@ -0,0 +1,14 @@
# Display verbose backtrace for debugging if backtrace is unset
if [ -z "${RUST_BACKTRACE}" ]; then
export RUST_BACKTRACE=1
fi
echo "RUST_BACKTRACE is set to ${RUST_BACKTRACE}\n"
# Format check
cargo fmt --all -- --check
# Lints check
cargo clippy --all-targets --all-features -- -D warnings
# Regular Tests
cargo test --verbose --all