From c6aef6f29015ec466376798fff8423097f1cb970 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 14 Jan 2026 04:53:09 +0100 Subject: [PATCH] Refactoring. (0.37.51) --- CMakeLists.txt | 2 +- examples/{ => extra}/curl_download.fun | 0 examples/{ => extra}/ini_class_demo.fun | 0 examples/{ => extra}/ini_complex.fun | 0 examples/{ => extra}/ini_demo.fun | 0 examples/{ => extra}/ini_diag.fun | 0 examples/{ => extra}/ini_subsections.fun | 0 examples/{ => extra}/libsql_example.fun | 0 examples/{ => extra}/sqlite_example.fun | 0 examples/{ => extra}/tk_file_manager.fun | 0 examples/{ => extra}/tk_hello.fun | 0 examples/{ => extra}/tk_testing.fun | 0 examples/{ => extra}/xml_access_catalog.fun | 0 examples/{ => extra}/xml_access_employees.fun | 0 examples/{ => extra}/xml_access_ns.fun | 0 examples/{ => extra}/xml_class_example.fun | 0 examples/{ => extra}/xml_minimal.fun | 0 .../interactive/input_hidden_pam_auth.fun | 3 ++ scripts/run_examples.sh | 42 ++++++++++++------- 19 files changed, 31 insertions(+), 16 deletions(-) rename examples/{ => extra}/curl_download.fun (100%) rename examples/{ => extra}/ini_class_demo.fun (100%) rename examples/{ => extra}/ini_complex.fun (100%) rename examples/{ => extra}/ini_demo.fun (100%) rename examples/{ => extra}/ini_diag.fun (100%) rename examples/{ => extra}/ini_subsections.fun (100%) rename examples/{ => extra}/libsql_example.fun (100%) rename examples/{ => extra}/sqlite_example.fun (100%) rename examples/{ => extra}/tk_file_manager.fun (100%) rename examples/{ => extra}/tk_hello.fun (100%) rename examples/{ => extra}/tk_testing.fun (100%) rename examples/{ => extra}/xml_access_catalog.fun (100%) rename examples/{ => extra}/xml_access_employees.fun (100%) rename examples/{ => extra}/xml_access_ns.fun (100%) rename examples/{ => extra}/xml_class_example.fun (100%) rename examples/{ => extra}/xml_minimal.fun (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index de66e88..784a121 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ 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_REQUIRED ON) diff --git a/examples/curl_download.fun b/examples/extra/curl_download.fun similarity index 100% rename from examples/curl_download.fun rename to examples/extra/curl_download.fun diff --git a/examples/ini_class_demo.fun b/examples/extra/ini_class_demo.fun similarity index 100% rename from examples/ini_class_demo.fun rename to examples/extra/ini_class_demo.fun diff --git a/examples/ini_complex.fun b/examples/extra/ini_complex.fun similarity index 100% rename from examples/ini_complex.fun rename to examples/extra/ini_complex.fun diff --git a/examples/ini_demo.fun b/examples/extra/ini_demo.fun similarity index 100% rename from examples/ini_demo.fun rename to examples/extra/ini_demo.fun diff --git a/examples/ini_diag.fun b/examples/extra/ini_diag.fun similarity index 100% rename from examples/ini_diag.fun rename to examples/extra/ini_diag.fun diff --git a/examples/ini_subsections.fun b/examples/extra/ini_subsections.fun similarity index 100% rename from examples/ini_subsections.fun rename to examples/extra/ini_subsections.fun diff --git a/examples/libsql_example.fun b/examples/extra/libsql_example.fun similarity index 100% rename from examples/libsql_example.fun rename to examples/extra/libsql_example.fun diff --git a/examples/sqlite_example.fun b/examples/extra/sqlite_example.fun similarity index 100% rename from examples/sqlite_example.fun rename to examples/extra/sqlite_example.fun diff --git a/examples/tk_file_manager.fun b/examples/extra/tk_file_manager.fun similarity index 100% rename from examples/tk_file_manager.fun rename to examples/extra/tk_file_manager.fun diff --git a/examples/tk_hello.fun b/examples/extra/tk_hello.fun similarity index 100% rename from examples/tk_hello.fun rename to examples/extra/tk_hello.fun diff --git a/examples/tk_testing.fun b/examples/extra/tk_testing.fun similarity index 100% rename from examples/tk_testing.fun rename to examples/extra/tk_testing.fun diff --git a/examples/xml_access_catalog.fun b/examples/extra/xml_access_catalog.fun similarity index 100% rename from examples/xml_access_catalog.fun rename to examples/extra/xml_access_catalog.fun diff --git a/examples/xml_access_employees.fun b/examples/extra/xml_access_employees.fun similarity index 100% rename from examples/xml_access_employees.fun rename to examples/extra/xml_access_employees.fun diff --git a/examples/xml_access_ns.fun b/examples/extra/xml_access_ns.fun similarity index 100% rename from examples/xml_access_ns.fun rename to examples/extra/xml_access_ns.fun diff --git a/examples/xml_class_example.fun b/examples/extra/xml_class_example.fun similarity index 100% rename from examples/xml_class_example.fun rename to examples/extra/xml_class_example.fun diff --git a/examples/xml_minimal.fun b/examples/extra/xml_minimal.fun similarity index 100% rename from examples/xml_minimal.fun rename to examples/extra/xml_minimal.fun diff --git a/examples/interactive/input_hidden_pam_auth.fun b/examples/interactive/input_hidden_pam_auth.fun index 56d5fb7..e1138dd 100755 --- a/examples/interactive/input_hidden_pam_auth.fun +++ b/examples/interactive/input_hidden_pam_auth.fun @@ -29,6 +29,9 @@ if (res["code"] == 0) else print("Login failed!") +// Propagate the child process exit status to the Fun program's exit code +exit res["code"] + /* Possible output: Username: hanez Password: diff --git a/scripts/run_examples.sh b/scripts/run_examples.sh index 1690cd7..183fdba 100755 --- a/scripts/run_examples.sh +++ b/scripts/run_examples.sh @@ -11,8 +11,9 @@ set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" EX_DIR="$ROOT/examples" -# Allow override via first arg or FUN_BIN env -BIN="${1:-${FUN_BIN:-}}" +# Optional overrides via FUN_BIN env. First positional arg may now be an examples subdirectory. +BIN="${FUN_BIN:-}" +SUBDIR="${1:-}" pick_bin() { local cands=( @@ -36,11 +37,17 @@ pick_bin() { 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 ! BIN="$(pick_bin)"; then 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 "or set FUN_BIN=/path/to/fun" >&2 + echo " FUN_BIN=/path/to/fun scripts/run_examples.sh [examples-subdir]" >&2 + echo "or: scripts/run_examples.sh /path/to/fun" >&2 exit 2 fi fi @@ -55,15 +62,26 @@ if [[ -z "${FUN_LIB_DIR:-}" ]]; then export FUN_LIB_DIR="$ROOT/lib" fi -# Ensure error bucket exists -mkdir -p "$EX_DIR/error" +# Do not auto-move failing examples; keep user's workspace unchanged + +# 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 -files=("$EX_DIR"/*.fun) +files=("$TARGET_DIR"/*.fun) shopt -u nullglob if (( ${#files[@]} == 0 )); then - echo "No .fun example files found in $EX_DIR" + echo "No .fun example files found in $TARGET_DIR" exit 0 fi @@ -80,13 +98,7 @@ for f in "${files[@]}"; do echo "=== Running: ${f#$ROOT/} ===" if ! "$BIN" "$f"; then echo "FAILED: ${f#$ROOT/}" - dest="$EX_DIR/error/$base_name" - # 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 + # Intentionally do not move files on failure; leave control to the user rc=1 fi done