mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Many compile-time options were broken so that they could not be turned off without causing compile errors and/or regression test failures. This commit now allows the following to be disabled: SHOPT_2DMATCH # two dimensional ${.sh.match} for ${var//pat/str} SHOPT_BGX # one SIGCHLD trap per completed job SHOPT_BRACEPAT # C-shell {...,...} expansions (, required) SHOPT_ESH # emacs/gmacs edit mode SHOPT_HISTEXPAND # csh-style history file expansions SHOPT_MULTIBYTE # multibyte character handling SHOPT_NAMESPACE # allow namespaces SHOPT_STATS # add .sh.stats variable SHOPT_VSH # vi edit mode The following still break ksh when disabled: SHOPT_FIXEDARRAY # fixed dimension indexed array SHOPT_RAWONLY # make viraw the only vi mode SHOPT_TYPEDEF # enable typeset type definitions Compiling without SHOPT_RAWONLY just gives four regression test failures in pty.sh, but turning off SHOPT_FIXEDARRAY and SHOPT_TYPEDEF causes compilation to fail. I've managed to tweak the code to make it compile without those two options, but then dozens of regression test failures occur, often in things nothing directly to do with those options. It looks like the separation between the code for these options and the rest was never properly maintained. Making it possible to disable SHOPT_FIXEDARRAY and SHOPT_TYPEDEF may involve major refactoring and testing and may not be worth it. This commit has far too many tweaks to list. Notables fixes are: src/cmd/ksh93/data/builtins.c, src/cmd/ksh93/data/options.c: - Do not compile in the shell options and documentation for disabled features (braceexpand, emacs/gmacs, vi/viraw), so the shell is not left with no-op options and inaccurate self-doc. src/cmd/ksh93/data/lexstates.c: - Comment the state tables to associte them with their IDs. - In the ST_MACRO table (sh_lexstate9[]), do not make the S_BRACE state for position 123 (ASCII for '{') conditional upon SHOPT_BRACEPAT (brace expansion), otherwise disabling this causes glob patterns of the form {3}(x) (matching 3 x'es) to stop working as well -- and that is ksh globbing, not brace expansion. src/cmd/ksh93/edit/edit.c: ed_read(): - Fixed a bug: SIGWINCH was not handled by the gmacs edit mode. src/cmd/ksh93/sh/name.c: nv_putval(): - The -L/-R left/right adjustment options to typeset do not count zero-width characters. This is the behaviour with SHOPT_MULTIBYTE enabled, regardless of locale. Of course, what a zero-width character is depends on the locale, but control characters are always considered zero-width. So, to avoid a regression, add some fallback code for non-SHOPT_MULTIBYTE builds that skips ASCII control characters (as per iscntrl(3)) so they are still considered to have zero width. src/cmd/ksh93/tests/shtests: - Export the SHOPT_* macros from SHOPT.sh to the tests as environment variables, so the tests can check for them and decide whether or how to run tests based on the compile-time options that the tested binary was presumably compiled with. - Do not run the C.UTF-8 tests if SHOPT_MULTIBYTE is not enabled. src/cmd/ksh93/tests/*.sh: - Add a bunch of checks for SHOPT_* env vars. Since most should have a value 0 (off) or 1 (on), the form ((SHOPT_FOO)) is a convenient way to use them as arithmetic booleans. .github/workflows/ci.yml: - Make GitHub do more testing: run two locale tests (Dutch and Japanese UTF-8 locales), then disable all the SHOPTs that we can currently disable, recompile ksh, and run the tests again.
110 lines
4.1 KiB
Bash
Executable file
110 lines
4.1 KiB
Bash
Executable file
########################################################################
|
|
# #
|
|
# This software is part of the ast package #
|
|
# Copyright (c) 1982-2012 AT&T Intellectual Property #
|
|
# and is licensed under the #
|
|
# Eclipse Public License, Version 1.0 #
|
|
# by AT&T Intellectual Property #
|
|
# #
|
|
# A copy of the License is available at #
|
|
# http://www.eclipse.org/org/documents/epl-v10.html #
|
|
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
|
|
# #
|
|
# Information and Software Systems Research #
|
|
# AT&T Research #
|
|
# Florham Park NJ #
|
|
# #
|
|
# David Korn <dgk@research.att.com> #
|
|
# #
|
|
########################################################################
|
|
function err_exit
|
|
{
|
|
print -u2 -n "\t"
|
|
print -u2 -r ${Command}[$1]: "${@:2}"
|
|
let Errors+=1
|
|
}
|
|
alias err_exit='err_exit $LINENO'
|
|
|
|
Command=${0##*/}
|
|
integer Errors=0
|
|
|
|
[[ -d $tmp && -w $tmp && $tmp == "$PWD" ]] || { err\_exit "$LINENO" '$tmp not set; run this from shtests. Aborting.'; exit 1; }
|
|
|
|
if((!SHOPT_NAMESPACE))
|
|
then err\_exit "$LINENO" 'warning: shell compiled without SHOPT_NAMESPACE; skipping tests'
|
|
exit 0
|
|
fi
|
|
|
|
foo=abc
|
|
typeset -C bar=(x=3 y=4 t=7)
|
|
typeset -A z=([abc]=qqq)
|
|
integer r=9
|
|
function fn
|
|
{
|
|
print global fn $foo
|
|
}
|
|
function fun
|
|
{
|
|
print global fun $foo
|
|
}
|
|
mkdir -p $tmp/global/bin $tmp/local/bin
|
|
cat > $tmp/global/xfun <<- \EOF
|
|
function xfun
|
|
{
|
|
print xfun global $foo
|
|
}
|
|
EOF
|
|
cat > $tmp/local/xfun <<- \EOF
|
|
function xfun
|
|
{
|
|
print xfun local $foo
|
|
}
|
|
EOF
|
|
chmod +x "$tmp/global/xfun" "$tmp/local/xfun"
|
|
print 'print local prog $1' > $tmp/local/bin/run
|
|
print 'print global prog $1' > $tmp/global/bin/run
|
|
chmod +x "$tmp/local/bin/run" "$tmp/global/bin/run"
|
|
PATH=$tmp/global/bin:$PATH
|
|
FPATH=$tmp/global
|
|
|
|
namespace x
|
|
{
|
|
foo=bar
|
|
typeset -C bar=(x=1 y=2 z=3)
|
|
typeset -A z=([qqq]=abc)
|
|
function fn
|
|
{
|
|
print local fn $foo
|
|
}
|
|
[[ $(fn) == 'local fn bar' ]] || err_exit 'fn inside namespace should run local function'
|
|
[[ $(fun) == 'global fun abc' ]] || err_exit 'global fun run from namespace not working'
|
|
(( r == 9 )) || err_exit 'global variable r not set in namespace'
|
|
false
|
|
[[ ${z[qqq]} == abc ]] || err_exit 'local array element not correct'
|
|
[[ ${z[abc]} == '' ]] || err_exit 'global array element should not be visible when local element exists'
|
|
[[ ${bar.y} == 2 ]] || err_exit 'local variable bar.y not found'
|
|
[[ ${bar.t} == '' ]] || err_exit 'global bar.t should not be visible'
|
|
function runxrun
|
|
{
|
|
xfun
|
|
}
|
|
function runrun
|
|
{
|
|
run $1
|
|
}
|
|
PATH=$tmp/local/bin:/bin
|
|
FPATH=$tmp/local
|
|
[[ $(runxrun) == 'xfun local bar' ]] || err_exit 'local function on FPATH failed'
|
|
[[ $(runrun $foo) == 'local prog bar' ]] || err_exit 'local binary on PATH failed'
|
|
}
|
|
[[ $(fn) == 'global fn abc' ]] || err_exit 'fn outside namespace should run global function'
|
|
[[ $(.x.fn) == 'local fn bar' ]] || err_exit 'namespace function called from global failed'
|
|
[[ ${z[abc]} == qqq ]] || err_exit 'global associative array should not be affected by definition in namespace'
|
|
[[ ${bar.y} == 4 ]] || err_exit 'global compound variable should not be affected by definition in namespace'
|
|
[[ ${bar.z} == '' ]] || err_exit 'global compound variable should not see elements in namespace'
|
|
[[ $(xfun) == 'xfun global abc' ]] || err_exit 'global function on FPATH failed'
|
|
[[ $(run $foo) == 'global prog abc' ]] || err_exit 'global binary on PATH failed'
|
|
false
|
|
[[ $(.x.runxrun) == 'xfun local bar' ]] || err_exit 'namespace function on FPATH failed'
|
|
|
|
exit $((Errors<125?Errors:125))
|