Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·70 lines (59 loc) · 2.98 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·70 lines (59 loc) · 2.98 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
#!/usr/bin/env bash
# Run all tests: pytest (Python tools) + smoke tests for every script under scripts/
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PASS=0; FAIL=0
green() { printf '\033[32m PASS %s\033[0m\n' "$*"; }
red() { printf '\033[31m FAIL %s\033[0m\n' "$*"; }
check() {
local label="$1"; shift
if eval "$@" &>/dev/null 2>&1; then
green "$label"; ((PASS++))
else
red "$label"; ((FAIL++))
fi
}
dur() { ffprobe -v quiet -show_entries format=duration \
-of default=noprint_wrappers=1:nokey=1 "$1" 2>/dev/null; }
# ---------------------------------------------------------------------------
# 1. Pytest — Python tools
# ---------------------------------------------------------------------------
echo ""
echo "── Python tests (pytest) ───────────────────────────────────────────────"
if cd "$SCRIPT_DIR" && uv run pytest tests/ -q --tb=short 2>&1; then
((PASS++))
else
((FAIL++))
fi
# ---------------------------------------------------------------------------
# 2. Shell script smoke tests
# ---------------------------------------------------------------------------
echo ""
echo "── Shell script smoke tests ────────────────────────────────────────────"
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
# Generate a 5-second test tone (ffmpeg lavfi — no real audio files needed)
TEST_MP3="$TMP/test.mp3"
ffmpeg -y -f lavfi -i "sine=frequency=440:duration=5" -b:a 128k "$TEST_MP3" &>/dev/null
# --- scripts/audio/change_speed.sh ---
S="$SCRIPT_DIR/scripts/audio/change_speed.sh"
echo ""
echo " change_speed.sh"
check "no args → non-zero exit" "! bash '$S'"
check "1.5x → output file exists" "bash '$S' '$TEST_MP3' 1.5 '$TMP/fast.mp3'"
check "1.5x → shorter than input" "awk 'BEGIN{exit ($(dur $TMP/fast.mp3) < $(dur $TEST_MP3))?0:1}'"
check "0.8x → output file exists" "bash '$S' '$TEST_MP3' 0.8 '$TMP/slow.mp3'"
check "0.8x → longer than input" "awk 'BEGIN{exit ($(dur $TMP/slow.mp3) > $(dur $TEST_MP3))?0:1}'"
check "auto-naming → sample-1.2x.mp3" "cp '$TEST_MP3' '$TMP/sample.mp3' && bash '$S' '$TMP/sample.mp3' 1.2 && test -f '$TMP/sample-1.2x.mp3'"
check "speed > 2.0 → chained atempo" "bash '$S' '$TEST_MP3' 2.5 '$TMP/chained.mp3'"
# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------
echo ""
echo "────────────────────────────────────────────────────────────────────────"
if [[ $FAIL -eq 0 ]]; then
printf '\033[32mAll tests passed (%d passed, 0 failed)\033[0m\n' "$PASS"
else
printf '\033[31m%d failed, %d passed\033[0m\n' "$FAIL" "$PASS"
exit 1
fi