Subject: fmbtest unnecessarily skipped on FreeBSD
From: Bruno Haible <[email-masked]>
To: [email-masked]
Date: Mon, 08 Jul 2024 14:14:41 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Building grep-3.11 on FreeBSD 14.0, "make check" reports that the fmbtest
test is skipped:

  fmbtest: skipped test: this system lacks the cs_CZ.UTF-8 locale
  SKIP: fmbtest

But

  $ locale -a | grep cs_CZ
  cs_CZ.ISO8859-2
  cz_CZ.UTF-8

shows that the system does have this locale.

The cause is that this invocation of 'locale' does not work:

  $ locale -k LC_CTYPE
  Unknown keyword: `LC_CTYPE`

But this one works:

  $ locale charmap
  UTF-8

=> Patch attached. It fixes the problem: it makes the test PASS.

'locale charmap' is known to work portably for ages; see
https://git.savannah.gnu.org/gitweb/?p=libiconv.git;a=tree;f=libcharset/tools;h=f756e65e5ea8fef47afc8bb7ae1094e169012c78;hb=HEAD

From a4501af35dcc7603ee5f500aa87aafe577958010 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email-masked]>
Date: Mon, 8 Jul 2024 14:06:16 +0200
Subject: [PATCH] tests: Fix recognition of cs_CZ.UTF-8 locale on FreeBSD.

* tests/fmbtest: Use 'locale charmap' to determine the locale's encoding.
* tests/foad1: Likewise.
---
 tests/fmbtest | 2 +-
 tests/foad1   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/fmbtest b/tests/fmbtest
index 38dd49d..f3404fd 100755
--- a/tests/fmbtest
+++ b/tests/fmbtest
@@ -10,7 +10,7 @@
 cz=cs_CZ.UTF-8
 
 # If cs_CZ.UTF-8 locale doesn't work, skip this test.
-LC_ALL=$cz locale -k LC_CTYPE 2>/dev/null | grep -q charmap.*UTF-8 \
+test "`LC_ALL=$cz locale charmap 2>/dev/null`" = UTF-8 \
   || skip_ this system lacks the $cz locale
 
 # If matching is done in single-byte mode, skip this test too
diff --git a/tests/foad1 b/tests/foad1
index 3a29f9e..b87e3f3 100755
--- a/tests/foad1
+++ b/tests/foad1
@@ -150,7 +150,7 @@ Exit $failures
 # The rest of this file is meant to be executed under this locale.
 LC_ALL=cs_CZ.UTF-8; export LC_ALL
 # If the UTF-8 locale doesn't work, skip these tests silently.
-locale -k LC_CTYPE 2>/dev/null | grep -q "charmap.*UTF-8" || Exit $failures
+test "`locale charmap 2>/dev/null`" = UTF-8 || Exit $failures
 
 # Test character class erroneously matching a '[' character.
 grep_test "[/" "" "[[:alpha:]]" -E
-- 
2.34.1