Rocket/scripts/test.sh
Sergio Benitez 1fb061496d Revamp configuration.
This commit completely overhauls Rocket's configuration systems, basing
it on the new Figment library. It includes many breaking changes
pertaining to configuration. They are:

  * "Environments" are replaced by "profiles".
  * 'ROCKET_PROFILE' takes the place of 'ROCKET_ENV'.
  * Profile names are now arbitrary, but 'debug' and 'release' are given
    special treatment as default profiles for the debug and release
    compilation profiles.
  * A 'default' profile now sits along-side the meta 'global' profile.
  * The concept of "extras" is no longer present; users can extract any
    values they want from the configured 'Figment'.
  * The 'Poolable' trait takes an '&Config'.
  * The 'secrets' feature is disabled by default.
  * It is a hard error if 'secrets' is enabled under the 'release'
    profile and no 'secret_key' is configured.
  * 'ConfigBuilder' no longer exists: all fields of 'Config' are public
    with public constructors for each type.
  * 'keep_alive' is disabled with '0', not 'false' or 'off'.
  * Inlined error variants into the 'Error' structure.
  * 'LoggingLevel' is now 'LogLevel'.
  * Limits can now be specified in SI units: "1 MiB".

The summary of other changes are:

  * The default config file can be configured with 'ROCKET_CONFIG'.
  * HTTP/1 and HTTP/2 keep-alive configuration is restored.
  * 'ctrlc' is now a recognized config option.
  * 'serde' is now a core dependency.
  * TLS misconfiguration errors are improved.
  * Several example use '_' as the return type of '#[launch]' fns.
  * 'AdHoc::config()' was added for simple config extraction.
  * Added more documentation for using 'Limits'.
  * Launch information is no longer treated specially.
  * The configuration guide was rewritten.

Resolves #852.
Resolves #209.
Closes #1404.
Closes #652.
2020-10-20 19:21:56 -07:00

132 lines
3.2 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"
# We set a `cfg` so that a missing `secret_key` doesn't abort tests.
export RUSTFLAGS="--cfg rocket_unsafe_secret_key"
# 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
}
# Ensures there are no tabs in any file.
function ensure_tab_free() {
local tab=$(printf '\t')
local matches=$(git grep -E -I "${tab}" "${PROJECT_ROOT}" | grep -v 'LICENSE')
if ! [ -z "${matches}" ]; then
echo "Tab characters were found in the following:"
echo "${matches}"
exit 1
fi
}
# Ensures there are no files with trailing whitespace.
function ensure_trailing_whitespace_free() {
local matches=$(git grep -E -I "\s+$" "${PROJECT_ROOT}" | grep -v -F '.stderr:')
if ! [ -z "${matches}" ]; then
echo "Trailing whitespace was found in the following:"
echo "${matches}"
exit 1
fi
}
if [[ $1 == +* ]]; then
CARGO="$CARGO $1"
shift
fi
echo ":: Preparing. Environment is..."
print_environment
echo " CARGO: $CARGO"
echo " RUSTFLAGS: $RUSTFLAGS"
echo ":: Ensuring all crate versions match..."
check_versions_match "${ALL_PROJECT_DIRS[@]}"
echo ":: Checking for tabs..."
ensure_tab_free
echo ":: Checking for trailing whitespace..."
ensure_trailing_whitespace_free
echo ":: Updating dependencies..."
if ! $CARGO update ; then
echo " WARNING: Update failed! Proceeding with possibly outdated deps..."
fi
if [ "$1" = "--contrib" ]; then
FEATURES=(
json
msgpack
tera_templates
handlebars_templates
serve
helmet
diesel_postgres_pool
diesel_sqlite_pool
diesel_mysql_pool
postgres_pool
mysql_pool
sqlite_pool
memcache_pool
brotli_compression
gzip_compression
)
pushd "${CONTRIB_LIB_ROOT}" > /dev/null 2>&1
echo ":: Building and testing contrib [default]..."
$CARGO test
for feature in "${FEATURES[@]}"; do
echo ":: Building and testing contrib [${feature}]..."
$CARGO test --no-default-features --features "${feature}"
done
popd > /dev/null 2>&1
elif [ "$1" = "--core" ]; then
FEATURES=(
secrets
tls
)
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
else
echo ":: Building and testing libraries..."
$CARGO test --all-features --all $@
fi