From 655eb672d6ed03b51f0fae3ab65815fd12b2bb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 12 Jan 2024 14:48:11 +0100 Subject: [PATCH] tools/toolbox: Add `meson test` convenience wrapper It can be fairly tedious to enter a toolbox and invoke `meson test` with the right build directory, so add a companion script to the existing meson-build.sh to handle that. Part-of: --- tools/toolbox/README.md | 8 +++ tools/toolbox/meson-test.sh | 108 ++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100755 tools/toolbox/meson-test.sh diff --git a/tools/toolbox/README.md b/tools/toolbox/README.md index 056bb63e4..3f1ff5c79 100644 --- a/tools/toolbox/README.md +++ b/tools/toolbox/README.md @@ -31,6 +31,14 @@ the project. Run the script with `--help` to see available options. +## meson-test.sh +Run a meson project's test suite in a toolbox. + +The script wraps meson's `test` command to make invoking it inside a +toolbox more convenient. + +Run the script with `--help` to see available options. + ## run-gnome-shell.sh Run gnome-shell from a toolbox. diff --git a/tools/toolbox/meson-test.sh b/tools/toolbox/meson-test.sh new file mode 100755 index 000000000..72631c25b --- /dev/null +++ b/tools/toolbox/meson-test.sh @@ -0,0 +1,108 @@ +#!/bin/bash + +set -e + +DEFAULT_TOOLBOX=gnome-shell-devel +CONFIG_FILE=${XDG_CONFIG_HOME:-$HOME/.config}/gnome-shell-toolbox-tools.conf + +usage() { + cat <<-EOF + Usage: $(basename $0) [OPTION…] + + Run meson project tests in a toolbox + + Options: + -t, --toolbox=TOOLBOX Use TOOLBOX instead of the default "$DEFAULT_TOOLBOX" + + --gdb Run test under gdb + --wrapper=WRAPPER Wrapper to run tests with (e.g. valgrind) + + --list List available tests + + --suite=SUITE Only run tests belonging to the given suite + --no-suite=SUITE Do not run tests belonging to the given suite + + --setup=SETUP Which test setup to use + --test-args=TEST_ARGS Arguments to pass to the specified test(s) or all tests + + -v, --verbose Do not redirect stdout and stderr + -q, --quiet Produce less output to the terminal + + -h, --help Display this help + + EOF +} + +die() { + echo "$@" >&2 + exit 1 +} + +find_toplevel() { + while true; do + grep -qs '\' meson.build && break + [[ $(pwd) -ef / ]] && die "Error: No meson toplevel found" + cd .. + done +} + +# load defaults +. $CONFIG_FILE +TOOLBOX=$DEFAULT_TOOLBOX + +TEMP=$(getopt \ + --name $(basename $0) \ + --options 't:vqh' \ + --longoptions 'toolbox:' \ + --longoptions 'gdb' \ + --longoptions 'wrapper:' \ + --longoptions 'list' \ + --longoptions 'suite:' \ + --longoptions 'no-suite:' \ + --longoptions 'setup:' \ + --longoptions 'test-args:' \ + --longoptions 'verbose' \ + --longoptions 'quiet' \ + --longoptions 'help' \ + -- "$@") || die "Run $(basename $0) --help to see available options" + +eval set -- "$TEMP" +unset TEMP + +MESON_ARGS=() + +while true; do + case $1 in + -t|--toolbox) + TOOLBOX=$2 + shift 2 + ;; + + --list|--gdb|-v|--verbose|-q|--quiet) + MESON_ARGS+=($1) + shift + ;; + + --wrapper|--suite|--no-suite|--setup|--test-args) + MESON_ARGS+=($1 $2) + shift 2 + ;; + + -h|--help) + usage + exit 0 + ;; + + --) + shift + break + ;; + esac +done + +find_toplevel + +BUILD_DIR=build-$TOOLBOX + +toolbox run --container $TOOLBOX \ + meson test -C $BUILD_DIR ${MESON_ARGS[*]} $@