Check fuzzers and benchmarks in testing script.

This commit is contained in:
Sergio Benitez 2021-06-07 17:53:57 -07:00
parent 0aa9a11ca4
commit 2d974ece78
2 changed files with 31 additions and 28 deletions

View File

@ -41,6 +41,7 @@ CORE_ROOT=$(relative "core") || exit $?
CONTRIB_ROOT=$(relative "contrib") || exit $? CONTRIB_ROOT=$(relative "contrib") || exit $?
SITE_ROOT=$(relative "site") || exit $? SITE_ROOT=$(relative "site") || exit $?
BENCHMARKS_ROOT=$(relative "benchmarks") || exit $? BENCHMARKS_ROOT=$(relative "benchmarks") || exit $?
FUZZ_ROOT=$(relative "core/lib/fuzz") || exit $?
# Root of project-like directories. # Root of project-like directories.
CORE_LIB_ROOT=$(relative "core/lib") || exit $? CORE_LIB_ROOT=$(relative "core/lib") || exit $?

View File

@ -58,6 +58,12 @@ function check_style() {
fi fi
} }
function indir() {
local dir="${1}"
shift
pushd "${dir}" > /dev/null 2>&1 ; $@ ; popd > /dev/null 2>&1
}
function test_contrib() { function test_contrib() {
SYNC_DB_POOLS_FEATURES=( SYNC_DB_POOLS_FEATURES=(
diesel_postgres_pool diesel_postgres_pool
@ -93,48 +99,44 @@ function test_core() {
uuid uuid
) )
pushd "${CORE_LIB_ROOT}" > /dev/null 2>&1 echo ":: Building and testing core [no features]..."
echo ":: Building and testing core [no features]..." indir "${CORE_LIB_ROOT}" $CARGO test --no-default-features $@
$CARGO test --no-default-features $@
for feature in "${FEATURES[@]}"; do for feature in "${FEATURES[@]}"; do
echo ":: Building and testing core [${feature}]..." echo ":: Building and testing core [${feature}]..."
$CARGO test --no-default-features --features "${feature}" $@ indir "${CORE_LIB_ROOT}" $CARGO test --no-default-features --features "${feature}" $@
done done
popd > /dev/null 2>&1
} }
function test_examples() { function test_examples() {
# Cargo compiles Rocket once with the `secrets` feature enabled, so when run
# in production, we need a secret key or tests will fail needlessly. We test
# in core that secret key failing/not failing works as expected, but here we
# provide a valid secret_key so tests don't fail.
echo ":: Building and testing examples..." echo ":: Building and testing examples..."
ROCKET_SECRET_KEY="itlYmFR2vYKrOmFhupMIn/hyB6lYCCTXz4yaQX89XVg=" \
pushd "${EXAMPLES_DIR}" > /dev/null 2>&1 indir "${EXAMPLES_DIR}" $CARGO test --all $@
# Rust compiles Rocket once with the `secrets` feature enabled, so when run }
# in production, we need a secret key or tests will fail needlessly. We
# test in core that secret key failing/not failing works as expected.
ROCKET_SECRET_KEY="itlYmFR2vYKrOmFhupMIn/hyB6lYCCTXz4yaQX89XVg=" \
$CARGO test --all $@
popd > /dev/null 2>&1
}
function test_default() { function test_default() {
echo ":: Building and testing core libraries..." echo ":: Building and testing core libraries..."
indir "${PROJECT_ROOT}" $CARGO test --all --all-features $@
pushd "${PROJECT_ROOT}" > /dev/null 2>&1 echo ":: Checking benchmarks..."
$CARGO test --all --all-features $@ indir "${BENCHMARKS_ROOT}" $CARGO check --benches --all-features $@
popd > /dev/null 2>&1
echo ":: Checking fuzzers..."
indir "${FUZZ_ROOT}" $CARGO check --all --all-features $@
} }
function run_benchmarks() { function run_benchmarks() {
echo ":: Running benchmarks..." echo ":: Running benchmarks..."
indir "${BENCHMARKS_ROOT}" $CARGO bench $@
pushd "${BENCHMARKS_ROOT}" > /dev/null 2>&1
$CARGO bench $@
popd > /dev/null 2>&1
} }
if [[ $1 == +* ]]; then if [[ $1 == +* ]]; then
CARGO="$CARGO $1" CARGO="$CARGO $1"
shift shift
fi fi
# The kind of test we'll be running. # The kind of test we'll be running.
@ -142,8 +144,8 @@ TEST_KIND="default"
KINDS=("contrib" "benchmarks" "core" "examples" "default" "all") KINDS=("contrib" "benchmarks" "core" "examples" "default" "all")
if [[ " ${KINDS[@]} " =~ " ${1#"--"} " ]]; then if [[ " ${KINDS[@]} " =~ " ${1#"--"} " ]]; then
TEST_KIND=${1#"--"} TEST_KIND=${1#"--"}
shift shift
fi fi
echo ":: Preparing. Environment is..." echo ":: Preparing. Environment is..."