This should improve skipping euc-mb and sjis-mb tests when the locale is not supported. I'm hesitant to put it in NEWS because I didn't test it on e.g. Cygwin.
It could be applied to other multibyte tests (fmbtest, char-class-multibyte) too. * tests/Makefile.am (check_PROGRAMS): Add get-mb-cur-max. * tests/get-mb-cur-max.c: New. * tests/euc-mb: Use it. Fail if the former detection test fails. * tests/sjis-mb: Use it. Fail if the former detection test fails. --- tests/Makefile.am | 2 ++ tests/euc-mb | 25 +++++++++++++++++-------- tests/get-mb-cur-max.c | 34 ++++++++++++++++++++++++++++++++++ tests/sjis-mb | 15 +++++++++------ 4 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 tests/get-mb-cur-max.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 6920d21..ce8fcb6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -14,6 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +check_PROGRAMS = get-mb-cur-max + TESTS = \ backref.sh \ backref-word \ diff --git a/tests/euc-mb b/tests/euc-mb index becb032..590bd91 100644 --- a/tests/euc-mb +++ b/tests/euc-mb @@ -3,7 +3,9 @@ # too greedily. # Derived from https://savannah.gnu.org/bugs/?23814 : ${srcdir=.} -. "$srcdir/init.sh"; path_prepend_ ../src +. "$srcdir/init.sh"; path_prepend_ . ../src + +locale=ja_JP.EUC-JP make_input () { echo "$1" | tr AB '\244\263' @@ -11,14 +13,21 @@ make_input () { euc_grep () { pat=`make_input "$1"` - LC_ALL=ja_JP.EUC-JP grep "$pat" + LC_ALL=$locale grep "$pat" } -if make_input BABA |euc_grep AB ; then - skip_ 'EUC-JP locale seems not to work' -fi -make_input BABAAB |euc_grep AB || \ - fail_ 'whole line rejected after matching in the middle of a multibyte char' +case `get-mb-cur-max $locale` in + 2|3) ;; + *) skip_ 'EUC-JP locale not found' ;; +esac + +fail=0 + +# Does EUC-JP work at all? +make_input BABA |euc_grep AB && fail=1 + +# Whole line rejected after matching in the middle of a multibyte char? +make_input BABAAB |euc_grep AB || fail=1 -Exit 0 +Exit $fail diff --git a/tests/get-mb-cur-max.c b/tests/get-mb-cur-max.c new file mode 100644 index 0000000..fd558ed --- /dev/null +++ b/tests/get-mb-cur-max.c @@ -0,0 +1,34 @@ +/* Auxiliary program to detect support for a locale. + Copyright 2010 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. */ + +#include "config.h" +#include <locale.h> +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) +{ + if (setlocale (LC_ALL, argv[1])) + { + printf ("%d\n", MB_CUR_MAX); + exit (0); + } + + exit (1); +} diff --git a/tests/sjis-mb b/tests/sjis-mb index f2479ba..6b2db30 100644 --- a/tests/sjis-mb +++ b/tests/sjis-mb @@ -4,21 +4,22 @@ # character, and a suffix of a valid double-byte character : ${srcdir=.} -. "$srcdir/init.sh"; path_prepend_ ../src +. "$srcdir/init.sh"; path_prepend_ . ../src require_timeout_ +locale=ja_JP.SHIFT_JIS + # % becomes an half-width katakana in SJIS, and an invalid sequence # in UTF-8. Use this to try skipping implementations that do not # support SJIS. encode() { echo "$1" | tr @% '\203\301'; } seq=0 test_grep_reject() { seq=`expr $seq + 1` encode "$2" | \ - LC_ALL=ja_JP.SHIFT_JIS \ + LC_ALL=$locale \ timeout 10s grep $1 `encode "$3"` > out$seq 2>&1 test $? = 1 } @@ -26,14 +27,14 @@ test_grep_reject() { test_grep() { seq=`expr $seq + 1` encode "$2" > exp$seq - LC_ALL=ja_JP.SHIFT_JIS \ + LC_ALL=$locale \ timeout 10s grep $1 `encode "$3"` exp$seq > out$seq 2>&1 test $? = 0 && compare out$seq exp$seq } -test_grep_reject -F @@ @ || skip_ 'system does not seem to know about SJIS' -test_grep -F %%AA A || skip_ 'system seems to treat SJIS the same as UTF-8' +test "`get-mb-cur-max $locale`" = 2 || skip_ 'SJIS locale not found' fail=0 failure_tes...@a successful_tests='%%AA @AA @A@@A' @@ -42,6 +43,8 @@ for i in $successful_tests; do test_grep -E $i A || fail=1 done +test_grep_reject -F @@ @ +test_grep_reject -E @@ @ for i in $failure_tests; do test_grep_reject -F $i A || fail=1 test_grep_reject -E $i A || fail=1 -- 1.6.6.1
