summaryrefslogtreecommitdiff
path: root/tests/sjis-mb
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2010-03-29 09:36:17 +0200
committerPaolo Bonzini <bonzini@gnu.org>2010-03-29 11:08:08 +0200
commit222e774d684d64cfb0713cba8c921eb94e54a91f (patch)
tree9b3a46d585be8a8cfa46c130a465169bccaff2f4 /tests/sjis-mb
parentfaeb8340a6635a8e5e3177da547a938d387ce778 (diff)
downloadgrep-222e774d684d64cfb0713cba8c921eb94e54a91f.tar.gz
tests: add program to detect locales
* 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. Expand comments.
Diffstat (limited to 'tests/sjis-mb')
-rw-r--r--tests/sjis-mb24
1 files changed, 16 insertions, 8 deletions
diff --git a/tests/sjis-mb b/tests/sjis-mb
index 4454ea16..07ef34cf 100644
--- a/tests/sjis-mb
+++ b/tests/sjis-mb
@@ -4,20 +4,27 @@
# 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_
-# % becomes a half-width katakana in SJIS, and an invalid sequence
-# in UTF-8. Use this to try skipping implementations that do not
-# support SJIS.
+locale=ja_JP.SHIFT_JIS
+
+# Sequences used in this test ("%" and "@" become 8-bit characters, while "A"
+# is the real ASCII character for "A"):
+# - "%" becomes an half-width katakana in SJIS, but it is an invalid sequence
+# in UTF-8.
+# - "@@" and "@A" are both valid sequences in SJIS. We try to fool grep into
+# matching "A" against "@A", or mistaking a valid "A" match for the second
+# byte of a multi-byte character.
+
encode() { echo "$1" | tr @% '\203\301'; }
k=0
test_grep_reject() {
k=$(expr $k + 1)
encode "$2" | \
- LC_ALL=ja_JP.SHIFT_JIS \
+ LC_ALL=$locale \
timeout 10s grep $1 $(encode "$3") > out$k 2>&1
test $? = 1
}
@@ -25,13 +32,12 @@ test_grep_reject() {
test_grep() {
k=$(expr $k + 1)
encode "$2" > exp$k
- LC_ALL=ja_JP.SHIFT_JIS \
+ LC_ALL=$locale \
timeout 10s grep $1 $(encode "$3") exp$k > out$k 2>&1
test $? = 0 && compare out$k exp$k
}
-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'
failure_tests=@A
successful_tests='%%AA @AA @A@@A'
@@ -42,6 +48,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