]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: check if we correctly handle locales with leading spaces 27707/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 19 May 2023 17:53:55 +0000 (19:53 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 19 May 2023 19:35:47 +0000 (21:35 +0200)
Provides coverage for #27179.

test/units/testsuite-73.sh

index 8e2bca10052420898acaef8f83186c064d559ba7..523acd8d06f75c6aeeb3d86ab08f8cd8cfceab3f 100755 (executable)
@@ -648,6 +648,38 @@ EOF
     assert_in "XKBLAYOUT=us" "$output"
 }
 
+locale_gen_cleanup() {
+    # Some running apps might keep the mount point busy, hence the lazy unmount
+    mountpoint -q /usr/lib/locale && umount --lazy /usr/lib/locale
+    [[ -e /tmp/locale.gen.bak ]] && mv -f /tmp/locale.gen.bak /etc/locale.gen
+
+    return 0
+}
+
+# Issue: https://github.com/systemd/systemd/pull/27179
+testcase_locale_gen_leading_space() {
+    if ! command -v locale-gen >/dev/null; then
+        echo "No locale-gen support, skipping test."
+        return 0
+    fi
+
+    [[ -e /etc/locale.gen ]] && cp -f /etc/locale.gen /tmp/locale.gen.bak
+    trap locale_gen_cleanup RETURN
+    # Overmount the existing locale-gen database with an empty directory
+    # to force it to regenerate locales
+    mount -t tmpfs tmpfs /usr/lib/locale
+
+    {
+        echo -e "en_US.UTF-8 UTF-8"
+        echo -e " en_US.UTF-8 UTF-8"
+        echo -e "\ten_US.UTF-8 UTF-8"
+        echo -e " \t en_US.UTF-8 UTF-8 \t"
+    } >/etc/locale.gen
+
+    localectl set-locale de_DE.UTF-8
+    localectl set-locale en_US.UTF-8
+}
+
 : >/failed
 
 # Make sure the content of kbd-model-map is the one that the tests expect