run_tests.sh 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_css test_popover test_dialogs test_models test_cairo test_drawing test_gestures test_models2 test_widgets3 test_shim test_shim2 test_shim3 test_dnd test_media test_gl test_print test_text test_expr test_constraints test_shortcuts test_snapshot test_lastwidgets test_application test_demos"
  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 test_adw_widgets test_adw_widgets2"
  20. fi
  21. # GtkSourceView 5 (GtkSource) is optional.
  22. if pkg-config --exists gtksourceview-5 2>/dev/null; then
  23. CFLAGS="$CFLAGS $(pkg-config --cflags gtksourceview-5)"
  24. LIBS="$LIBS $(pkg-config --libs gtksourceview-5)"
  25. TESTS="$TESTS test_sourceview"
  26. fi
  27. # OpenGL (GtkGLArea examples/tests).
  28. if pkg-config --exists gl 2>/dev/null; then
  29. LIBS="$LIBS $(pkg-config --libs gl)"
  30. fi
  31. mkdir -p "$BIN" "$OBJ"
  32. # pure-Modula-2 helper must be compiled with -c first (no main), then
  33. # linked in; passing the .mod directly would add a second main.
  34. # shellcheck disable=SC2086
  35. $GM2 -I"$ROOT/src" -I"$ROOT/lib" $GM2FLAGS -c "$ROOT/lib/GtkUtils.mod" -o "$OBJ/GtkUtils.o"
  36. # shellcheck disable=SC2086
  37. $GM2 -I"$ROOT/src" -I"$ROOT/lib" $GM2FLAGS -c "$ROOT/lib/GtkClosures.mod" -o "$OBJ/GtkClosures.o"
  38. # C shim for GObject subclassing (compiled with the C compiler).
  39. ${CC:-cc} $CFLAGS -c "$ROOT/lib/m2gtkshim.c" -o "$OBJ/m2gtkshim.o"
  40. # the m2 gtk-demo registry (demos/) is compiled once and linked into test_demos.
  41. if [ -d "$ROOT/demos" ]; then
  42. # shellcheck disable=SC2086
  43. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemoImpl.mod" -o "$OBJ/DemoImpl.o"
  44. # shellcheck disable=SC2086
  45. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/GtkDemo.mod" -o "$OBJ/GtkDemo.o"
  46. fi
  47. # compile the test-only GSettings schema and make it discoverable
  48. SCHEMA_SRC="$ROOT/tests/schemas"
  49. SCHEMA_BLD="$ROOT/build/schemas"
  50. mkdir -p "$SCHEMA_BLD"
  51. cp "$SCHEMA_SRC"/*.gschema.xml "$SCHEMA_BLD"/ 2>/dev/null || true
  52. glib-compile-schemas "$SCHEMA_BLD" 2>/dev/null || true
  53. GSETTINGS_SCHEMA_DIR="$SCHEMA_BLD"
  54. export GSETTINGS_SCHEMA_DIR
  55. pass=0; fail=0; skip=0
  56. for t in $TESTS; do
  57. echo "== $t =="
  58. DEMO_OBJS=""
  59. case "$t" in test_demos) DEMO_OBJS="$OBJ/DemoImpl.o $OBJ/GtkDemo.o" ;; esac
  60. # shellcheck disable=SC2086
  61. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS $CFLAGS \
  62. "$ROOT/tests/$t.mod" "$OBJ/GtkUtils.o" "$OBJ/GtkClosures.o" \
  63. "$OBJ/m2gtkshim.o" $DEMO_OBJS -o "$BIN/$t" $LIBS
  64. case "$t" in
  65. 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_css|test_popover|test_dialogs|test_models|test_drawing|test_gestures|test_models2|test_widgets3|test_shim|test_shim2|test_shim3|test_dnd|test_media|test_gl|test_print|test_text|test_expr|test_constraints|test_shortcuts|test_snapshot|test_lastwidgets|test_adw|test_application|test_demos|test_adw_widgets|test_adw_widgets2|test_sourceview) needs_display=1 ;;
  66. *) needs_display=0 ;;
  67. esac
  68. if [ "$needs_display" = 1 ] && [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
  69. echo " (skipped: no display)"
  70. skip=$((skip+1))
  71. continue
  72. fi
  73. if "$BIN/$t"; then
  74. pass=$((pass+1))
  75. else
  76. fail=$((fail+1))
  77. fi
  78. done
  79. echo "OK: $pass passed, $skip skipped, $fail failed"
  80. [ "$fail" -eq 0 ]