#!/bin/sh # m2-GTK4 test runner - builds each tests/*.mod with gm2 and runs it. # Usage: ./tests/run_tests.sh # GUI tests are skipped automatically when no display is available. set -e CDIR=$(dirname "$0") ROOT=$(cd "$CDIR/.." && pwd) BIN="$ROOT/build/tests" OBJ="$ROOT/build/objs" GM2="${GM2:-gm2}" GM2FLAGS="${GM2FLAGS:--fiso}" CFLAGS=$(pkg-config --cflags gtk4) LIBS=$(pkg-config --libs gtk4) # libadwaita is optional: add its flags and test when available. 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" if pkg-config --exists libadwaita-1 2>/dev/null; then CFLAGS="$CFLAGS $(pkg-config --cflags libadwaita-1)" LIBS="$LIBS $(pkg-config --libs libadwaita-1)" TESTS="$TESTS test_adw test_adw_widgets test_adw_widgets2" fi # GtkSourceView 5 (GtkSource) is optional. if pkg-config --exists gtksourceview-5 2>/dev/null; then CFLAGS="$CFLAGS $(pkg-config --cflags gtksourceview-5)" LIBS="$LIBS $(pkg-config --libs gtksourceview-5)" TESTS="$TESTS test_sourceview" fi # libspelling + libpanel (platform GNOME libraries) are optional. if pkg-config --exists libspelling-1 libpanel-1 2>/dev/null; then CFLAGS="$CFLAGS $(pkg-config --cflags libspelling-1 libpanel-1)" LIBS="$LIBS $(pkg-config --libs libspelling-1 libpanel-1)" TESTS="$TESTS test_platform" fi # OpenGL (GtkGLArea examples/tests). if pkg-config --exists gl 2>/dev/null; then LIBS="$LIBS $(pkg-config --libs gl)" fi mkdir -p "$BIN" "$OBJ" # pure-Modula-2 helper must be compiled with -c first (no main), then # linked in; passing the .mod directly would add a second main. # shellcheck disable=SC2086 $GM2 -I"$ROOT/src" -I"$ROOT/lib" $GM2FLAGS -c "$ROOT/lib/GtkUtils.mod" -o "$OBJ/GtkUtils.o" # shellcheck disable=SC2086 $GM2 -I"$ROOT/src" -I"$ROOT/lib" $GM2FLAGS -c "$ROOT/lib/GtkClosures.mod" -o "$OBJ/GtkClosures.o" # C shim for GObject subclassing (compiled with the C compiler). ${CC:-cc} $CFLAGS -c "$ROOT/lib/m2gtkshim.c" -o "$OBJ/m2gtkshim.o" # the m2 gtk-demo registry (demos/) is compiled once and linked into test_demos. if [ -d "$ROOT/demos" ]; then # shellcheck disable=SC2086 $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemoCatalog.mod" -o "$OBJ/DemoCatalog.o" # shellcheck disable=SC2086 $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemoImpl.mod" -o "$OBJ/DemoImpl.o" # shellcheck disable=SC2086 $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/DemosBasic.mod" -o "$OBJ/DemosBasic.o" # shellcheck disable=SC2086 $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS -c "$ROOT/demos/GtkDemo.mod" -o "$OBJ/GtkDemo.o" fi # compile the test-only GSettings schema and make it discoverable SCHEMA_SRC="$ROOT/tests/schemas" SCHEMA_BLD="$ROOT/build/schemas" mkdir -p "$SCHEMA_BLD" cp "$SCHEMA_SRC"/*.gschema.xml "$SCHEMA_BLD"/ 2>/dev/null || true glib-compile-schemas "$SCHEMA_BLD" 2>/dev/null || true GSETTINGS_SCHEMA_DIR="$SCHEMA_BLD" export GSETTINGS_SCHEMA_DIR pass=0; fail=0; skip=0 for t in $TESTS; do echo "== $t ==" DEMO_OBJS="" case "$t" in test_demos) DEMO_OBJS="$OBJ/DemoCatalog.o $OBJ/DemoImpl.o $OBJ/DemosBasic.o $OBJ/GtkDemo.o" ;; esac # shellcheck disable=SC2086 $GM2 -I"$ROOT/src" -I"$ROOT/lib" -I"$ROOT/demos" $GM2FLAGS $CFLAGS \ "$ROOT/tests/$t.mod" "$OBJ/GtkUtils.o" "$OBJ/GtkClosures.o" \ "$OBJ/m2gtkshim.o" $DEMO_OBJS -o "$BIN/$t" $LIBS case "$t" in 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 ;; *) needs_display=0 ;; esac if [ "$needs_display" = 1 ] && [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then echo " (skipped: no display)" skip=$((skip+1)) continue fi if "$BIN/$t"; then pass=$((pass+1)) else fail=$((fail+1)) fi done echo "OK: $pass passed, $skip skipped, $fail failed" [ "$fail" -eq 0 ]