Skip to content

Commit

Permalink
Check for systems where "x" is a known locale
Browse files Browse the repository at this point in the history
OpenBSD accepts "x" as an alias of "C", and I can't use `locale -a` to
detect this.  If $(uname) is OpenBSD, then use "x.x" as the unknown
locale.

Most other systems agree that "x" is unknown.  If `locale -a` shows
that someone added the "x" locale, then skip the test.

Partial fix for #483
  • Loading branch information
kernigh authored and krader1961 committed Apr 28, 2018
1 parent b75dab7 commit 02b52a7
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/cmd/ksh93/tests/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -704,22 +704,42 @@ do
log_error "unset $v; : \$$v failed"
fi
done
x=x
for v in LC_ALL LC_CTYPE LC_MESSAGES LC_COLLATE LC_NUMERIC
do
nameref r=$v
unset $v
[[ $r ]] && log_error "unset $v failed -- expected '', got '$r'"
d=$($SHELL -c "$v=$x" 2>&1)
[[ $d ]] || log_error "$v=$x failed -- expected locale diagnostic"
{ g=$( r=$x; print -- $r ); } 2>/dev/null
[[ $g == '' ]] || log_error "$v=$x failed -- expected '', got '$g'"
{ g=$( r=C; r=$x; print -- $r ); } 2>/dev/null
[[ $g == 'C' ]] || log_error "$v=C; $v=$x failed -- expected 'C', got '$g'"
done
PATH=$path
# $x must be an unknown locale.
case "$(uname)" in
OpenBSD)
# "x" acts as a known alias of "C", but "x.x" is unknown (see
# https://man.openbsd.org/setlocale). For worse, `locale -a` doesn't
# list "x", so `locale -a | grep -q '^x$'` doesn't work.
x=x.x
;;
*)
# Most systems agree that "x" is an unknown locale.
if locale -a | grep -q '^x$'; then
# Someone added "x" using localedef(1)?
log_warning "skipping test: 'x' is a known locale"
unset x
else
x=x
fi
;;
esac

if [[ -n $x ]]; then
for v in LC_ALL LC_CTYPE LC_MESSAGES LC_COLLATE LC_NUMERIC; do
nameref r=$v
unset $v
[[ $r ]] && log_error "unset $v failed -- expected '', got '$r'"
d=$($SHELL -c "$v=$x" 2>&1)
[[ $d ]] || log_error "$v=$x failed -- expected locale diagnostic"
{ g=$( r=$x; print -- $r ); } 2>/dev/null
[[ $g == '' ]] || log_error "$v=$x failed -- expected '', got '$g'"
{ g=$( r=C; r=$x; print -- $r ); } 2>/dev/null
[[ $g == 'C' ]] || log_error "$v=C; $v=$x failed -- expected 'C', got '$g'"
done
fi

cd $TEST_DIR

print print -n zzz > zzz
Expand Down

0 comments on commit 02b52a7

Please sign in to comment.