1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/cmd/ksh93/tests
Johnothan King f7213f03a2 Fix multiple bugs when using 'alias -p' to print aliases (#398)
This commit was originally intended to fix just one bug with shcomp's
handling of 'alias -p', but while fixing that I found a large number
of related issues in the alias command's -p, -t and -x options. The
current patch provides bugfixes for all of the bugs listed below:

1) Listing aliases in a script with 'alias -p' or 'alias' broke
   shcomp's bytecode output:
   https://github.com/ksh93/ksh/issues/87#issuecomment-813819122

2) Listing individual aliases with the -p option doesn't work:
      $ alias foo=bar bar=foo
      $ alias foo
      foo=bar
      $ alias -p foo  # No output

3) Listing specific tracked aliases with -pt does not display them
   in a reusable format, but rather adds another tracked alias:
      $ hash -r cat vi
      $ alias -pt vi  # No output
      $ alias -pt rm
      $ alias -t
      cat=/usr/bin/cat
      rm=/usr/bin/rm
      vi=/usr/bin/vi

4) Listing all tracked aliases with -pt does not output them in a
   reusable format (the resulting command printed only creates a
   normal alias, which is different from a tracked alias):
      $ hash -r cat
      $ alias -pt
      alias cat=/usr/bin/cat  # Expected 'alias -t cat'

5) Listing a non-existent alias with -p doesn't cause an error:
      $ unalias -a
      $ alias -p notanalias  # No output
      $ echo $?
      0
      $ alias notanalias
      notanalias: alias not found
      $ echo $?
      1
      $ hash -r
      $ alias -pt notacommand  # No output
      $ echo $?
      0

6) Attempting to list 256 non-existent aliases results in exit
   status zero:
      $ unalias -a
      $ alias $(awk -v ORS= 'BEGIN { for(i=0;i<256;i++) print "x "; }')
      x: alias not found
      --cut error message--
      $ echo $?
      0

Changes:

- typeset.c: Avoid printing anything while shcomp is compiling a
  script. This is needed because the alias command is run by shcomp
  to prevent parsing issues.

- b_alias(): To avoid adding tracked aliases with -pt, set
  tdata.aflag to '+' so that setall() and other related functions
  only list tracked aliases.

- b_alias(): Set tdata.pflag to 1 so that setall() and other
  functions recognize -p was passed.

- print_value(): Add support for listing specific aliases with
  'alias -p'.

- setall(): To avoid any issues with zombie tracked aliases (see also
  the regression tests) ignore tracked alias nodes marked with the
  NV_NOALIAS attribute. This bit is set for tracked alias nodes by
  the nv_rehash() function.

- setall(): For backward compatibility, continue incrementing the
  exit status for each invalid alias and tracked alias passed. This
  was already how alias behaved when listing aliases without -p, so
  using -p shouldn't cause a change in behavior:
      $ unalias -a
      $ alias foo bar
      foo: alias not found
      bar: alias not found
      $ echo $?
      2
  To fix bug 6, the exit status is set to one if an enforced 8-bit
  exit status would be zero.

- print_namval(): Set the prefix to 'alias -t' so that listing
  tracked aliases with 'alias -pt' works correctly.

- data/msg.c and include/name.h: Add an error message for when
  'alias -pt' doesn't find a tracked alias.

- tests/alias.sh: Add a ton of regression tests for the bugs fixed in
  this commit.
2021-12-27 03:49:06 +00:00
..
_common Fix xtrace (shtests -x) for the regression tests 2021-05-14 19:56:11 +02:00
alias.sh Fix multiple bugs when using 'alias -p' to print aliases (#398) 2021-12-27 03:49:06 +00:00
append.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
arith.sh arithmetic: Fix the octal leading zero mess (#337) 2021-11-17 04:28:08 +01:00
arrays.sh Fix various compiler warnings and minor issues (#362) 2021-12-09 06:42:59 +01:00
arrays2.sh nv_associative(): finally use proper check for enum (re: b98e32fc) 2021-11-24 02:06:08 +01:00
attributes.sh Fix xtrace (shtests -x) for the regression tests 2021-05-14 19:56:11 +02:00
basic.sh Minor improvements to the regression tests (#366) 2021-12-09 06:43:39 +01:00
bracket.sh Backport ksh93v- bugfix for [[ 1<2 ]] (#380) 2021-12-17 03:26:41 +01:00
builtins.sh Fix yet more minor bugs related to the regression tests (#389) 2021-12-21 08:01:00 +00:00
case.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
comvar.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
comvario.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
coprocess.sh Various minor capitalization and typo fixes (#371) 2021-12-13 01:49:42 +01:00
cubetype.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
enum.sh Re-fix defining types conditionally or in subshells (re: f508660d) 2021-12-17 01:28:28 +01:00
exit.sh Fix shell exit on function call redirection error (re: 23f2e23) 2021-05-19 06:59:18 +02:00
expand.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
functions.sh Various minor capitalization and typo fixes (#371) 2021-12-13 01:49:42 +01:00
glob.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
grep.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
heredoc.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
io.sh Fix process substitutions printing PIDs in profile scripts (#395) 2021-12-22 13:27:00 +00:00
jobs.sh ...and now make it work with shcomp (re: aed5c6d7) 2021-03-13 19:27:15 +00:00
leaks.sh Release 1.0.0-beta.2 2021-12-17 04:20:04 +01:00
locale.sh more regression test updates (re: 7cdb01f6) 2021-12-16 11:46:17 +01:00
math.sh Fix xtrace (shtests -x) for the regression tests 2021-05-14 19:56:11 +02:00
nameref.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
namespace.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
options.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
path.sh tests/path.sh: update regression test (re: 7cdb01f6) 2021-12-16 09:20:00 +01:00
pointtype.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
pty.sh Do not exit shell on Ctrl+C with SIGINT ignored (re: 7e5fd3e9) 2021-12-16 19:56:46 +01:00
quoting.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
quoting2.sh Fix remaining bug in ${var:-'{}'} (re: d087b031) 2021-05-03 03:14:30 +01:00
readcsv.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
readonly.sh Adjust readonly regression tests for freezes (#267) 2021-04-11 19:57:40 +01:00
recttype.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
restricted.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
return.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
select.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
shtests shtests --posix: ensure consistent locale: unset all LC_* vars 2021-12-27 03:48:27 +00:00
sigchld.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
signal.sh Various minor capitalization and typo fixes (#371) 2021-12-13 01:49:42 +01:00
statics.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
subshell.sh Fix various compiler warnings and minor issues (#362) 2021-12-09 06:42:59 +01:00
substring.sh Minor improvements to the regression tests (#366) 2021-12-09 06:43:39 +01:00
tilde.sh Revert "[1.0 release prep] Remove tilde expansion discipline" 2021-12-09 07:31:37 +01:00
timetype.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
treemove.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
types.sh Fix yet more minor bugs related to the regression tests (#389) 2021-12-21 08:01:00 +00:00
variables.sh Fix yet more minor bugs related to the regression tests (#389) 2021-12-21 08:01:00 +00:00
vartree1.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
vartree2.sh Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00