Refactoring. (0.37.51)
This commit is contained in:
parent
db68b30d5b
commit
c6aef6f290
19 changed files with 31 additions and 16 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(fun VERSION 0.37.51 LANGUAGES C)
|
project(fun VERSION 0.37.52 LANGUAGES C)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ if (res["code"] == 0)
|
||||||
else
|
else
|
||||||
print("Login failed!")
|
print("Login failed!")
|
||||||
|
|
||||||
|
// Propagate the child process exit status to the Fun program's exit code
|
||||||
|
exit res["code"]
|
||||||
|
|
||||||
/* Possible output:
|
/* Possible output:
|
||||||
Username: hanez
|
Username: hanez
|
||||||
Password:
|
Password:
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,9 @@ set -euo pipefail
|
||||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
|
||||||
EX_DIR="$ROOT/examples"
|
EX_DIR="$ROOT/examples"
|
||||||
|
|
||||||
# Allow override via first arg or FUN_BIN env
|
# Optional overrides via FUN_BIN env. First positional arg may now be an examples subdirectory.
|
||||||
BIN="${1:-${FUN_BIN:-}}"
|
BIN="${FUN_BIN:-}"
|
||||||
|
SUBDIR="${1:-}"
|
||||||
|
|
||||||
pick_bin() {
|
pick_bin() {
|
||||||
local cands=(
|
local cands=(
|
||||||
|
|
@ -36,11 +37,17 @@ pick_bin() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If user passed a subdir that actually looks like an executable path, treat it as BIN for backward compatibility
|
||||||
|
if [[ -n "$SUBDIR" && -x "$SUBDIR" && ! -d "$EX_DIR/$SUBDIR" ]]; then
|
||||||
|
BIN="$SUBDIR"
|
||||||
|
SUBDIR=""
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z "${BIN}" ]]; then
|
if [[ -z "${BIN}" ]]; then
|
||||||
if ! BIN="$(pick_bin)"; then
|
if ! BIN="$(pick_bin)"; then
|
||||||
echo "error: fun binary not found. Try building it (e.g., via CMake) or pass it explicitly:" >&2
|
echo "error: fun binary not found. Try building it (e.g., via CMake) or pass it explicitly:" >&2
|
||||||
echo " scripts/run_examples.sh /path/to/fun" >&2
|
echo " FUN_BIN=/path/to/fun scripts/run_examples.sh [examples-subdir]" >&2
|
||||||
echo "or set FUN_BIN=/path/to/fun" >&2
|
echo "or: scripts/run_examples.sh /path/to/fun" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
@ -55,15 +62,26 @@ if [[ -z "${FUN_LIB_DIR:-}" ]]; then
|
||||||
export FUN_LIB_DIR="$ROOT/lib"
|
export FUN_LIB_DIR="$ROOT/lib"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure error bucket exists
|
# Do not auto-move failing examples; keep user's workspace unchanged
|
||||||
mkdir -p "$EX_DIR/error"
|
|
||||||
|
# Determine target examples directory (optionally restricted to a subdir)
|
||||||
|
TARGET_DIR="$EX_DIR"
|
||||||
|
if [[ -n "${SUBDIR}" ]]; then
|
||||||
|
if [[ -d "$EX_DIR/$SUBDIR" ]]; then
|
||||||
|
TARGET_DIR="$EX_DIR/$SUBDIR"
|
||||||
|
else
|
||||||
|
echo "error: examples subdirectory not found: $SUBDIR" >&2
|
||||||
|
echo " expected at: $EX_DIR/$SUBDIR" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
files=("$EX_DIR"/*.fun)
|
files=("$TARGET_DIR"/*.fun)
|
||||||
shopt -u nullglob
|
shopt -u nullglob
|
||||||
|
|
||||||
if (( ${#files[@]} == 0 )); then
|
if (( ${#files[@]} == 0 )); then
|
||||||
echo "No .fun example files found in $EX_DIR"
|
echo "No .fun example files found in $TARGET_DIR"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -80,13 +98,7 @@ for f in "${files[@]}"; do
|
||||||
echo "=== Running: ${f#$ROOT/} ==="
|
echo "=== Running: ${f#$ROOT/} ==="
|
||||||
if ! "$BIN" "$f"; then
|
if ! "$BIN" "$f"; then
|
||||||
echo "FAILED: ${f#$ROOT/}"
|
echo "FAILED: ${f#$ROOT/}"
|
||||||
dest="$EX_DIR/error/$base_name"
|
# Intentionally do not move files on failure; leave control to the user
|
||||||
# Move the failing example to the error folder
|
|
||||||
if mv -f "$f" "$dest"; then
|
|
||||||
echo "Moved to: examples/error/$base_name"
|
|
||||||
else
|
|
||||||
echo "warning: failed to move $base_name to examples/error/" >&2
|
|
||||||
fi
|
|
||||||
rc=1
|
rc=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue