mirror of
https://github.com/rwf2/Rocket.git
synced 2024-12-26 04:12:40 +00:00
5a4e66ec43
This follows the completed graduation of stable contrib features into core, removing 'rocket_contrib' in its entirety in favor of two new crates. These crates are versioned independently of Rocket's core libraries, allowing upgrades to dependencies without consideration for versions in core libraries. 'rocket_dyn_templates' replaces the contrib 'templates' features. While largely a 1-to-1 copy, it makes the following changes: * the 'tera_templates' feature is now 'tera' * the 'handlebars_templates' feature is now 'handlebars' * fails to compile if neither 'tera' nor 'handlebars' is enabled 'rocket_sync_db_pools' replaces the contrib 'database' features. It makes no changes to the replaced features except that the `database` attribute is properly documented at the crate root.
196 lines
5.0 KiB
Bash
Executable File
196 lines
5.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Brings in _ROOT, _DIR, _DIRS globals.
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
source "${SCRIPT_DIR}/config.sh"
|
|
|
|
# Add Cargo to PATH.
|
|
export PATH=${HOME}/.cargo/bin:${PATH}
|
|
export CARGO_INCREMENTAL=0
|
|
CARGO="cargo"
|
|
|
|
# Checks that the versions for Cargo projects $@ all match
|
|
function check_versions_match() {
|
|
local last_version=""
|
|
for dir in "${@}"; do
|
|
local cargo_toml="${dir}/Cargo.toml"
|
|
if ! [ -f "${cargo_toml}" ]; then
|
|
echo "Cargo configuration file '${cargo_toml}' does not exist."
|
|
exit 1
|
|
fi
|
|
|
|
local version=$(grep version "${cargo_toml}" | head -n 1 | cut -d' ' -f3)
|
|
if [ -z "${last_version}" ]; then
|
|
last_version="${version}"
|
|
elif ! [ "${version}" = "${last_version}" ]; then
|
|
echo "Versions differ in '${cargo_toml}'. ${version} != ${last_version}"
|
|
exit 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
function check_style() {
|
|
# Ensure there are no tabs in any file.
|
|
local tab=$(printf '\t')
|
|
local matches=$(git grep -E -I -n "${tab}" "${PROJECT_ROOT}" | grep -v 'LICENSE')
|
|
if ! [ -z "${matches}" ]; then
|
|
echo "Tab characters were found in the following:"
|
|
echo "${matches}"
|
|
exit 1
|
|
fi
|
|
|
|
# Ensure non-comment lines are under 100 characters.
|
|
local n=100
|
|
local matches=$(git grep -P -I -n "(?=^..{$n,}$)(?!^\s*\/\/[\/!].*$).*" '*.rs')
|
|
if ! [ -z "${matches}" ]; then
|
|
echo "Lines longer than $n characters were found in the following:"
|
|
echo "${matches}"
|
|
exit 1
|
|
fi
|
|
|
|
# Ensure there's no trailing whitespace.
|
|
local matches=$(git grep -E -I -n "\s+$" "${PROJECT_ROOT}" | grep -v -F '.stderr:')
|
|
if ! [ -z "${matches}" ]; then
|
|
echo "Trailing whitespace was found in the following:"
|
|
echo "${matches}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function test_contrib() {
|
|
SYNC_DB_POOLS_FEATURES=(
|
|
diesel_postgres_pool
|
|
diesel_sqlite_pool
|
|
diesel_mysql_pool
|
|
postgres_pool
|
|
sqlite_pool
|
|
memcache_pool
|
|
)
|
|
|
|
DYN_TEMPLATES_FEATURES=(
|
|
tera
|
|
handlebars
|
|
)
|
|
|
|
for feature in "${SYNC_DB_POOLS_FEATURES[@]}"; do
|
|
echo ":: Building and testing sync_db_pools [$feature]..."
|
|
$CARGO test -p rocket_sync_db_pools --no-default-features --features $feature $@
|
|
done
|
|
|
|
for feature in "${DYN_TEMPLATES_FEATURES[@]}"; do
|
|
echo ":: Building and testing dyn_templates [$feature]..."
|
|
$CARGO test -p rocket_dyn_templates --no-default-features --features $feature $@
|
|
done
|
|
}
|
|
|
|
function test_core() {
|
|
FEATURES=(
|
|
secrets
|
|
tls
|
|
json
|
|
msgpack
|
|
uuid
|
|
)
|
|
|
|
pushd "${CORE_LIB_ROOT}" > /dev/null 2>&1
|
|
echo ":: Building and testing core [no features]..."
|
|
$CARGO test --no-default-features $@
|
|
|
|
for feature in "${FEATURES[@]}"; do
|
|
echo ":: Building and testing core [${feature}]..."
|
|
$CARGO test --no-default-features --features "${feature}" $@
|
|
done
|
|
popd > /dev/null 2>&1
|
|
}
|
|
|
|
function test_examples() {
|
|
echo ":: Building and testing examples..."
|
|
|
|
pushd "${EXAMPLES_DIR}" > /dev/null 2>&1
|
|
# 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() {
|
|
echo ":: Building and testing core libraries..."
|
|
|
|
pushd "${PROJECT_ROOT}" > /dev/null 2>&1
|
|
$CARGO test --all --all-features $@
|
|
popd > /dev/null 2>&1
|
|
}
|
|
|
|
function run_benchmarks() {
|
|
echo ":: Running benchmarks..."
|
|
|
|
pushd "${BENCHMARKS_ROOT}" > /dev/null 2>&1
|
|
$CARGO bench $@
|
|
popd > /dev/null 2>&1
|
|
}
|
|
|
|
if [[ $1 == +* ]]; then
|
|
CARGO="$CARGO $1"
|
|
shift
|
|
fi
|
|
|
|
# The kind of test we'll be running.
|
|
TEST_KIND="default"
|
|
KINDS=("contrib" "benchmarks" "core" "examples" "default" "all")
|
|
|
|
if [[ " ${KINDS[@]} " =~ " ${1#"--"} " ]]; then
|
|
TEST_KIND=${1#"--"}
|
|
shift
|
|
fi
|
|
|
|
echo ":: Preparing. Environment is..."
|
|
print_environment
|
|
echo " CARGO: $CARGO"
|
|
echo " EXTRA FLAGS: $@"
|
|
|
|
echo ":: Ensuring all crate versions match..."
|
|
check_versions_match "${ALL_PROJECT_DIRS[@]}"
|
|
|
|
echo ":: Ensuring minimum style requirements are met..."
|
|
check_style
|
|
|
|
echo ":: Updating dependencies..."
|
|
if ! $CARGO update ; then
|
|
echo " WARNING: Update failed! Proceeding with possibly outdated deps..."
|
|
fi
|
|
|
|
case $TEST_KIND in
|
|
core) test_core $@ ;;
|
|
contrib) test_contrib $@ ;;
|
|
examples) test_examples $@ ;;
|
|
default) test_default $@ ;;
|
|
benchmarks) run_benchmarks $@ ;;
|
|
all)
|
|
test_default $@ & default=$!
|
|
test_examples $@ & examples=$!
|
|
test_core $@ & core=$!
|
|
test_contrib $@ & contrib=$!
|
|
|
|
failures=()
|
|
if ! wait $default ; then failures+=("DEFAULT"); fi
|
|
if ! wait $examples ; then failures+=("EXAMPLES"); fi
|
|
if ! wait $core ; then failures+=("CORE"); fi
|
|
if ! wait $contrib ; then failures+=("CONTRIB"); fi
|
|
|
|
if [ ${#failures[@]} -ne 0 ]; then
|
|
tput setaf 1;
|
|
echo -e "\n!!! ${#failures[@]} TEST SUITE FAILURE(S) !!!"
|
|
for failure in "${failures[@]}"; do
|
|
echo " :: ${failure}"
|
|
done
|
|
|
|
tput sgr0
|
|
exit ${#failures[@]}
|
|
fi
|
|
|
|
;;
|
|
esac
|