1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-06-01 12:56:04 +02:00

25571: when parsing use line numbers for the start of a token, not the end

add test and move debug trap tests to new file
This commit is contained in:
Peter Stephenson 2008-08-31 19:50:47 +00:00
parent 2c52a13aa5
commit 2e3363ef7d
6 changed files with 138 additions and 89 deletions

View File

@ -1,3 +1,10 @@
2008-08-31 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 25571: Src/lex.c, Src/parse.c, Test/.distfiles,
Test/C03traps.ztst, Test/C05debug.ztst: make line numbers when
parsing reflect the start of a parsed token rather than the end;
add a test and move debug trap tests to a separate file.
2008-08-31 Clint Adams <clint@zsh.org>
* Frank Terbeck: 25561: Completion/Unix/Command/_git: fix quoting

View File

@ -46,6 +46,17 @@ mod_export int tok;
/**/
mod_export int tokfd;
/*
* Line number at which the first character of a token was found.
* We always set this in gettok(), which is always called from
* yylex() unless we have reached an error. So it is always
* valid when parsing. It is not useful during execution
* of the parsed structure.
*/
/**/
zlong toklineno;
/* lexical analyzer error flag */
/**/
@ -211,6 +222,7 @@ struct lexstack {
unsigned char *cstack;
int csp;
zlong toklineno;
};
static struct lexstack *lstack = NULL;
@ -269,6 +281,7 @@ lexsave(void)
ls->ecsoffs = ecsoffs;
ls->ecssub = ecssub;
ls->ecnfunc = ecnfunc;
ls->toklineno = toklineno;
cmdsp = 0;
inredir = 0;
hdocs = NULL;
@ -333,6 +346,7 @@ lexrestore(void)
ecssub = lstack->ecssub;
ecnfunc = lstack->ecnfunc;
hlinesz = lstack->hlinesz;
toklineno = lstack->toklineno;
errflag = 0;
ln = lstack->next;
@ -661,6 +675,7 @@ gettok(void)
beginning:
tokstr = NULL;
while (iblank(c = hgetc()) && !lexstop);
toklineno = lineno;
if (lexstop)
return (errflag) ? LEXERR : ENDINPUT;
isfirstln = 0;

View File

