From 7b124abd2e036657091a6565ffd83ac7b3d053bd Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Mon, 24 Jun 2019 21:00:51 +1000 Subject: [PATCH] Fix engine test failure under flatpak Geary.ImapDb.Database/utf8_case_insensitive_collation depends on a well known UTF-8 collation order, but distros only ship C.UTF-8 by default and Flatpak doesn't ship that, so support en_US.UTF-8 as a fallback. See https://gitlab.com/freedesktop-sdk/freedesktop-sdk/issues/812 --- test/engine/imap-db/imap-db-database-test.vala | 11 +++++++++++ test/test-engine.vala | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/test/engine/imap-db/imap-db-database-test.vala b/test/engine/imap-db/imap-db-database-test.vala index 44a4845f..5b758c2a 100644 --- a/test/engine/imap-db/imap-db-database-test.vala +++ b/test/engine/imap-db/imap-db-database-test.vala @@ -147,7 +147,18 @@ class Geary.ImapDB.DatabaseTest : TestCase { INSERT INTO Test (test_str) VALUES ('BB'); INSERT INTO Test (test_str) VALUES ('🤯'); """); + string[] expected = { "a", "BB", "B", "🤯" }; + // Distros don't ship well-known locales other than C.UTF-8 by + // default, but Flatpak does not currently ship C.UTF-8 at + // all, so need to support both. :( + // + // See test-engine.vala and + // https://gitlab.com/freedesktop-sdk/freedesktop-sdk/issues/812 + if (GLib.Intl.setlocale(LocaleCategory.COLLATE, null) != "C.UTF-8") { + // en_US.UTF-8: + expected = { "BB", "B", "a", "🤯" }; + } Db.Result result = db.query( "SELECT test_str FROM Test ORDER BY test_str COLLATE UTF8COLL DESC" diff --git a/test/test-engine.vala b/test/test-engine.vala index 55862bd5..a972d75e 100644 --- a/test/test-engine.vala +++ b/test/test-engine.vala @@ -10,11 +10,19 @@ int main(string[] args) { * Initialise all the things. */ - Test.init(ref args); - // Ensure things like e.g. GLib's formatting routines uses a - // UTF-8-based locale rather ASCII - GLib.Intl.setlocale(LocaleCategory.ALL, "C.UTF-8"); + // well-known UTF-8-based locale rather ASCII. + // + // Distros don't ship well-known locales other than C.UTF-8 by + // default, but Flatpak does not currently support C.UTF-8, so + // need to try both. :( + // https://gitlab.com/freedesktop-sdk/freedesktop-sdk/issues/812 + string? locale = GLib.Intl.setlocale(LocaleCategory.ALL, "C.UTF-8"); + if (locale == null) { + GLib.Intl.setlocale(LocaleCategory.ALL, "en_US.UTF-8"); + } + + Test.init(ref args); Geary.RFC822.init(); Geary.HTML.init();