mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
The CLI tests' devvm is built with -cover, and every script set one GOCOVERDIR. Go names a run's temporary meta-data file by the time (time.Now().UnixNano(), microseconds on macOS) with no process ID, so two devvm runs from parallel scripts that start together write the same temporary file; the first renames it and the second's rename fails, and devvm prints "coverage meta-data emit failed" on stderr, failing any script that checks stderr (seen in ls.txtar and version.txtar). - script_test.go: scriptCoverDir sets GOCOVERDIR to a folder of the script's own (os.MkdirTemp under CLI_GOCOVERDIR). - scripts/test.sh: covdata merge takes the unit folder and every non-empty script folder as one comma-separated -i list, so percent and the baselines read the same counters as before. - Contributing's Coverage section says each script writes to a folder of its own, and why. Co-Authored-By: Claude Opus 5.5 <[email protected]>
42 lines
2.0 KiB
Bash
Executable File
42 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Run the unit and CLI tests with the race detector, then hold each package's coverage to its
|
|
# baseline (scripts/coverage.sh).
|
|
# scripts/test.sh fail when a package's coverage drops below its baseline (mise run test)
|
|
# scripts/test.sh --raise raise the baselines instead (mise run coverage)
|
|
# Tests get a throwaway HOME and XDG folders, so none can reach the real ones, no SSH agent, and
|
|
# no color settings of your own. Each package gets 30 minutes, not go test's 10, so the CLI tests
|
|
# finish on a busy machine instead of timing out. Coverage comes from each package's own tests and
|
|
# from the CLI tests' devvm, built with -cover for every package (CLI_GOCOVERDIR, a folder for each script), merged with
|
|
# go tool covdata. The baselines are in testdata/coverage/.
|
|
set -euo pipefail
|
|
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
mode=check
|
|
case ${1:-} in
|
|
'') ;;
|
|
--raise) mode=raise ;;
|
|
*) echo "usage: scripts/test.sh [--raise]" >&2; exit 2 ;;
|
|
esac
|
|
|
|
GOCACHE="$(go env GOCACHE)" GOMODCACHE="$(go env GOMODCACHE)" GOPATH="$(go env GOPATH)"
|
|
export GOCACHE GOMODCACHE GOPATH
|
|
home="$(mktemp -d "${TMPDIR:-/tmp}/devvm-test.XXXXXX")"
|
|
trap 'rm -rf "$home"' EXIT
|
|
cov="$home/coverage"
|
|
mkdir -p "$cov/unit" "$cov/cli" "$cov/merged"
|
|
unset SSH_AUTH_SOCK NO_COLOR FORCE_COLOR CLICOLOR_FORCE
|
|
cd "$root"
|
|
HOME="$home" XDG_DATA_HOME="$home/.local/share" XDG_CONFIG_HOME="$home/.config" XDG_CACHE_HOME="$home/.cache" \
|
|
CLI_GOCOVERDIR="$cov/cli" \
|
|
gotestsum -- -race -cover -timeout 30m ./... -args -test.gocoverdir="$cov/unit"
|
|
# Each CLI test script writes its devvm's coverage to a folder of its own under $cov/cli, so
|
|
# devvm runs in parallel scripts don't race on one meta-data file. A script that never ran
|
|
# devvm leaves its folder empty, and it's left out.
|
|
inputs="$cov/unit"
|
|
for dir in "$cov/cli"/*/; do
|
|
dir="${dir%/}"
|
|
if [ -d "$dir" ] && [ -n "$(ls -A "$dir")" ]; then inputs="$inputs,$dir"; fi
|
|
done
|
|
go tool covdata merge -i="$inputs" -o="$cov/merged"
|
|
go tool covdata percent -i="$cov/merged" >"$cov/percents"
|
|
scripts/coverage.sh "$mode" "$cov/percents"
|