@ -721,7 +721,7 @@ static int
par_pline(int *complex)
{
int p;
zlong line = lineno;
zlong line = toklineno;
p = ecadd(0);

View File

@ -17,6 +17,7 @@ C01arith.ztst
C02cond.ztst
C03traps.ztst
C04funcdef.ztst
C05debug.ztst
D01prompt.ztst
D02glob.ztst
D03procsubst.ztst

View File

@ -350,94 +350,6 @@
>trap
>Working 0
unsetopt DEBUG_BEFORE_CMD
debug-trap-bug1() {
setopt localtraps
print "print bug file here" >bug-file
print "print this is line one
print this is line two
print this is line three
print and this is line fifty-nine." >bug-file2
function debug_trap_handler {
print $functrace[1]
do_bug
}
function do_bug {
. ./bug-file
}
trap 'echo EXIT hit' EXIT
trap 'debug_trap_handler' DEBUG
. ./bug-file2
}
debug-trap-bug1
0: Relationship between traps and sources
>debug-trap-bug1:15
>bug file here
>this is line one
>./bug-file2:1
>bug file here
>this is line two
>./bug-file2:2
>bug file here
>this is line three
>./bug-file2:3
>bug file here
>and this is line fifty-nine.
>./bug-file2:4
>bug file here
>debug-trap-bug1:16
>bug file here
>EXIT hit
cat >zsh-trapreturn-bug2 <<-'HERE'
cmd='./fdasfsdafd'
[[ -x $cmd ]] && rm $cmd
set -o DEBUG_BEFORE_CMD
trap '[[ $? -ne 0 ]] && exit 0' DEBUG
$cmd # invalid command
# Failure
exit 10
HERE
$ZTST_testdir/../Src/zsh -f ./zsh-trapreturn-bug2
0: trapreturn handling bug is properly fixed
?./zsh-trapreturn-bug2:5: no such file or directory: ./fdasfsdafd
fn() {
setopt localtraps localoptions debugbeforecmd
trap '(( LINENO == 4 )) && setopt errexit' DEBUG
print $LINENO three
print $LINENO four
print $LINENO five
[[ -o errexit ]] && print "Hey, ERREXIT is set!"
}
fn
1:Skip line from DEBUG trap
>3 three
>5 five
# Assignments are a special case, since they use a simpler
# wordcode type, so we need to test skipping them separately.
fn() {
setopt localtraps localoptions debugbeforecmd
trap '(( LINENO == 4 )) && setopt errexit' DEBUG
x=three
x=four
print $LINENO $x
[[ -o errexit ]] && print "Hey, ERREXIT is set!"
}
fn
1:Skip assignment from DEBUG trap
>5 three
fn() {
setopt localtraps localoptions debugbeforecmd
trap 'print $LINENO' DEBUG
[[ a = a ]] && print a is ok
}
fn
0:line numbers of complex sublists
>3
>a is ok
%clean

114
Test/C05debug.ztst Normal file
View File

@ -0,0 +1,114 @@
%prep
setopt localtraps
%test
unsetopt DEBUG_BEFORE_CMD
debug-trap-bug1() {
setopt localtraps
print "print bug file here" >bug-file
print "print this is line one
print this is line two
print this is line three
print and this is line fifty-nine." >bug-file2
function debug_trap_handler {
print $functrace[1]
do_bug
}
function do_bug {
. ./bug-file
}
trap 'echo EXIT hit' EXIT
trap 'debug_trap_handler' DEBUG
. ./bug-file2
}
debug-trap-bug1
0: Relationship between traps and sources
>debug-trap-bug1:15
>bug file here
>this is line one
>./bug-file2:1
>bug file here
>this is line two
>./bug-file2:2
>bug file here
>this is line three
>./bug-file2:3
>bug file here
>and this is line fifty-nine.
>./bug-file2:4
>bug file here
>debug-trap-bug1:16
>bug file here
>EXIT hit
cat >zsh-trapreturn-bug2 <<-'HERE'
cmd='./fdasfsdafd'
[[ -x $cmd ]] && rm $cmd
set -o DEBUG_BEFORE_CMD
trap '[[ $? -ne 0 ]] && exit 0' DEBUG
$cmd # invalid command
# Failure
exit 10
HERE
$ZTST_testdir/../Src/zsh -f ./zsh-trapreturn-bug2
0: trapreturn handling bug is properly fixed
?./zsh-trapreturn-bug2:5: no such file or directory: ./fdasfsdafd
fn() {
setopt localtraps localoptions debugbeforecmd
trap '(( LINENO == 4 )) && setopt errexit' DEBUG
print $LINENO three
print $LINENO four
print $LINENO five
[[ -o errexit ]] && print "Hey, ERREXIT is set!"
}
fn
1:Skip line from DEBUG trap
>3 three
>5 five
# Assignments are a special case, since they use a simpler
# wordcode type, so we need to test skipping them separately.
fn() {
setopt localtraps localoptions debugbeforecmd
trap '(( LINENO == 4 )) && setopt errexit' DEBUG
x=three
x=four
print $LINENO $x
[[ -o errexit ]] && print "Hey, ERREXIT is set!"
}
fn
1:Skip assignment from DEBUG trap
>5 three
fn() {
setopt localtraps localoptions debugbeforecmd
trap 'print $LINENO' DEBUG
[[ a = a ]] && print a is ok
}
fn
0:line numbers of complex sublists
>3
>a is ok
fn() {
setopt localtraps localoptions debugbeforecmd
trap 'print $LINENO' DEBUG
print before
x=' first
second
third'
print $x
}
fn
0:line numbers of multiline assignments
>3
>before
>4
>7
> first
> second
> third