zero-check-pipeline/validate/tests.sh
Travis Herbranson c801f03f5d validate: detect uv projects in deps.sh and tests.sh
Preserve pre-existing WIP from master's working tree. When a project
has a uv.lock alongside pyproject.toml, run pip-audit and pytest under
`uv run --directory $project` so they execute in the project's own
managed venv instead of whatever pytest/pip-audit happens to be on PATH.

Lifted verbatim from master's uncommitted working tree; committed on
this branch as the base for subsequent Bug B (tests.sh SIGPIPE) and
Bug C (pip-audit venv) fixes which both modify these regions.
2026-05-12 07:50:55 -04:00

67 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
TARGET="${1:-.}"
errors=0
echo "=== Test Suite ==="
has_python=$(find "$TARGET" -name "test_*.py" -o -name "*_test.py" | head -1)
has_go=$(find "$TARGET" -name "*_test.go" | head -1)
if [ -z "$has_python" ] && [ -z "$has_go" ]; then
printf "${YELLOW}!${NC} No test files found — skipping\n"
exit 0
fi
if [ -n "$has_python" ]; then
if ! command -v pytest &>/dev/null; then
printf "${RED}${NC} pytest not installed\n"
exit 2
fi
has_uvlock=$(find "$TARGET" -maxdepth 2 -name "uv.lock" | head -1)
echo "-- Python (pytest --cov) --"
if [ -n "$has_uvlock" ]; then
printf " mode: uv project\n"
uv_dir=$(dirname "$has_uvlock")
test_cmd="uv run --directory $uv_dir pytest --cov --cov-report=term-missing -q"
else
printf " mode: global pytest\n"
test_cmd="pytest $TARGET --cov --cov-report=term-missing -q"
fi
if $test_cmd 2>/dev/null; then
printf "${GREEN}${NC} Python tests passed\n"
else
printf "${RED}${NC} Python tests failed\n"
errors=$((errors + 1))
fi
fi
if [ -n "$has_go" ]; then
if ! command -v go &>/dev/null; then
printf "${RED}${NC} go not installed\n"
exit 2
fi
echo "-- Go (go test -cover) --"
if go test -cover ./... 2>/dev/null; then
printf "${GREEN}${NC} Go tests passed\n"
else
printf "${RED}${NC} Go tests failed\n"
errors=$((errors + 1))
fi
fi
if [ "$errors" -gt 0 ]; then
exit 1
else
exit 0
fi