Added basic tests
This commit is contained in:
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
pass=0
|
||||
fail=0
|
||||
|
||||
checker=""
|
||||
if command -v yamllint &>/dev/null; then
|
||||
checker=yamllint
|
||||
elif python3 -c "import yaml" 2>/dev/null; then
|
||||
checker=python
|
||||
fi
|
||||
|
||||
test_yaml() {
|
||||
local file=$1
|
||||
|
||||
case "$checker" in
|
||||
yamllint)
|
||||
if yamllint -d "{extends: relaxed, rules: {line-length: disable}}" "$file"; then
|
||||
echo " PASS $file"
|
||||
pass=$((pass+1))
|
||||
else
|
||||
echo " FAIL $file"
|
||||
fail=$((fail+1))
|
||||
fi
|
||||
;;
|
||||
python)
|
||||
if python3 -c "
|
||||
import yaml, sys
|
||||
with open('$file') as f:
|
||||
yaml.safe_load(f)
|
||||
" 2>/dev/null; then
|
||||
echo " PASS $file"
|
||||
pass=$((pass+1))
|
||||
else
|
||||
echo " FAIL $file"
|
||||
fail=$((fail+1))
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo " SKIP $file (no yamllint or PyYAML)"
|
||||
pass=$((pass+1))
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
echo "=== YAML Validation ==="
|
||||
for f in "$@"; do
|
||||
[ -f "$f" ] && test_yaml "$f"
|
||||
done
|
||||
|
||||
echo "---"
|
||||
echo "Passed: $pass Failed: $fail"
|
||||
[ "$fail" -eq 0 ]
|
||||
Reference in New Issue
Block a user