From 0e139cfbc710156bc4b4b3c254c7b2ff2f10ff34 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 15 Jan 2024 14:29:10 +0100 Subject: [PATCH] build: add a gen-scanner-test target This adds a command to re-generate the test data. This needs to be done when either an XML source file or the scanner's output is changed. Signed-off-by: Simon Ser --- tests/data/README.md | 3 +++ tests/meson.build | 20 ++++++++++++++------ tests/scanner-test-gen.sh | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 tests/data/README.md create mode 100755 tests/scanner-test-gen.sh diff --git a/tests/data/README.md b/tests/data/README.md new file mode 100644 index 00000000..14813453 --- /dev/null +++ b/tests/data/README.md @@ -0,0 +1,3 @@ +To re-generate the test data, run: + + ninja -C build/ gen-scanner-test diff --git a/tests/meson.build b/tests/meson.build index 6cdd2b4a..236f08c0 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -75,15 +75,23 @@ endif sed_path = find_program('sed').full_path() if get_option('scanner') + scanner_test_env = [ + 'TEST_DATA_DIR=@0@/data'.format(meson.current_source_dir()), + 'TEST_OUTPUT_DIR=@0@/output'.format(meson.current_build_dir()), + 'SED=@0@'.format(sed_path), + 'WAYLAND_SCANNER=@0@'.format(wayland_scanner.full_path()), + ] + test( 'scanner-test', find_program('scanner-test.sh'), - env: [ - 'TEST_DATA_DIR=@0@/data'.format(meson.current_source_dir()), - 'TEST_OUTPUT_DIR=@0@/output'.format(meson.current_build_dir()), - 'SED=@0@'.format(sed_path), - 'WAYLAND_SCANNER=@0@'.format(wayland_scanner.full_path()), - ], + env: scanner_test_env, + ) + + run_target( + 'gen-scanner-test', + command: find_program('scanner-test-gen.sh'), + env: scanner_test_env, ) endif diff --git a/tests/scanner-test-gen.sh b/tests/scanner-test-gen.sh new file mode 100755 index 00000000..5af1a727 --- /dev/null +++ b/tests/scanner-test-gen.sh @@ -0,0 +1,21 @@ +#!/bin/sh -eu + +generate() { + "$WAYLAND_SCANNER" $1 < "$TEST_DATA_DIR/$2" > "$TEST_DATA_DIR/$3" + "$SED" -i -e 's/Generated by wayland-scanner [0-9.]*/SCANNER TEST/' \ + "$TEST_DATA_DIR/$3" +} + +generate "code" "example.xml" "example-code.c" +generate "client-header" "example.xml" "example-client.h" +generate "server-header" "example.xml" "example-server.h" + +generate "code" "small.xml" "small-code.c" +generate "client-header" "small.xml" "small-client.h" +generate "server-header" "small.xml" "small-server.h" + +generate "-c code" "small.xml" "small-code-core.c" +generate "-c client-header" "small.xml" "small-client-core.h" +generate "-c server-header" "small.xml" "small-server-core.h" + +generate "private-code" "small.xml" "small-private-code.c"