Skip to content

Commit 05c916a

Browse files
committed
tests: Add tests for locale migration
1 parent 18407a5 commit 05c916a

3 files changed

Lines changed: 232 additions & 0 deletions

File tree

tests/libtest.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ assert_has_dir () {
123123
test -d "$1" || (echo 1>&2 "Couldn't find '$1'"; exit 1)
124124
}
125125

126+
assert_not_has_symlink () {
127+
if test -L "$1"; then
128+
echo 1>&2 "Symlink '$1' exists"; exit 1
129+
fi
130+
}
131+
126132
assert_not_has_file () {
127133
if test -f "$1"; then
128134
sed -e 's/^/# /' < "$1" >&2

tests/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test_names = [
2424
'test-builder-cleanup',
2525
'test-builder-licence-paths',
2626
'test-builder-src-date-epoch',
27+
'test-builder-locale-migration',
2728
]
2829

2930
tap_test = find_program(
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) 2026 Boudhayan Bhattacharya <bbhtt@bbhtt.in>
4+
#
5+
# This library is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU Lesser General Public
7+
# License as published by the Free Software Foundation; either
8+
# version 2 of the License, or (at your option) any later version.
9+
#
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public
16+
# License along with this library; if not, write to the
17+
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18+
# Boston, MA 02111-1307, USA.
19+
20+
set -euo pipefail
21+
22+
. $(dirname $0)/libtest.sh
23+
24+
skip_without_fuse
25+
26+
echo "1..4"
27+
28+
setup_repo
29+
install_repo
30+
setup_sdk_repo
31+
install_sdk_repo
32+
33+
cd "$TEST_DATA_DIR"
34+
35+
run_build () {
36+
local manifest=$1
37+
${FLATPAK_BUILDER} --force-clean appdir "$manifest" >&2
38+
}
39+
40+
cat > test-locale-migration.json <<'EOF'
41+
{
42+
"app-id": "org.test.locale_migration",
43+
"runtime": "org.test.Platform",
44+
"sdk": "org.test.Sdk",
45+
"modules": [{
46+
"name": "test",
47+
"buildsystem": "simple",
48+
"build-commands": [
49+
"mkdir -p /app/share/locale/de/LC_MESSAGES",
50+
"echo 'de translation' > /app/share/locale/de/LC_MESSAGES/test.mo",
51+
52+
"mkdir -p /app/share/locale/C/LC_MESSAGES",
53+
"echo 'C locale' > /app/share/locale/C/LC_MESSAGES/test.mo",
54+
"mkdir -p /app/share/locale/en/LC_MESSAGES",
55+
"echo 'en locale' > /app/share/locale/en/LC_MESSAGES/test.mo",
56+
57+
"mkdir -p /app/lib/locale/ru/LC_MESSAGES",
58+
"echo 'ru translation' > /app/lib/locale/ru/LC_MESSAGES/test.mo",
59+
60+
"mkdir -p /app/share/locale/sr_RS@latin.UTF-8/LC_MESSAGES",
61+
"echo 'sr combined' > /app/share/locale/sr_RS@latin.UTF-8/LC_MESSAGES/test.mo",
62+
63+
"mkdir -p /app/share/locale/ko/LC_MESSAGES",
64+
"echo 'app1' > /app/share/locale/ko/LC_MESSAGES/app1.mo",
65+
"echo 'app2' > /app/share/locale/ko/LC_MESSAGES/app2.mo",
66+
67+
"mkdir -p /app/share/locale/es/LC_MESSAGES",
68+
"echo 'es share' > /app/share/locale/es/LC_MESSAGES/test.mo",
69+
"mkdir -p /app/lib/locale/es/LC_CTYPE",
70+
"echo 'es lib' > /app/lib/locale/es/LC_CTYPE/test.mo",
71+
72+
"mkdir -p /app/share/locale/de_DE/LC_MESSAGES",
73+
"echo 'de_DE translation' > /app/share/locale/de_DE/LC_MESSAGES/test.mo",
74+
"mkdir -p /app/share/locale/de_AT/LC_MESSAGES",
75+
"echo 'de_AT translation' > /app/share/locale/de_AT/LC_MESSAGES/test.mo",
76+
77+
"touch /app/share/locale/plain-file",
78+
79+
"mkdir -p /app/share/locale/sv"
80+
]
81+
}]
82+
}
83+
EOF
84+
85+
run_build test-locale-migration.json
86+
87+
# share/locale is migrated to share/runtime/locale/$lang
88+
assert_has_symlink appdir/files/share/locale/de
89+
assert_symlink_has_content appdir/files/share/locale/de 'share/runtime/locale/de'
90+
assert_has_file appdir/files/share/runtime/locale/de/share/de/LC_MESSAGES/test.mo
91+
assert_file_has_content appdir/files/share/runtime/locale/de/share/de/LC_MESSAGES/test.mo 'de translation'
92+
93+
# lib/locale is migrated to share/runtime/locale/$lang
94+
assert_has_symlink appdir/files/lib/locale/ru
95+
assert_symlink_has_content appdir/files/lib/locale/ru 'share/runtime/locale/ru'
96+
assert_has_file appdir/files/share/runtime/locale/ru/lib/ru/LC_MESSAGES/test.mo
97+
assert_file_has_content appdir/files/share/runtime/locale/ru/lib/ru/LC_MESSAGES/test.mo 'ru translation'
98+
99+
# C and en locales are not migrated
100+
assert_has_dir appdir/files/share/locale/C
101+
assert_has_file appdir/files/share/locale/C/LC_MESSAGES/test.mo
102+
assert_file_has_content appdir/files/share/locale/C/LC_MESSAGES/test.mo 'C locale'
103+
104+
assert_has_dir appdir/files/share/locale/en
105+
assert_has_file appdir/files/share/locale/en/LC_MESSAGES/test.mo
106+
assert_file_has_content appdir/files/share/locale/en/LC_MESSAGES/test.mo 'en locale'
107+
108+
# sr_RS@latin.UTF-8 -> sr
109+
assert_has_symlink appdir/files/share/locale/sr_RS@latin.UTF-8
110+
assert_has_file appdir/files/share/runtime/locale/sr/share/sr_RS@latin.UTF-8/LC_MESSAGES/test.mo
111+
assert_file_has_content appdir/files/share/runtime/locale/sr/share/sr_RS@latin.UTF-8/LC_MESSAGES/test.mo 'sr combined'
112+
113+
# multiple files in a single locale dir are migrated
114+
assert_has_symlink appdir/files/share/locale/ko
115+
assert_has_file appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app1.mo
116+
assert_file_has_content appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app1.mo 'app1'
117+
assert_has_file appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app2.mo
118+
assert_file_has_content appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app2.mo 'app2'
119+
120+
# same language in share/locale and lib/locale is merged to same target
121+
assert_has_symlink appdir/files/share/locale/es
122+
assert_has_file appdir/files/share/runtime/locale/es/share/es/LC_MESSAGES/test.mo
123+
assert_file_has_content appdir/files/share/runtime/locale/es/share/es/LC_MESSAGES/test.mo 'es share'
124+
assert_has_symlink appdir/files/lib/locale/es
125+
assert_has_file appdir/files/share/runtime/locale/es/lib/es/LC_CTYPE/test.mo
126+
assert_file_has_content appdir/files/share/runtime/locale/es/lib/es/LC_CTYPE/test.mo 'es lib'
127+
128+
# language variants are merged
129+
assert_has_symlink appdir/files/share/locale/de_DE
130+
assert_has_symlink appdir/files/share/locale/de_AT
131+
assert_has_file appdir/files/share/runtime/locale/de/share/de_DE/LC_MESSAGES/test.mo
132+
assert_file_has_content appdir/files/share/runtime/locale/de/share/de_DE/LC_MESSAGES/test.mo 'de_DE translation'
133+
assert_has_file appdir/files/share/runtime/locale/de/share/de_AT/LC_MESSAGES/test.mo
134+
assert_file_has_content appdir/files/share/runtime/locale/de/share/de_AT/LC_MESSAGES/test.mo 'de_AT translation'
135+
136+
# empty locale dir creates empty migration dir
137+
assert_has_dir appdir/files/share/locale/sv
138+
assert_has_dir appdir/files/share/runtime/locale/sv
139+
140+
# non-directory entries are ignored
141+
assert_has_file appdir/files/share/locale/plain-file
142+
assert_not_has_symlink appdir/files/share/locale/plain-file
143+
144+
echo "ok locale dirs migrated"
145+
146+
cat > test-locale-disabled.json <<'EOF'
147+
{
148+
"app-id": "org.test.locale_migration_disabled",
149+
"runtime": "org.test.Platform",
150+
"sdk": "org.test.Sdk",
151+
"separate-locales": false,
152+
"modules": [{
153+
"name": "test",
154+
"buildsystem": "simple",
155+
"build-commands": [
156+
"mkdir -p /app/share/locale/de/LC_MESSAGES",
157+
"echo 'de translation' > /app/share/locale/de/LC_MESSAGES/test.mo"
158+
]
159+
}]
160+
}
161+
EOF
162+
163+
run_build test-locale-disabled.json
164+
165+
assert_has_dir appdir/files/share/locale/de
166+
assert_has_file appdir/files/share/locale/de/LC_MESSAGES/test.mo
167+
assert_file_has_content appdir/files/share/locale/de/LC_MESSAGES/test.mo 'de translation'
168+
assert_not_has_dir appdir/files/share/runtime/locale
169+
170+
echo "ok locale dirs migration is disabled on separate-locales false"
171+
172+
cat > test-locale-migration-runtime.json <<'EOF'
173+
{
174+
"app-id": "org.test.locale_migration_runtime",
175+
"runtime": "org.test.Platform",
176+
"sdk": "org.test.Sdk",
177+
"build-runtime": true,
178+
"modules": [{
179+
"name": "test",
180+
"buildsystem": "simple",
181+
"build-commands": [
182+
"mkdir -p /usr/share/locale/pl/LC_MESSAGES",
183+
"echo 'pl translation' > /usr/share/locale/pl/LC_MESSAGES/test.mo",
184+
185+
"mkdir -p /usr/lib/locale/cs/LC_MESSAGES",
186+
"echo 'cs translation' > /usr/lib/locale/cs/LC_MESSAGES/test.mo"
187+
]
188+
}]
189+
}
190+
EOF
191+
192+
run_build test-locale-migration-runtime.json
193+
194+
assert_has_symlink appdir/usr/share/locale/pl
195+
assert_has_file appdir/usr/share/runtime/locale/pl/share/pl/LC_MESSAGES/test.mo
196+
assert_file_has_content appdir/usr/share/runtime/locale/pl/share/pl/LC_MESSAGES/test.mo 'pl translation'
197+
198+
assert_has_symlink appdir/usr/lib/locale/cs
199+
assert_has_file appdir/usr/share/runtime/locale/cs/lib/cs/LC_MESSAGES/test.mo
200+
assert_file_has_content appdir/usr/share/runtime/locale/cs/lib/cs/LC_MESSAGES/test.mo 'cs translation'
201+
202+
echo "ok locale dirs migration works with runtime"
203+
204+
cat > test-locale-no-dirs.json <<'EOF'
205+
{
206+
"app-id": "org.test.locale_no_dirs",
207+
"runtime": "org.test.Platform",
208+
"sdk": "org.test.Sdk",
209+
"modules": [{
210+
"name": "test",
211+
"buildsystem": "simple",
212+
"build-commands": [
213+
"mkdir -p /app/bin",
214+
"echo test > /app/bin/test"
215+
]
216+
}]
217+
}
218+
EOF
219+
220+
run_build test-locale-no-dirs.json
221+
222+
assert_has_file appdir/files/bin/test
223+
assert_not_has_dir appdir/files/share/runtime/locale
224+
225+
echo "ok locale migration handles missing locale dirs"

0 commit comments

Comments
 (0)