-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·86 lines (78 loc) · 2.06 KB
/
test.sh
File metadata and controls
executable file
·86 lines (78 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /bin/bash
set -o errexit -o pipefail -o nounset
# Validate PDU_NO_FAIL_FAST
no_fail_fast="${PDU_NO_FAIL_FAST:-false}"
case "$no_fail_fast" in
true | false) ;;
*)
echo "error: Invalid value for PDU_NO_FAIL_FAST: $no_fail_fast (expected 'true' or 'false')" >&2
exit 1
;;
esac
# A temporary file is used instead of a variable because run_if and unit are
# subshells, so variable assignments inside them don't propagate to the parent.
failure_dir=$(mktemp -d)
trap 'rm -rf "$failure_dir"' EXIT
failure_marker="$failure_dir/failed"
run() (
echo >&2
echo "exec> $*" >&2
"$@"
)
skip() (
echo >&2
echo "skip> $*" >&2
)
run_if() (
condition="$1"
shift
case "$condition" in
true)
if [[ $no_fail_fast == 'true' ]]; then
run "$@" || {
exit_status=$?
printf 'error: Command failed with exit code %d: ' "$exit_status" >&2
printf '%q ' "$@" >&2
printf '\n' >&2
touch "$failure_marker"
}
else
run "$@"
fi
;;
false) skip "$@" ;;
*)
echo "error: Invalid condition: $condition" >&2
exit 1
;;
esac
)
unit() (
read -ra build_flags <<<"${BUILD_FLAGS:-}"
read -ra test_flags <<<"${TEST_FLAGS:-}"
read -ra test_skip <<<"${TEST_SKIP:-}"
skip_args=()
for name in ${test_skip[@]+"${test_skip[@]}"}; do
skip_args+=(--skip "$name")
done
run_if "${LINT:-true}" cargo clippy "$@" -- -D warnings
run_if "${DOC:-false}" cargo doc "$@"
run_if "${BUILD:-true}" cargo build ${build_flags[@]+"${build_flags[@]}"} "$@"
if [[ ${#skip_args[@]} -gt 0 ]]; then
run_if "${TEST:-true}" cargo test ${test_flags[@]+"${test_flags[@]}"} "$@" -- "${skip_args[@]}"
else
run_if "${TEST:-true}" cargo test ${test_flags[@]+"${test_flags[@]}"} "$@"
fi
)
run_if "${FMT:-true}" cargo fmt -- --check
unit "$@"
unit --no-default-features "$@"
unit --all-features "$@"
unit --features cli "$@"
unit --features cli-completions "$@"
unit --features ai-instructions "$@"
if [[ -f "$failure_marker" ]]; then
echo >&2
echo 'error: Some checks have failed. Review the output above for details.' >&2
exit 1
fi