add random lang hability

This commit is contained in:
fatalerrors
2026-05-27 17:31:37 +02:00
parent 7c761a4895
commit 7287d8ef87

View File

@@ -118,13 +118,13 @@ export -f busy
# Options:
# --min-delay=<ms> : minimum delay between output lines (milliseconds, default: 40)
# --max-delay=<ms> : maximum delay between output lines (milliseconds, default: 150)
# --lang=<lang> : source language preset: c (default), cpp, java, python
# --lang=<lang> : source language preset: c (default), cpp, java, python, random
# --errors : inject fake compilation errors at the end of the build
fake_compile()
{
local min_ms="${FAKE_COMPILE_DEFAULT_MIN_DELAY:-40}" \
max_ms="${FAKE_COMPILE_DEFAULT_MAX_DELAY:-150}" \
lang="c" with_errors=0
lang="${FAKE_COMPILE_DEFAULT_LANG:-c}" with_errors=0
local PARSED
# Short: h, n:, x:, l:, e
@@ -146,7 +146,7 @@ fake_compile()
printf "\t-h, --help\t\t\tDisplay this help screen\n"
printf "\t-n, --min-delay MS\t\tMin delay between lines in milliseconds (default: 40)\n"
printf "\t-x, --max-delay MS\t\tMax delay between lines in milliseconds (default: 150)\n"
printf "\t-l, --lang LANG\t\t\tLanguage preset: c, cpp, java, python (default: c)\n"
printf "\t-l, --lang LANG\t\t\tLanguage preset: c, cpp, java, python, random (default: c)\n"
printf "\t-e, --errors\t\t\tInject fake compilation errors at the end\n"
return 0
;;
@@ -169,9 +169,9 @@ fake_compile()
-l|--lang)
lang="$2"
case "$lang" in
c|cpp|java|python) ;;
c|cpp|java|python|random) ;;
*)
disp E "Invalid lang: must be one of: c, cpp, java, python."
disp E "Invalid lang: must be one of: c, cpp, java, python, random."
return 1
;;
esac
@@ -243,6 +243,16 @@ fake_compile()
esac
while true; do
if [[ "$lang" == "random" ]]; then
_langs=("c" "cpp" "java" "python")
_pick="${_langs[$((RANDOM % 4))]}"
case "$_pick" in
c) files=("${c_files[@]}"); ext=".c" ;;
cpp) files=("${cpp_files[@]}"); ext=".cpp" ;;
java) files=("${java_files[@]}"); ext=".java" ;;
python) files=("${python_files[@]}"); ext=".py" ;;
esac
fi
total=${#files[@]}
i=0
for f in "${files[@]}"; do