diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc index 085d0db0..8cd31ae6 100644 --- a/tests/Makefile.am.inc +++ b/tests/Makefile.am.inc @@ -89,6 +89,7 @@ dist_test_scripts = \ tests/test-builder-python.sh \ tests/test-builder-cleanup.sh \ tests/test-builder-licence-paths.sh \ + tests/test-builder-locale-migration.sh \ $(NULL) @VALGRIND_CHECK_RULES@ diff --git a/tests/meson.build b/tests/meson.build index 88a82dc6..aec77d17 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -13,6 +13,7 @@ test_names = [ 'test-builder-python', 'test-builder-cleanup', 'test-builder-licence-paths', + 'test-builder-locale-migration', ] tap_test = find_program( diff --git a/tests/test-builder-locale-migration.sh b/tests/test-builder-locale-migration.sh new file mode 100755 index 00000000..d832df15 --- /dev/null +++ b/tests/test-builder-locale-migration.sh @@ -0,0 +1,186 @@ +#!/bin/bash +# +# Copyright (C) 2026 Boudhayan Bhattacharya +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +set -euo pipefail + +. $(dirname $0)/libtest.sh + +skip_without_fuse + +echo "1..3" + +setup_repo +install_repo +setup_sdk_repo +install_sdk_repo + +cd "$TEST_DATA_DIR" + +run_build () { + local manifest=$1 + ${FLATPAK_BUILDER} --force-clean appdir "$manifest" >&2 +} + +cat > test-locale-migration.json <<'EOF' +{ + "app-id": "org.test.locale_migration", + "runtime": "org.test.Platform", + "sdk": "org.test.Sdk", + "modules": [{ + "name": "test", + "buildsystem": "simple", + "build-commands": [ + "mkdir -p /app/share/locale/de/LC_MESSAGES", + "echo 'de translation' > /app/share/locale/de/LC_MESSAGES/test.mo", + "mkdir -p /app/share/locale/C/LC_MESSAGES", + "echo 'C locale' > /app/share/locale/C/LC_MESSAGES/test.mo", + "mkdir -p /app/share/locale/en/LC_MESSAGES", + "echo 'en locale' > /app/share/locale/en/LC_MESSAGES/test.mo", + "mkdir -p /app/lib/locale/ru/LC_MESSAGES", + "echo 'ru translation' > /app/lib/locale/ru/LC_MESSAGES/test.mo", + "mkdir -p /app/share/locale/sr@latin/LC_MESSAGES", + "echo 'sr latin' > /app/share/locale/sr@latin/LC_MESSAGES/test.mo", + "mkdir -p /app/share/locale/pt_BR/LC_MESSAGES", + "echo 'pt_BR translation' > /app/share/locale/pt_BR/LC_MESSAGES/test.mo", + "mkdir -p /app/share/locale/de.utf8/LC_MESSAGES", + "echo 'de utf8' > /app/share/locale/de.utf8/LC_MESSAGES/test.mo", + "mkdir -p /app/share/locale/ko/LC_MESSAGES", + "echo 'app1' > /app/share/locale/ko/LC_MESSAGES/app1.mo", + "echo 'app2' > /app/share/locale/ko/LC_MESSAGES/app2.mo", + "mkdir -p /app/share/locale/es/LC_MESSAGES", + "echo 'es share' > /app/share/locale/es/LC_MESSAGES/test.mo", + "mkdir -p /app/lib/locale/es/LC_CTYPE", + "echo 'es lib' > /app/lib/locale/es/LC_CTYPE/test.mo", + "mkdir -p /app/share/locale/sv" + ] + }] +} +EOF + +run_build test-locale-migration.json + +# share/locale is migrated to share/runtime/locale/ +assert_has_symlink appdir/files/share/locale/de +assert_symlink_has_content appdir/files/share/locale/de 'share/runtime/locale/de' +assert_has_file appdir/files/share/runtime/locale/de/share/de/LC_MESSAGES/test.mo +assert_file_has_content appdir/files/share/runtime/locale/de/share/de/LC_MESSAGES/test.mo 'de translation' + +# lib/locale is migrated to share/runtime/locale/ +assert_has_symlink appdir/files/lib/locale/ru +assert_symlink_has_content appdir/files/lib/locale/ru 'share/runtime/locale/ru' +assert_has_file appdir/files/share/runtime/locale/ru/lib/ru/LC_MESSAGES/test.mo +assert_file_has_content appdir/files/share/runtime/locale/ru/lib/ru/LC_MESSAGES/test.mo 'ru translation' + +# C and en locales are not migrated +assert_has_dir appdir/files/share/locale/C +assert_has_file appdir/files/share/locale/C/LC_MESSAGES/test.mo +assert_file_has_content appdir/files/share/locale/C/LC_MESSAGES/test.mo 'C locale' + +assert_has_dir appdir/files/share/locale/en +assert_has_file appdir/files/share/locale/en/LC_MESSAGES/test.mo +assert_file_has_content appdir/files/share/locale/en/LC_MESSAGES/test.mo 'en locale' + +# '@' stripped: sr@latin -> sr +assert_has_symlink appdir/files/share/locale/sr@latin +assert_has_file appdir/files/share/runtime/locale/sr/share/sr@latin/LC_MESSAGES/test.mo +assert_file_has_content appdir/files/share/runtime/locale/sr/share/sr@latin/LC_MESSAGES/test.mo 'sr latin' + +# '_' stripped: pt_BR -> pt +assert_has_symlink appdir/files/share/locale/pt_BR +assert_symlink_has_content appdir/files/share/locale/pt_BR 'share/runtime/locale/pt' +assert_has_file appdir/files/share/runtime/locale/pt/share/pt_BR/LC_MESSAGES/test.mo +assert_file_has_content appdir/files/share/runtime/locale/pt/share/pt_BR/LC_MESSAGES/test.mo 'pt_BR translation' + +# '.' stripped: de.utf8 -> de +assert_has_symlink appdir/files/share/locale/de.utf8 +assert_has_file appdir/files/share/runtime/locale/de/share/de.utf8/LC_MESSAGES/test.mo +assert_file_has_content appdir/files/share/runtime/locale/de/share/de.utf8/LC_MESSAGES/test.mo 'de utf8' + +# multiple files in a single locale dir are migrated +assert_has_symlink appdir/files/share/locale/ko +assert_has_file appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app1.mo +assert_file_has_content appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app1.mo 'app1' +assert_has_file appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app2.mo +assert_file_has_content appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app2.mo 'app2' + +# same language in share/locale and lib/locale is merged +assert_has_symlink appdir/files/share/locale/es +assert_has_file appdir/files/share/runtime/locale/es/share/es/LC_MESSAGES/test.mo +assert_file_has_content appdir/files/share/runtime/locale/es/share/es/LC_MESSAGES/test.mo 'es share' +assert_has_symlink appdir/files/lib/locale/es +assert_has_file appdir/files/share/runtime/locale/es/lib/es/LC_CTYPE/test.mo +assert_file_has_content appdir/files/share/runtime/locale/es/lib/es/LC_CTYPE/test.mo 'es lib' + +# empty locale dir creates empty migration dir +assert_has_dir appdir/files/share/locale/sv +assert_has_dir appdir/files/share/runtime/locale/sv + +echo "ok locale dirs migrated" + + +cat > test-locale-disabled.json <<'EOF' +{ + "app-id": "org.test.locale_migration_disabled", + "runtime": "org.test.Platform", + "sdk": "org.test.Sdk", + "separate-locales": false, + "modules": [{ + "name": "test", + "buildsystem": "simple", + "build-commands": [ + "mkdir -p /app/share/locale/de/LC_MESSAGES", + "echo 'de translation' > /app/share/locale/de/LC_MESSAGES/test.mo" + ] + }] +} +EOF + +run_build test-locale-disabled.json + +assert_has_dir appdir/files/share/locale/de +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" + +cat > test-locale-migration-runtime.json <<'EOF' +{ + "app-id": "org.test.locale_migration_runtime", + "runtime": "org.test.Platform", + "sdk": "org.test.Sdk", + "build-runtime": true, + "modules": [{ + "name": "test", + "buildsystem": "simple", + "build-commands": [ + "mkdir -p /usr/share/locale/pl/LC_MESSAGES", + "echo 'pl translation' > /usr/share/locale/pl/LC_MESSAGES/test.mo" + ] + }] +} +EOF + +run_build test-locale-migration-runtime.json + +assert_has_symlink appdir/usr/share/locale/pl +assert_has_file appdir/usr/share/runtime/locale/pl/share/pl/LC_MESSAGES/test.mo +assert_file_has_content appdir/usr/share/runtime/locale/pl/share/pl/LC_MESSAGES/test.mo 'pl translation' + +echo "ok locale dirs migration works with runtime"