run_tests.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. # libspelling + libpanel (platform GNOME libraries) are optional.
  28. if pkg-config --exists libspelling-1 libpanel-1 2>/dev/null; then
  29. CFLAGS="$CFLAGS $(pkg-config --cflags libspelling-1 libpanel-1)"
  30. LIBS="$LIBS $(pkg-config --libs libspelling-1 libpanel-1)"
  31. TESTS="$TESTS test_platform"
  32. fi
  33. # OpenGL (GtkGLArea examples/tests).
  34. if pkg-config --exists gl 2>/dev/null; then
  35. LIBS="$LIBS $(pkg-config --libs gl)"
  36. fi
  37. mkdir -p "$BIN" "$OBJ"
  38. # pure-Modula-2 helper must be compiled with -c first (no main), then
  39. # linked in; passing the .mod directly would add a second main.
  40. # shellcheck disable=SC2086
  41. $GM2 -I"$ROOT/src" -I"$ROOT/lib" $GM2FLAGS -c "$ROOT/lib/GtkUtils.mod" -o "$OBJ/GtkUtils.o"
  42. # shellcheck disable=SC2086
  43. $GM2 -I"$ROOT/src" -I"$ROOT/lib" $GM2FLAGS -c "$ROOT/lib/GtkClosures.mod" -o "$OBJ/GtkClosures.o"
  44. # C shim for GObject subclassing (compiled with the C compiler).
  45. ${CC:-cc} $CFLAGS -c "$ROOT/lib/m2gtkshim.c" -o "$OBJ/m2gtkshim.o"
  46. # the m2 gtk-demo registry (demos/) is compiled once and linked into test_demos.
  47. if [ -d "$ROOT/demos" ]; then
  48. # shellcheck disable=SC2086
  49. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemoCatalog.mod" -o "$OBJ/DemoCatalog.o"
  50. # shellcheck disable=SC2086
  51. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemoImpl.mod" -o "$OBJ/DemoImpl.o"
  52. # shellcheck disable=SC2086
  53. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemosBasic.mod" -o "$OBJ/DemosBasic.o"
  54. # shellcheck disable=SC2086
  55. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemosLayout.mod" -o "$OBJ/DemosLayout.o"
  56. # shellcheck disable=SC2086
  57. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemosText.mod" -o "$OBJ/DemosText.o"
  58. # shellcheck disable=SC2086
  59. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemosWindows.mod" -o "$OBJ/DemosWindows.o"
  60. # shellcheck disable=SC2086
  61. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemosInput.mod" -o "$OBJ/DemosInput.o"
  62. # shellcheck disable=SC2086
  63. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemosChooser.mod" -o "$OBJ/DemosChooser.o"
  64. # shellcheck disable=SC2086
  65. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemosCanvas.mod" -o "$OBJ/DemosCanvas.o"
  66. # shellcheck disable=SC2086
  67. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/GtkDemo.mod" -o "$OBJ/GtkDemo.o"
  68. fi
  69. # compile the test-only GSettings schema and make it discoverable
  70. SCHEMA_SRC="$ROOT/tests/schemas"
  71. SCHEMA_BLD="$ROOT/build/schemas"
  72. mkdir -p "$SCHEMA_BLD"
  73. cp "$SCHEMA_SRC"/*.gschema.xml "$SCHEMA_BLD"/ 2>/dev/null || true
  74. glib-compile-schemas "$SCHEMA_BLD" 2>/dev/null || true
  75. GSETTINGS_SCHEMA_DIR="$SCHEMA_BLD"
  76. export GSETTINGS_SCHEMA_DIR
  77. pass=0; fail=0; skip=0
  78. for t in $TESTS; do
  79. echo "== $t =="
  80. DEMO_OBJS=""
  81. case "$t" in test_demos) DEMO_OBJS="$OBJ/DemoCatalog.o $OBJ/DemoImpl.o $OBJ/DemosBasic.o $OBJ/DemosLayout.o $OBJ/DemosText.o $OBJ/DemosWindows.o $OBJ/DemosInput.o $OBJ/DemosChooser.o $OBJ/DemosCanvas.o $OBJ/GtkDemo.o" ;; esac
  82. # shellcheck disable=SC2086
  83. $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS $CFLAGS \
  84. "$ROOT/tests/$t.mod" "$OBJ/GtkUtils.o" "$OBJ/GtkClosures.o" \
  85. "$OBJ/m2gtkshim.o" $DEMO_OBJS -o "$BIN/$t" $LIBS
  86. case "$t" in
  87. 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|test_platform) needs_display=1 ;;
  88. *) needs_display=0 ;;
  89. esac
  90. if [ "$needs_display" = 1 ] && [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
  91. echo " (skipped: no display)"
  92. skip=$((skip+1))
  93. continue
  94. fi
  95. if "$BIN/$t"; then
  96. pass=$((pass+1))
  97. else
  98. fail=$((fail+1))
  99. fi
  100. done
  101. echo "OK: $pass passed, $skip skipped, $fail failed"
  102. [ "$fail" -eq 0 ]