91 lines
2.2 KiB
Bash
Executable File
91 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Function to show usage
|
|
usage() {
|
|
echo "Usage: $0 [write|validate]"
|
|
exit 1
|
|
}
|
|
|
|
# Ensure a mode is provided
|
|
if [[ $# -ne 1 ]]; then
|
|
usage
|
|
fi
|
|
|
|
MODE=$1
|
|
|
|
# Write mode
|
|
if [[ "$MODE" == "write" ]]; then
|
|
echo "Running in write mode..."
|
|
|
|
for script in *.kts; do
|
|
test_file="${script}.testvalue"
|
|
|
|
echo "Processing $script..."
|
|
output=$(kotlin "$script" 2>&1)
|
|
|
|
if [[ -f "$test_file" ]]; then
|
|
if [[ "$output" == "$(cat "$test_file")" ]]; then
|
|
echo "No change: $script"
|
|
else
|
|
echo "Output changed for $script"
|
|
diff -u "$test_file" <(echo "$output")
|
|
read -p "Update test value? (y/n) " update
|
|
if [[ "$update" == "y" ]]; then
|
|
echo "$output" > "$test_file"
|
|
echo "Updated $test_file"
|
|
fi
|
|
fi
|
|
else
|
|
echo "$output" > "$test_file"
|
|
echo "Created $test_file"
|
|
fi
|
|
done
|
|
|
|
for test_file in *.kts.testvalue; do
|
|
script="${test_file%.testvalue}"
|
|
if [[ ! -f "$script" ]]; then
|
|
echo "Test file $test_file does not have a matching script."
|
|
read -p "Delete $test_file? (y/n) " delete
|
|
if [[ "$delete" == "y" ]]; then
|
|
rm "$test_file"
|
|
echo "Deleted $test_file"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
# Validate mode
|
|
elif [[ "$MODE" == "validate" ]]; then
|
|
echo "Running in validate mode..."
|
|
pass=0
|
|
fail=0
|
|
|
|
for test_file in *.kts.testvalue; do
|
|
script="${test_file%.testvalue}"
|
|
if [[ -f "$script" ]]; then
|
|
output=$(kotlin "$script" 2>&1)
|
|
if [[ "$output" == "$(cat "$test_file")" ]]; then
|
|
echo "PASS: $script"
|
|
((pass++))
|
|
else
|
|
echo "FAIL: $script"
|
|
diff -u "$test_file" <(echo "$output")
|
|
((fail++))
|
|
fi
|
|
else
|
|
echo "Orphaned test file: $test_file (no matching script)"
|
|
((fail++))
|
|
fi
|
|
done
|
|
|
|
echo "Summary: $pass pass, $fail fail"
|
|
|
|
if [[ $fail -gt 0 ]]; then
|
|
exit 1
|
|
else
|
|
exit 0
|
|
fi
|
|
|
|
else
|
|
usage
|
|
fi
|