Skip to content

Commit f0aed66

Browse files
committed
tests: Add tests for locale migration
1 parent 3d21998 commit f0aed66

4 files changed

Lines changed: 228 additions & 0 deletions

File tree

tests/Makefile.am.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ dist_test_scripts = \
8989
tests/test-builder-python.sh \
9090
tests/test-builder-cleanup.sh \
9191
tests/test-builder-licence-paths.sh \
92+
tests/test-builder-locale-migration.sh \
9293
$(NULL)
9394

9495
@VALGRIND_CHECK_RULES@

tests/libtest.sh

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

118+
assert_not_has_symlink () {
119+
if test -L "$1"; then
120+
echo 1>&2 "Symlink '$1' exists"; exit 1
121+
fi
122+
}
123+
118124
assert_not_has_file () {
119125
if test -f "$1"; then
120126
sed -e 's/^/# /' < "$1" >&2

tests/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test_names = [
1313
'test-builder-python',
1414
'test-builder-cleanup',
1515
'test-builder-licence-paths',
16+
'test-builder-locale-migration',
1617
]
1718

1819
tap_test = find_program(
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
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+
cat > test-locale-migration.json <<'EOF'
36+
{
37+
"app-id": "org.test.locale_migration",
38+
"runtime": "org.test.Platform",
39+
"sdk": "org.test.Sdk",
40+
"modules": [{
41+
"name": "test",
42+
"buildsystem": "simple",
43+
"build-commands": [
44+
"mkdir -p /app/share/locale/de/LC_MESSAGES",
45+
"echo 'de translation' > /app/share/locale/de/LC_MESSAGES/test.mo",
46+
47+
"mkdir -p /app/share/locale/C/LC_MESSAGES",
48+
"echo 'C locale' > /app/share/locale/C/LC_MESSAGES/test.mo",
49+
"mkdir -p /app/share/locale/en/LC_MESSAGES",
50+
"echo 'en locale' > /app/share/locale/en/LC_MESSAGES/test.mo",
51+
52+
"mkdir -p /app/lib/locale/ru/LC_MESSAGES",
53+
"echo 'ru translation' > /app/lib/locale/ru/LC_MESSAGES/test.mo",
54+
55+
"mkdir -p /app/share/locale/sr_RS@latin.UTF-8/LC_MESSAGES",
56+
"echo 'sr combined' > /app/share/locale/sr_RS@latin.UTF-8/LC_MESSAGES/test.mo",
57+
58+
"mkdir -p /app/share/locale/ko/LC_MESSAGES",
59+
"echo 'app1' > /app/share/locale/ko/LC_MESSAGES/app1.mo",
60+
"echo 'app2' > /app/share/locale/ko/LC_MESSAGES/app2.mo",
61+
62+
"mkdir -p /app/share/locale/es/LC_MESSAGES",
63+
"echo 'es share' > /app/share/locale/es/LC_MESSAGES/test.mo",
64+
"mkdir -p /app/lib/locale/es/LC_CTYPE",
65+
"echo 'es lib' > /app/lib/locale/es/LC_CTYPE/test.mo",
66+
67+
"mkdir -p /app/share/locale/de_DE/LC_MESSAGES",
68+
"echo 'de_DE translation' > /app/share/locale/de_DE/LC_MESSAGES/test.mo",
69+
"mkdir -p /app/share/locale/de_AT/LC_MESSAGES",
70+
"echo 'de_AT translation' > /app/share/locale/de_AT/LC_MESSAGES/test.mo",
71+
72+
"touch /app/share/locale/plain-file",
73+
74+
"mkdir -p /app/share/locale/sv"
75+
]
76+
}]
77+
}
78+
EOF
79+
80+
run_build test-locale-migration.json
81+
82+
# share/locale is migrated to share/runtime/locale/$lang
83+
assert_has_symlink appdir/files/share/locale/de
84+
assert_symlink_has_content appdir/files/share/locale/de 'share/runtime/locale/de'
85+
assert_has_file appdir/files/share/runtime/locale/de/share/de/LC_MESSAGES/test.mo
86+
assert_file_has_content appdir/files/share/runtime/locale/de/share/de/LC_MESSAGES/test.mo 'de translation'
87+
88+
# lib/locale is migrated to share/runtime/locale/$lang
89+
assert_has_symlink appdir/files/lib/locale/ru
90+
assert_symlink_has_content appdir/files/lib/locale/ru 'share/runtime/locale/ru'
91+
assert_has_file appdir/files/share/runtime/locale/ru/lib/ru/LC_MESSAGES/test.mo
92+
assert_file_has_content appdir/files/share/runtime/locale/ru/lib/ru/LC_MESSAGES/test.mo 'ru translation'
93+
94+
# C and en locales are not migrated
95+
assert_has_dir appdir/files/share/locale/C
96+
assert_has_file appdir/files/share/locale/C/LC_MESSAGES/test.mo
97+
assert_file_has_content appdir/files/share/locale/C/LC_MESSAGES/test.mo 'C locale'
98+
99+
assert_has_dir appdir/files/share/locale/en
100+
assert_has_file appdir/files/share/locale/en/LC_MESSAGES/test.mo
101+
assert_file_has_content appdir/files/share/locale/en/LC_MESSAGES/test.mo 'en locale'
102+
103+
# sr_RS@latin.UTF-8 -> sr
104+
assert_has_symlink appdir/files/share/locale/sr_RS@latin.UTF-8
105+
assert_has_file appdir/files/share/runtime/locale/sr/share/sr_RS@latin.UTF-8/LC_MESSAGES/test.mo
106+
assert_file_has_content appdir/files/share/runtime/locale/sr/share/sr_RS@latin.UTF-8/LC_MESSAGES/test.mo 'sr combined'
107+
108+
# multiple files in a single locale dir are migrated
109+
assert_has_symlink appdir/files/share/locale/ko
110+
assert_has_file appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app1.mo
111+
assert_file_has_content appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app1.mo 'app1'
112+
assert_has_file appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app2.mo
113+
assert_file_has_content appdir/files/share/runtime/locale/ko/share/ko/LC_MESSAGES/app2.mo 'app2'
114+
115+
# same language in share/locale and lib/locale is merged to same target
116+
assert_has_symlink appdir/files/share/locale/es
117+
assert_has_file appdir/files/share/runtime/locale/es/share/es/LC_MESSAGES/test.mo
118+
assert_file_has_content appdir/files/share/runtime/locale/es/share/es/LC_MESSAGES/test.mo 'es share'
119+
assert_has_symlink appdir/files/lib/locale/es
120+
assert_has_file appdir/files/share/runtime/locale/es/lib/es/LC_CTYPE/test.mo
121+
assert_file_has_content appdir/files/share/runtime/locale/es/lib/es/LC_CTYPE/test.mo 'es lib'
122+
123+
# language variants are merged
124+
assert_has_symlink appdir/files/share/locale/de_DE
125+
assert_has_symlink appdir/files/share/locale/de_AT
126+
assert_has_file appdir/files/share/runtime/locale/de/share/de_DE/LC_MESSAGES/test.mo
127+
assert_file_has_content appdir/files/share/runtime/locale/de/share/de_DE/LC_MESSAGES/test.mo 'de_DE translation'
128+
assert_has_file appdir/files/share/runtime/locale/de/share/de_AT/LC_MESSAGES/test.mo
129+
assert_file_has_content appdir/files/share/runtime/locale/de/share/de_AT/LC_MESSAGES/test.mo 'de_AT translation'
130+
131+
# empty locale dir creates empty migration dir
132+
assert_has_dir appdir/files/share/locale/sv
133+
assert_has_dir appdir/files/share/runtime/locale/sv
134+
135+
# non-directory entries are ignored
136+
assert_has_file appdir/files/share/locale/plain-file
137+
assert_not_has_symlink appdir/files/share/locale/plain-file
138+
139+
echo "ok locale dirs migrated"
140+
141+
cat > test-locale-disabled.json <<'EOF'
142+
{
143+
"app-id": "org.test.locale_migration_disabled",
144+
"runtime": "org.test.Platform",
145+
"sdk": "org.test.Sdk",
146+
"separate-locales": false,
147+
"modules": [{
148+
"name": "test",
149+
"buildsystem": "simple",
150+
"build-commands": [
151+
"mkdir -p /app/share/locale/de/LC_MESSAGES",
152+
"echo 'de translation' > /app/share/locale/de/LC_MESSAGES/test.mo"
153+
]
154+
}]
155+
}
156+
EOF
157+
158+
run_build test-locale-disabled.json
159+
160+
assert_has_dir appdir/files/share/locale/de
161+
assert_has_file appdir/files/share/locale/de/LC_MESSAGES/test.mo
162+
assert_file_has_content appdir/files/share/locale/de/LC_MESSAGES/test.mo 'de translation'
163+
assert_not_has_dir appdir/files/share/runtime/locale
164+
165+
echo "ok locale dirs migration is disabled on separate-locales false"
166+
167+
cat > test-locale-migration-runtime.json <<'EOF'
168+
{
169+
"app-id": "org.test.locale_migration_runtime",
170+
"runtime": "org.test.Platform",
171+
"sdk": "org.test.Sdk",
172+
"build-runtime": true,
173+
"modules": [{
174+
"name": "test",
175+
"buildsystem": "simple",
176+
"build-commands": [
177+
"mkdir -p /usr/share/locale/pl/LC_MESSAGES",
178+
"echo 'pl translation' > /usr/share/locale/pl/LC_MESSAGES/test.mo",
179+
180+
"mkdir -p /usr/lib/locale/cs/LC_MESSAGES",
181+
"echo 'cs translation' > /usr/lib/locale/cs/LC_MESSAGES/test.mo"
182+
]
183+
}]
184+
}
185+
EOF
186+
187+
run_build test-locale-migration-runtime.json
188+
189+
assert_has_symlink appdir/usr/share/locale/pl
190+
assert_has_file appdir/usr/share/runtime/locale/pl/share/pl/LC_MESSAGES/test.mo
191+
assert_file_has_content appdir/usr/share/runtime/locale/pl/share/pl/LC_MESSAGES/test.mo 'pl translation'
192+
193+
assert_has_symlink appdir/usr/lib/locale/cs
194+
assert_has_file appdir/usr/share/runtime/locale/cs/lib/cs/LC_MESSAGES/test.mo
195+
assert_file_has_content appdir/usr/share/runtime/locale/cs/lib/cs/LC_MESSAGES/test.mo 'cs translation'
196+
197+
echo "ok locale dirs migration works with runtime"
198+
199+
cat > test-locale-no-dirs.json <<'EOF'
200+
{
201+
"app-id": "org.test.locale_no_dirs",
202+
"runtime": "org.test.Platform",
203+
"sdk": "org.test.Sdk",
204+
"modules": [{
205+
"name": "test",
206+
"buildsystem": "simple",
207+
"build-commands": [
208+
"mkdir -p /app/bin",
209+
"echo test > /app/bin/test"
210+
]
211+
}]
212+
}
213+
EOF
214+
215+
run_build test-locale-no-dirs.json
216+
217+
assert_has_file appdir/files/bin/test
218+
assert_not_has_dir appdir/files/share/runtime/locale
219+
220+
echo "ok locale migration handles missing locale dirs"

0 commit comments

Comments
 (0)