From b29d997d53b79bed0ebdf5d651b8624688f92f79 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 14 Sep 2026 23:29:27 +0100 Subject: [PATCH] tests: Use "no plan" style of TAP output Similar to https://github.com/flatpak/flatpak/commit/b1fdf6c4ef9d10b90a5d1004963f9c13606e2c15 this makes it more obvious where the boundary between test-cases is, and similar to https://github.com/flatpak/flatpak/pull/6794 it avoids needing to declare up-front how many tests we plan to run (which makes conflicts inevitable if we add more than one test to the same script). Signed-off-by: Simon McVittie --- tests/libtest.sh | 17 ++++++++++ tests/test-appstream.sh | 14 ++++---- tests/test-builder-cleanup.sh | 22 ++++++------- tests/test-builder-deprecated.sh | 20 +++++------ tests/test-builder-licence-paths.sh | 12 +++---- tests/test-builder-locale-migration.sh | 12 +++---- tests/test-builder-python.sh | 8 ++--- tests/test-builder.sh | 18 +++++----- .../test-sandboxed-mode-source-resolution.sh | 33 +++++++++---------- 9 files changed, 86 insertions(+), 70 deletions(-) diff --git a/tests/libtest.sh b/tests/libtest.sh index 2b1d34d3..1fa46e8d 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -95,6 +95,23 @@ export U="--user" export FLATPAK="${CMD_PREFIX} flatpak" export FLATPAK_BUILDER="${CMD_PREFIX} flatpak-builder" +test_number=0 + +ok () { + { { local BASH_XTRACEFD=3; } 2> /dev/null + test_number=$(( test_number + 1 )) + echo "ok $test_number - $*"; + echo "================ $(basename ${BASH_SOURCE[1]}):${BASH_LINENO[0]} - $@ ================" >&2; + } 3> /dev/null +} + +done_testing () { + { { local BASH_XTRACEFD=3; } 2> /dev/null + echo "1..$test_number" + echo "# Done testing" + } 3> /dev/null +} + assert_streq () { test "$1" = "$2" || (echo 1>&2 "$1 != $2"; exit 1) } diff --git a/tests/test-appstream.sh b/tests/test-appstream.sh index fed1f937..cd36a2dc 100755 --- a/tests/test-appstream.sh +++ b/tests/test-appstream.sh @@ -23,8 +23,6 @@ set -euo pipefail skip_without_fuse -echo "1..3" - setup_repo install_repo setup_sdk_repo @@ -50,7 +48,7 @@ gzip -cdq builddir_sc/files/share/app-info/xmls/org.flatpak.appstream_media.xml. > appstream.xml assert_file_has_content_extended appstream.xml '>org/flatpak/appstream_media/[^/]+/icons/128x128/org.flatpak.appstream_media.png' -echo "ok compose partial url policy" +ok "compose partial url policy" # test compose full url policy if appstream_has_version 0 16 3; then @@ -65,9 +63,9 @@ if appstream_has_version 0 16 3; then > appstream.xml assert_file_has_content_extended appstream.xml '>https://example.org/media/org/flatpak/appstream_media/[^/]+/icons/128x128/org.flatpak.appstream_media.png' - echo "ok compose full url policy" + ok "compose full url policy" else - echo "ok # Skip AppStream < 0.16.3" + ok "# Skip AppStream < 0.16.3" fi # test compose jxl image format @@ -84,7 +82,9 @@ if appstream_has_version 1 2 0; then > appstream.xml assert_file_has_content_extended appstream.xml '>https://example.org/media/org/flatpak/appstream_media/[^/]+/icons/128x128/org.flatpak.appstream_media.jxl' - echo "ok compose jxl image format" + ok "compose jxl image format" else - echo "ok # Skip AppStream < 1.2.0" + ok "# Skip AppStream < 1.2.0" fi + +done_testing diff --git a/tests/test-builder-cleanup.sh b/tests/test-builder-cleanup.sh index c3828078..92966243 100755 --- a/tests/test-builder-cleanup.sh +++ b/tests/test-builder-cleanup.sh @@ -23,8 +23,6 @@ set -euo pipefail skip_without_fuse -echo "1..9" - setup_repo install_repo setup_sdk_repo @@ -65,7 +63,7 @@ assert_not_has_file appdir/files/share/doc/file1 assert_not_has_file appdir/files/share/doc/file2 assert_not_has_dir appdir/files/share/doc -echo "ok toplevel cleanup applies to all modules" +ok "toplevel cleanup applies to all modules" cat > test-cleanup-module-scope.json <<'EOF' { @@ -99,7 +97,7 @@ run_build test-cleanup-module-scope.json assert_not_has_file appdir/files/share/doc/file1 assert_has_file appdir/files/share/doc/file2 -echo "ok module cleanup does not affect other modules" +ok "module cleanup does not affect other modules" cat > test-cleanup-basename.json <<'EOF' { @@ -124,7 +122,7 @@ run_build test-cleanup-basename.json assert_not_has_file appdir/files/share/a.txt assert_has_file appdir/files/share/b.log -echo "ok basename pattern works" +ok "basename pattern works" cat > test-cleanup-star.json <<'EOF' { @@ -150,7 +148,7 @@ run_build test-cleanup-star.json assert_not_has_file appdir/files/a/file.txt assert_has_file appdir/files/b/file.log -echo "ok wildcard matching works" +ok "wildcard matching works" cat > test-cleanup-module-star-scope.json <<'EOF' { @@ -186,7 +184,7 @@ assert_has_file appdir/files/share/file1.txt assert_not_has_file appdir/files/share/file2.txt assert_has_file appdir/files/share/file2.log -echo "ok wildcard matching works and is scoped to module" +ok "wildcard matching works and is scoped to module" cat > test-cleanup-question.json <<'EOF' { @@ -224,7 +222,7 @@ assert_not_has_file appdir/files/share/a2.txt assert_has_file appdir/files/share/a22.txt assert_not_has_file appdir/files/share/ab.txt -echo "ok '?' matches exactly one char and is module-scoped" +ok "'?' matches exactly one char and is module-scoped" cat > test-cleanup-question-slash.json <<'EOF' { @@ -250,7 +248,7 @@ run_build test-cleanup-question-slash.json assert_not_has_file appdir/files/a1/file.txt assert_has_file appdir/files/a/b/file.txt -echo "ok '?' does not match '/'" +ok "'?' does not match '/'" cat > test-invalid-pattern1.json <<'EOF' { @@ -274,7 +272,7 @@ run_build test-invalid-pattern1.json # share/doc is not a valid pattern, no cleanup should happen assert_has_file appdir/files/share/doc/file -echo "ok invalid pattern 1 did not cleanup" +ok "invalid pattern 1 did not cleanup" cat > test-cleanup-trailing-slash.json <<'EOF' { @@ -298,4 +296,6 @@ run_build test-cleanup-trailing-slash.json assert_not_has_file appdir/files/share/doc/file assert_not_has_dir appdir/files/share/doc -echo "ok trailing slash works" +ok "trailing slash works" + +done_testing diff --git a/tests/test-builder-deprecated.sh b/tests/test-builder-deprecated.sh index 179216d4..e99a04a5 100755 --- a/tests/test-builder-deprecated.sh +++ b/tests/test-builder-deprecated.sh @@ -22,8 +22,6 @@ srcdir=$(dirname "$0") skip_without_fuse -echo "1..8" - setup_repo install_repo setup_sdk_repo @@ -46,46 +44,48 @@ BUILD_LOG=build-error-log run_build org.test.Deprecated.MD5.archive.json assert_file_has_content build-error-log 'The "md5" source property is deprecated due to the weakness of MD5 hashes.' assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.' -echo "ok deprecated MD5 hash for archive in JSON" +ok "deprecated MD5 hash for archive in JSON" BUILD_LOG=build-error-log run_build org.test.Deprecated.MD5.archive.yaml assert_file_has_content build-error-log 'The "md5" source property is deprecated due to the weakness of MD5 hashes.' assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.' -echo "ok deprecated MD5 hash for archive in YAML" +ok "deprecated MD5 hash for archive in YAML" BUILD_LOG=build-error-log run_build org.test.Deprecated.MD5.file.json assert_file_has_content build-error-log 'The "md5" source property is deprecated due to the weakness of MD5 hashes.' assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.' -echo "ok deprecated MD5 hash for file in JSON" +ok "deprecated MD5 hash for file in JSON" BUILD_LOG=build-error-log run_build org.test.Deprecated.MD5.file.yaml assert_file_has_content build-error-log 'The "md5" source property is deprecated due to the weakness of MD5 hashes.' assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.' -echo "ok deprecated MD5 hash for file in YAML" +ok "deprecated MD5 hash for file in YAML" BUILD_LOG=build-error-log run_build org.test.Deprecated.SHA1.archive.json assert_file_has_content build-error-log 'The "sha1" source property is deprecated due to the weakness of SHA1 hashes.' assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.' -echo "ok deprecated SHA1 hash for archive in JSON" +ok "deprecated SHA1 hash for archive in JSON" BUILD_LOG=build-error-log run_build org.test.Deprecated.SHA1.archive.yaml assert_file_has_content build-error-log 'The "sha1" source property is deprecated due to the weakness of SHA1 hashes.' assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.' -echo "ok deprecated SHA1 hash for archive in YAML" +ok "deprecated SHA1 hash for archive in YAML" BUILD_LOG=build-error-log run_build org.test.Deprecated.SHA1.file.json assert_file_has_content build-error-log 'The "sha1" source property is deprecated due to the weakness of SHA1 hashes.' assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.' -echo "ok deprecated SHA1 hash for file in JSON" +ok "deprecated SHA1 hash for file in JSON" BUILD_LOG=build-error-log run_build org.test.Deprecated.SHA1.file.yaml assert_file_has_content build-error-log 'The "sha1" source property is deprecated due to the weakness of SHA1 hashes.' assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.' -echo "ok deprecated SHA1 hash for file in YAML" +ok "deprecated SHA1 hash for file in YAML" + +done_testing diff --git a/tests/test-builder-licence-paths.sh b/tests/test-builder-licence-paths.sh index 37707dbc..9bb8a8dc 100755 --- a/tests/test-builder-licence-paths.sh +++ b/tests/test-builder-licence-paths.sh @@ -23,8 +23,6 @@ set -euo pipefail skip_without_fuse -echo "1..4" - setup_repo install_repo setup_sdk_repo @@ -61,7 +59,7 @@ run_build_fail test-licence_interm_symlink.json assert_not_has_file appdir/files/share/licenses/org.test.licence_interm_symlink/test/environ -echo "ok intermediate path symlink is rejected" +ok "intermediate path symlink is rejected" mkdir -p source_licence_2 ln -s /etc/hostname source_licence_2/LICENSE @@ -90,7 +88,7 @@ run_build_fail test-licence_abs_symlink.json assert_not_has_file appdir/files/share/licenses/org.test.licence_abs_symlink/test/LICENSE -echo "ok absolute path symlink is rejected" +ok "absolute path symlink is rejected" mkdir -p source_licence_3 echo "MY LICENSE TEXT" > source_licence_3/LICENSE @@ -122,7 +120,7 @@ assert_file_has_content \ appdir/files/share/licenses/org.test.licence_working_1/test/LICENSE \ '^MY LICENSE TEXT$' -echo "ok license file is recorded with license-files key" +ok "license file is recorded with license-files key" mkdir -p source_licence_4 echo "MY DEFAULT LICENSE TEXT" > source_licence_4/LICENSE @@ -153,4 +151,6 @@ assert_file_has_content \ appdir/files/share/licenses/org.test.licence_working_2/test/LICENSE \ '^MY DEFAULT LICENSE TEXT$' -echo "ok license file is recorded by default" +ok "license file is recorded by default" + +done_testing diff --git a/tests/test-builder-locale-migration.sh b/tests/test-builder-locale-migration.sh index 6222b4a3..4448ccdb 100755 --- a/tests/test-builder-locale-migration.sh +++ b/tests/test-builder-locale-migration.sh @@ -23,8 +23,6 @@ set -euo pipefail skip_without_fuse -echo "1..4" - setup_repo install_repo setup_sdk_repo @@ -136,7 +134,7 @@ assert_has_dir appdir/files/share/runtime/locale/sv assert_has_file appdir/files/share/locale/plain-file assert_not_has_symlink appdir/files/share/locale/plain-file -echo "ok locale dirs migrated" +ok "locale dirs migrated" cat > test-locale-disabled.json <<'EOF' { @@ -162,7 +160,7 @@ assert_has_file appdir/files/share/locale/de/LC_MESSAGES/test.mo assert_file_has_content appdir/files/share/locale/de/LC_MESSAGES/test.mo 'de translation' assert_not_has_dir appdir/files/share/runtime/locale -echo "ok locale dirs migration is disabled on separate-locales false" +ok "locale dirs migration is disabled on separate-locales false" cat > test-locale-migration-runtime.json <<'EOF' { @@ -194,7 +192,7 @@ assert_has_symlink appdir/usr/lib/locale/cs assert_has_file appdir/usr/share/runtime/locale/cs/lib/cs/LC_MESSAGES/test.mo assert_file_has_content appdir/usr/share/runtime/locale/cs/lib/cs/LC_MESSAGES/test.mo 'cs translation' -echo "ok locale dirs migration works with runtime" +ok "locale dirs migration works with runtime" cat > test-locale-no-dirs.json <<'EOF' { @@ -217,4 +215,6 @@ run_build test-locale-no-dirs.json assert_has_file appdir/files/bin/test assert_not_has_dir appdir/files/share/runtime/locale -echo "ok locale migration handles missing locale dirs" +ok "locale migration handles missing locale dirs" + +done_testing diff --git a/tests/test-builder-python.sh b/tests/test-builder-python.sh index eecbcd44..e7edf547 100755 --- a/tests/test-builder-python.sh +++ b/tests/test-builder-python.sh @@ -24,8 +24,6 @@ set -euo pipefail skip_without_fuse skip_without_python2 -echo "1..2" - setup_repo install_repo setup_python2_repo @@ -51,7 +49,7 @@ builder_run_app org.test.Python.json testpython.py > testpython.out assert_file_has_content testpython.out ^modified$ -echo "ok handled pyc rewriting multiple times" +ok "handled pyc rewriting multiple times" run_build org.test.Python2.json @@ -62,4 +60,6 @@ builder_run_app org.test.Python2.json testpython.py > testpython.out assert_file_has_content testpython.out "^first $" -echo "ok handled .pyc without .py" +ok "handled .pyc without .py" + +done_testing diff --git a/tests/test-builder.sh b/tests/test-builder.sh index 67dd5218..71b658c2 100755 --- a/tests/test-builder.sh +++ b/tests/test-builder.sh @@ -23,8 +23,6 @@ set -euo pipefail skip_without_fuse -echo "1..10" - setup_repo install_repo setup_sdk_repo @@ -103,7 +101,7 @@ for MANIFEST in test.json test.yaml test-rename.json test-rename-appdata.json ; assert_file_has_content appdir/files/share/licenses/org.test.Hello2/test/LICENSE '^MY LICENSE$' - echo "ok build" + ok "build" done ${FLATPAK} ${U} install -y test-repo org.test.Hello2 master >&2 @@ -113,7 +111,7 @@ assert_file_has_content hello_out3 '^Hello world2, from a sandbox$' run --command=cat org.test.Hello2 /app/share/app-data > app_data_1 assert_file_has_content app_data_1 version1 -echo "ok install+run" +ok "install+run" echo "version2" > app-data run_build $FL_GPGARGS --repo="$REPO" test.json @@ -126,13 +124,13 @@ ${FLATPAK} ${U} update -y org.test.Hello2 master >&2 run --command=cat org.test.Hello2 /app/share/app-data > app_data_2 assert_file_has_content app_data_2 version2 -echo "ok update" +ok "update" # The build-args of --help should prevent the faulty cleanup and # platform-cleanup commands from executing APPDIR=runtimedir run_build $FL_GPGARGS --repo="$REPO" test-runtime.json -echo "ok runtime build cleanup with build-args" +ok "runtime build cleanup with build-args" # test screenshot ref commit APPDIR=builddir_sc \ @@ -144,7 +142,7 @@ ostree --repo=$REPO/repo_sc refs|grep -Eq "^screenshots/$(flatpak --default-arch ostree checkout --repo=$REPO/repo_sc -U screenshots/$(flatpak --default-arch) outdir_sc find outdir_sc -path "*/icons/64x64/org.test.Hello.png" -type f | grep -q . -echo "ok screenshot ref commit" +ok "screenshot ref commit" # test install APPDIR=builddir run_build --user --install org.flatpak.install_test.json @@ -154,11 +152,13 @@ echo "$REFS" | grep -q "org\.flatpak\.install_test" echo "$REFS" | grep -q "org\.flatpak\.install_test\.Debug" echo "$REFS" | grep -q "org\.flatpak\.install_test\.Locale" -echo "ok install" +ok "install" run_build --repo="$REPO" test-locale-cleanup.json assert_not_has_file appdir/files/share/runtime/locale/es/share/es/testA.mo assert_has_file appdir/files/share/runtime/locale/es/share/es/testB.mo -echo "ok testB's locale survives after testA's cleanup" +ok "testB's locale survives after testA's cleanup" + +done_testing diff --git a/tests/test-sandboxed-mode-source-resolution.sh b/tests/test-sandboxed-mode-source-resolution.sh index e945e0f5..fca4e754 100755 --- a/tests/test-sandboxed-mode-source-resolution.sh +++ b/tests/test-sandboxed-mode-source-resolution.sh @@ -24,8 +24,6 @@ set -euo pipefail skip_without_fuse -echo "1..15" - setup_repo install_repo setup_sdk_repo @@ -66,7 +64,7 @@ run_build --sandbox test-path-inside.json assert_has_file appdir/files/test.txt assert_file_has_content appdir/files/test.txt 'test' -echo "ok path source inside manifest tree works for file type in sandboxed mode" +ok "path source inside manifest tree works for file type in sandboxed mode" cat > test-file-url-inside.json < test-file-url-outside.json < test-archive-file_uri-inside.json < test-archive-file_uri-outside.json < test-git-file_uri-inside.json < test-git-file_uri-outside.json <