mirror of
https://github.com/kmc7468/cs220.git
synced 2025-12-14 22:18:46 +00:00
grader updates from CS431 (#11)
* If any of linters fail, don't run the tests. * If build fails, echo the error message to stderr. * Fix sanitizer options. * Don't use colored output (it messes up gg log). * $@ → "$@" * $@ → $* in string
This commit is contained in:
committed by
Seungmin Jeon
parent
e91413b506
commit
7913e6774e
@@ -18,8 +18,7 @@ RUNNERS=(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Lints.
|
# Lints.
|
||||||
cargo fmt --check
|
run_linters || exit 1
|
||||||
cargo clippy
|
|
||||||
|
|
||||||
# Executes test for each runner.
|
# Executes test for each runner.
|
||||||
for RUNNER in "${RUNNERS[@]}"; do
|
for RUNNER in "${RUNNERS[@]}"; do
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ RUNNERS=(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Lints.
|
# Lints.
|
||||||
cargo fmt --check
|
run_linters || exit 1
|
||||||
cargo clippy
|
|
||||||
|
|
||||||
# Executes test for each runner.
|
# Executes test for each runner.
|
||||||
for RUNNER in "${RUNNERS[@]}"; do
|
for RUNNER in "${RUNNERS[@]}"; do
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ RUNNERS=(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Lints.
|
# Lints.
|
||||||
cargo fmt --check
|
run_linters || exit 1
|
||||||
cargo clippy
|
|
||||||
|
|
||||||
# Executes test for each runner.
|
# Executes test for each runner.
|
||||||
for RUNNER in "${RUNNERS[@]}"; do
|
for RUNNER in "${RUNNERS[@]}"; do
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ RUNNERS=(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Lints.
|
# Lints.
|
||||||
cargo fmt --check
|
run_linters || exit 1
|
||||||
cargo clippy
|
|
||||||
|
|
||||||
# Executes test for each runner.
|
# Executes test for each runner.
|
||||||
for RUNNER in "${RUNNERS[@]}"; do
|
for RUNNER in "${RUNNERS[@]}"; do
|
||||||
|
|||||||
@@ -10,12 +10,12 @@
|
|||||||
rustup toolchain update stable nightly
|
rustup toolchain update stable nightly
|
||||||
|
|
||||||
echo_err() {
|
echo_err() {
|
||||||
echo -e "\033[0;31m\033[1m$@\033[0m" 1>&2
|
echo "$@" 1>&2
|
||||||
}
|
}
|
||||||
export -f echo_err
|
export -f echo_err
|
||||||
|
|
||||||
# check_diff FILE TEST_LINES_FROM_TAIL
|
# check_diff FILE TEST_LINES_FROM_TAIL
|
||||||
# Abort if tests are modified.
|
# Abort if "--lib" tests are modified.
|
||||||
# Uses global variable TEMPLATE_REV.
|
# Uses global variable TEMPLATE_REV.
|
||||||
check_diff() {
|
check_diff() {
|
||||||
local FILE=$1
|
local FILE=$1
|
||||||
@@ -25,13 +25,26 @@ check_diff() {
|
|||||||
}
|
}
|
||||||
export -f check_diff
|
export -f check_diff
|
||||||
|
|
||||||
|
# Returns non-zero exit code if any of the linters have failed.
|
||||||
|
run_linters() {
|
||||||
|
cargo fmt -- --check
|
||||||
|
local FMT_ERR=$?
|
||||||
|
cargo clippy -- -D warnings
|
||||||
|
local CLIPPY_ERR=$?
|
||||||
|
[ "$FMT_ERR" -ne 0 ] && echo_err 'Please format your code with `cargo fmt` first.'
|
||||||
|
[ "$CLIPPY_ERR" -ne 0 ] && echo_err 'Please fix the issues from `cargo clippy` first.'
|
||||||
|
return $(( FMT_ERR || CLIPPY_ERR ))
|
||||||
|
}
|
||||||
|
export -f run_linters
|
||||||
|
|
||||||
# usage: cargo_asan [SUBCOMMAND] [OPTIONS] [-- <args>...]
|
# usage: cargo_asan [SUBCOMMAND] [OPTIONS] [-- <args>...]
|
||||||
# example: cargo_asan test --release TEST_NAME -- --skip SKIPPED
|
# example: cargo_asan test --release TEST_NAME -- --skip SKIPPED
|
||||||
|
# NOTE: sanitizer documentation at https://doc.rust-lang.org/beta/unstable-book/compiler-flags/sanitizer.html
|
||||||
cargo_asan() {
|
cargo_asan() {
|
||||||
local SUBCOMMAND=$1; shift
|
local SUBCOMMAND=$1; shift
|
||||||
RUSTFLAGS="-Z sanitizer=address" \
|
RUSTFLAGS="-Z sanitizer=address" \
|
||||||
RUSTDOCFLAGS="-Z sanitizer=address" \
|
RUSTDOCFLAGS="-Z sanitizer=address" \
|
||||||
cargo +nightly $SUBCOMMAND --target x86_64-unknown-linux-gnu $@
|
cargo +nightly $SUBCOMMAND -Z build-std --target x86_64-unknown-linux-gnu "$@"
|
||||||
}
|
}
|
||||||
export -f cargo_asan
|
export -f cargo_asan
|
||||||
|
|
||||||
@@ -41,24 +54,32 @@ cargo_tsan() {
|
|||||||
TSAN_OPTIONS="suppressions=suppress_tsan.txt" \
|
TSAN_OPTIONS="suppressions=suppress_tsan.txt" \
|
||||||
RUSTDOCFLAGS="-Z sanitizer=thread" \
|
RUSTDOCFLAGS="-Z sanitizer=thread" \
|
||||||
RUST_TEST_THREADS=1 \
|
RUST_TEST_THREADS=1 \
|
||||||
cargo +nightly $SUBCOMMAND --target x86_64-unknown-linux-gnu $@
|
cargo +nightly $SUBCOMMAND -Z build-std --target x86_64-unknown-linux-gnu "$@"
|
||||||
}
|
}
|
||||||
export -f cargo_tsan
|
export -f cargo_tsan
|
||||||
|
|
||||||
# usage: _run_tests_with CARGO [OPTIONS]
|
# usage: _run_tests_with CARGO [OPTIONS]
|
||||||
# example: _run_tests_with cargo_tsan --release
|
# example: _run_tests_with cargo_tsan --release
|
||||||
# echos number of failed tests
|
# Echos number of failed tests to stdout.
|
||||||
# Uses global variable TESTS, TIMEOUT
|
# Echos error message to stderr.
|
||||||
# [OPTIONS] must not contain " -- " (cargo options only)
|
# Uses global variables TESTS, TIMEOUT.
|
||||||
|
# [OPTIONS] must not contain " -- " (cargo options only).
|
||||||
_run_tests_with() {
|
_run_tests_with() {
|
||||||
local CARGO=$1; shift
|
local CARGO=$1; shift
|
||||||
$CARGO test --no-run $@ &>/dev/null \
|
local MSGS # https://mywiki.wooledge.org/BashPitfalls#local_var.3D.24.28cmd.29
|
||||||
|| (echo_err "Build failed!"; exit 1)
|
MSGS=$($CARGO test --no-run "$@" 2>&1)
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo_err "Build failed! Error message:"
|
||||||
|
echo_err "${MSGS}"
|
||||||
|
echo_err "--------------------------------------------------------------------------------"
|
||||||
|
echo ${#TESTS[@]} # failed all tests
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
local FAILED=0
|
local FAILED=0
|
||||||
for TEST in "${TESTS[@]}"; do
|
for TEST in "${TESTS[@]}"; do
|
||||||
local TEST_CMD="$CARGO test $@ $TEST"
|
local TEST_CMD="$CARGO test $* $TEST"
|
||||||
timeout ${TIMEOUT:-10s} bash -c "$TEST_CMD 2>/dev/null" 1>&2
|
timeout ${TIMEOUT:-20s} bash -c "$TEST_CMD 2>/dev/null" 1>&2
|
||||||
case $? in
|
case $? in
|
||||||
0) ;;
|
0) ;;
|
||||||
124) echo_err "Test timed out: $TEST_CMD"; FAILED=$((FAILED + 1));;
|
124) echo_err "Test timed out: $TEST_CMD"; FAILED=$((FAILED + 1));;
|
||||||
@@ -73,6 +94,6 @@ _run_tests_with() {
|
|||||||
run_tests() {
|
run_tests() {
|
||||||
# "cargo --release" should be split into "cargo" and "--release"
|
# "cargo --release" should be split into "cargo" and "--release"
|
||||||
local IFS=' '
|
local IFS=' '
|
||||||
echo $(_run_tests_with $RUNNER)
|
_run_tests_with $RUNNER
|
||||||
}
|
}
|
||||||
export -f run_tests
|
export -f run_tests
|
||||||
|
|||||||
Reference in New Issue
Block a user