run_tests.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. # m2-GTK4 test runner - builds each tests/*.mod with gm2 and runs it.
  3. # Usage: ./tests/run_tests.sh
  4. # GUI tests are skipped automatically when no display is available.
  5. set -e
  6. CDIR=$(dirname "$0")
  7. ROOT=$(cd "$CDIR/.." && pwd)
  8. BIN="$ROOT/build/tests"
  9. OBJ="$ROOT/build/objs"
  10. GM2="${GM2:-gm2}"
  11. GM2FLAGS="${GM2FLAGS:--fiso}"
  12. CFLAGS=$(pkg-config --cflags gtk4)
  13. LIBS=$(pkg-config --libs gtk4)
  14. # libadwaita is optional: add its flags and test when available.
  15. TESTS="test_glib test_version test_widgets test_inputs test_inputs2 test_containers test_containers2 test_actions test_closure test_headerbar test_gio test_gerror test_filedialog test_views test_builder test_utility test_application"
  16. if pkg-config --exists libadwaita-1 2>/dev/null; then
  17. CFLAGS="$CFLAGS $(pkg-config --cflags libadwaita-1)"
  18. LIBS="$LIBS $(pkg-config --libs libadwaita-1)"
  19. TESTS="$TESTS test_adw"
  20. fi
  21. mkdir -p "$BIN" "$OBJ"
  22. # pure-Modula-2 helper must be compiled with -c first (no main), then
  23. # linked in; passing the .mod directly would add a second main.
  24. # shellcheck disable=SC2086
  25. $GM2 -I"$ROOT/src" -I"$ROOT/lib" $GM2FLAGS -c "$ROOT/lib/GtkUtils.mod" -o "$OBJ/GtkUtils.o"
  26. # shellcheck disable=SC2086
  27. $GM2 -I"$ROOT/src" -I"$ROOT/lib" $GM2FLAGS -c "$ROOT/lib/GtkClosures.mod" -o "$OBJ/GtkClosures.o"
  28. # compile the test-only GSettings schema and make it discoverable
  29. SCHEMA_SRC="$ROOT/tests/schemas"
  30. SCHEMA_BLD="$ROOT/build/schemas"
  31. mkdir -p "$SCHEMA_BLD"
  32. cp "$SCHEMA_SRC"/*.gschema.xml "$SCHEMA_BLD"/ 2>/dev/null || true
  33. glib-compile-schemas "$SCHEMA_BLD" 2>/dev/null || true
  34. GSETTINGS_SCHEMA_DIR="$SCHEMA_BLD"
  35. export GSETTINGS_SCHEMA_DIR
  36. pass=0; fail=0; skip=0
  37. for t in $TESTS; do
  38. echo "== $t =="
  39. # shellcheck disable=SC2086
  40. $GM2 -I"$ROOT/src" -I"$ROOT/lib" $GM2FLAGS $CFLAGS \
  41. "$ROOT/tests/$t.mod" "$OBJ/GtkUtils.o" "$OBJ/GtkClosures.o" -o "$BIN/$t" $LIBS
  42. case "$t" in
  43. test_widgets|test_inputs|test_inputs2|test_containers|test_containers2|test_actions|test_closure|test_headerbar|test_filedialog|test_views|test_builder|test_utility|test_adw|test_application) needs_display=1 ;;
  44. *) needs_display=0 ;;
  45. esac
  46. if [ "$needs_display" = 1 ] && [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
  47. echo " (skipped: no display)"
  48. skip=$((skip+1))
  49. continue
  50. fi
  51. if "$BIN/$t"; then
  52. pass=$((pass+1))
  53. else
  54. fail=$((fail+1))
  55. fi
  56. done
  57. echo "OK: $pass passed, $skip skipped, $fail failed"
  58. [ "$fail" -eq 0 ]