Refine tests, CLI
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
set -u
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
CONFIG_DIR="${FFX_CONFIG_DIR:-${HOME}/.local/etc}"
|
||||
CONFIG_FILE="${FFX_CONFIG_FILE:-${CONFIG_DIR}/ffx.json}"
|
||||
VAR_DIR="${FFX_VAR_DIR:-${HOME}/.local/var/ffx}"
|
||||
@@ -11,6 +9,7 @@ LOG_DIR="${FFX_LOG_DIR:-${HOME}/.local/var/log}"
|
||||
DATABASE_FILE="${FFX_DATABASE_FILE:-${VAR_DIR}/ffx.db}"
|
||||
|
||||
CHECK_ONLY=0
|
||||
WITH_TESTS=0
|
||||
|
||||
MUTATIONS=0
|
||||
INSTALL_FAILURES=0
|
||||
@@ -33,12 +32,13 @@ fi
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [--check] [--help]
|
||||
Usage: $(basename "$0") [--check] [--with-tests] [--help]
|
||||
|
||||
Prepare the local FFX development environment for this repository.
|
||||
Prepare the local workstation environment for an already installed FFX bundle.
|
||||
|
||||
Options:
|
||||
--check Report readiness only. Do not create, install, or modify.
|
||||
--with-tests Include test-related notes while preparing system dependencies and local config.
|
||||
--help Show this help text.
|
||||
|
||||
Environment overrides:
|
||||
@@ -47,6 +47,11 @@ Environment overrides:
|
||||
FFX_VAR_DIR Override the default data directory.
|
||||
FFX_LOG_DIR Override the default log directory.
|
||||
FFX_DATABASE_FILE Override the database path written into a newly seeded config.
|
||||
|
||||
Notes:
|
||||
- tools/setup.sh is the first installation step and owns bundle venv setup.
|
||||
- This script is the second step and owns system dependencies plus local config.
|
||||
- Python test packages are installed by tools/setup.sh --with-tests, not here.
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -228,6 +233,16 @@ print_seeded_file_status() {
|
||||
report_seeded_component "ffx config" "ffx-config" "optional"
|
||||
}
|
||||
|
||||
print_test_package_status() {
|
||||
if [ "${WITH_TESTS}" -eq 0 ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Test environment notes:"
|
||||
report_component ok "system test dependencies" "no extra system packages beyond the standard runtime toolchain"
|
||||
report_component ok "Python test packages" "install via tools/setup.sh --with-tests"
|
||||
}
|
||||
|
||||
detect_package_manager() {
|
||||
if command_exists apt-get; then
|
||||
printf 'apt-get\n'
|
||||
@@ -380,6 +395,9 @@ parse_args() {
|
||||
--check)
|
||||
CHECK_ONLY=1
|
||||
;;
|
||||
--with-tests)
|
||||
WITH_TESTS=1
|
||||
;;
|
||||
--help|-h)
|
||||
usage
|
||||
exit 0
|
||||
@@ -409,10 +427,17 @@ main() {
|
||||
echo
|
||||
print_seeded_file_status
|
||||
|
||||
echo
|
||||
print_test_package_status
|
||||
|
||||
if [ "${CHECK_ONLY}" -eq 0 ]; then
|
||||
seed_default_config
|
||||
echo
|
||||
print_dependency_status
|
||||
echo
|
||||
print_seeded_file_status
|
||||
echo
|
||||
print_test_package_status
|
||||
fi
|
||||
|
||||
echo
|
||||
@@ -14,6 +14,7 @@ ALIAS_BLOCK_END="# <<< ffx alias <<<"
|
||||
ALIAS_LINE="alias ffx=\"${VENV_FFX}\""
|
||||
|
||||
CHECK_ONLY=0
|
||||
WITH_TESTS=0
|
||||
READINESS_FAILURES=0
|
||||
INSTALL_FAILURES=0
|
||||
|
||||
@@ -31,19 +32,25 @@ fi
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [--check] [--help]
|
||||
Usage: $(basename "$0") [--check] [--with-tests] [--help]
|
||||
|
||||
Prepare the persistent FFX bundle virtualenv at:
|
||||
Prepare the persistent FFX bundle installation at:
|
||||
${VENV_DIR}
|
||||
|
||||
Actions:
|
||||
- create or reuse ${VENV_DIR}
|
||||
- install this repository into the venv with pip --editable
|
||||
- ensure ${BASHRC_FILE} exposes alias ffx -> ${VENV_FFX}
|
||||
- optionally install Python packages required for modern tests
|
||||
|
||||
Options:
|
||||
--check Report readiness only. Do not create or modify anything.
|
||||
--help Show this help text.
|
||||
--check Report readiness only. Do not create or modify anything.
|
||||
--with-tests Also install and verify Python packages required for modern tests.
|
||||
--help Show this help text.
|
||||
|
||||
Notes:
|
||||
- This is the first installation step.
|
||||
- tools/configure_workstation.sh is the second step and configures system dependencies plus local user files.
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -100,6 +107,10 @@ check_venv_ffx() {
|
||||
[ -x "${VENV_FFX}" ]
|
||||
}
|
||||
|
||||
check_venv_pytest() {
|
||||
check_venv_dir && "${VENV_PYTHON}" -m pytest --version >/dev/null 2>&1
|
||||
}
|
||||
|
||||
check_bashrc_file() {
|
||||
[ -f "${BASHRC_FILE}" ]
|
||||
}
|
||||
@@ -136,6 +147,14 @@ detail_venv_ffx() {
|
||||
fi
|
||||
}
|
||||
|
||||
detail_venv_pytest() {
|
||||
if check_venv_pytest; then
|
||||
"${VENV_PYTHON}" -m pytest --version 2>/dev/null | head -n 1
|
||||
else
|
||||
printf 'missing pytest in %s' "${VENV_DIR}"
|
||||
fi
|
||||
}
|
||||
|
||||
detail_bashrc_file() {
|
||||
if check_bashrc_file; then
|
||||
printf '%s' "${BASHRC_FILE}"
|
||||
@@ -186,6 +205,17 @@ print_status_report() {
|
||||
READINESS_FAILURES=$((READINESS_FAILURES + 1))
|
||||
fi
|
||||
|
||||
if [ "${WITH_TESTS}" -eq 1 ]; then
|
||||
echo
|
||||
echo "Bundle test package status:"
|
||||
if check_venv_pytest; then
|
||||
report_component ok "bundle pytest" "$(detail_venv_pytest)"
|
||||
else
|
||||
report_component failed "bundle pytest" "$(detail_venv_pytest)"
|
||||
READINESS_FAILURES=$((READINESS_FAILURES + 1))
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Shell exposure status:"
|
||||
if check_bashrc_file; then
|
||||
@@ -220,11 +250,23 @@ ensure_bundle_venv() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
printf 'Installing FFX package into %s...\n' "${VENV_DIR}"
|
||||
if ! "${VENV_PIP}" install --editable "${ROOT_DIR}"; then
|
||||
printf 'Failed to install FFX package into %s.\n' "${VENV_DIR}" >&2
|
||||
INSTALL_FAILURES=$((INSTALL_FAILURES + 1))
|
||||
return 1
|
||||
if [ "${WITH_TESTS}" -eq 1 ]; then
|
||||
printf 'Installing FFX package and test extras into %s...\n' "${VENV_DIR}"
|
||||
if ! (
|
||||
cd "${ROOT_DIR}" &&
|
||||
"${VENV_PIP}" install --editable '.[test]'
|
||||
); then
|
||||
printf 'Failed to install FFX package and test extras into %s.\n' "${VENV_DIR}" >&2
|
||||
INSTALL_FAILURES=$((INSTALL_FAILURES + 1))
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
printf 'Installing FFX package into %s...\n' "${VENV_DIR}"
|
||||
if ! "${VENV_PIP}" install --editable "${ROOT_DIR}"; then
|
||||
printf 'Failed to install FFX package into %s.\n' "${VENV_DIR}" >&2
|
||||
INSTALL_FAILURES=$((INSTALL_FAILURES + 1))
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
@@ -300,6 +342,9 @@ parse_args() {
|
||||
--check)
|
||||
CHECK_ONLY=1
|
||||
;;
|
||||
--with-tests)
|
||||
WITH_TESTS=1
|
||||
;;
|
||||
--help|-h)
|
||||
usage
|
||||
exit 0
|
||||
|
||||
22
tools/test.sh
Executable file
22
tools/test.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
|
||||
PYTHON_BIN="${FFX_PYTHON:-${HOME}/.local/share/ffx.venv/bin/python}"
|
||||
|
||||
if [[ ! -x "${PYTHON_BIN}" ]]; then
|
||||
echo "Missing Python interpreter: ${PYTHON_BIN}" >&2
|
||||
echo "Set FFX_PYTHON to a suitable interpreter if needed." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "${REPO_ROOT}"
|
||||
|
||||
exec "${PYTHON_BIN}" -m pytest \
|
||||
--ignore=tests/legacy \
|
||||
--ignore=tests/support \
|
||||
tests \
|
||||
"$@"
|
||||
Reference in New Issue
Block a user