diff options
-rw-r--r-- | jim.c | 10 | ||||
-rw-r--r-- | tests/leval.test | 69 |
2 files changed, 77 insertions, 2 deletions
@@ -11045,6 +11045,7 @@ static Jim_Obj *JimInterpolateTokens(Jim_Interp *interp, const ScriptToken * tok Jim_Obj *sintv[JIM_EVAL_SINTV_LEN]; Jim_Obj *objPtr; char *s; + const char *error_action = NULL; if (tokens <= JIM_EVAL_SINTV_LEN) intv = sintv; @@ -11064,14 +11065,16 @@ static Jim_Obj *JimInterpolateTokens(Jim_Interp *interp, const ScriptToken * tok tokens = i; continue; } - /* XXX: Should probably set an error about break outside loop */ + error_action = "break"; /* fall through to error */ case JIM_CONTINUE: if (flags & JIM_SUBST_FLAG) { intv[i] = NULL; continue; } - /* XXX: Ditto continue outside loop */ + if (!error_action) { + error_action = "continue"; + } /* fall through to error */ default: while (i--) { @@ -11080,6 +11083,9 @@ static Jim_Obj *JimInterpolateTokens(Jim_Interp *interp, const ScriptToken * tok if (intv != sintv) { Jim_Free(intv); } + if (error_action) { + Jim_SetResultFormatted(interp, "invoked \"%s\" outside of a loop", error_action); + } return NULL; } Jim_IncrRefCount(intv[i]); diff --git a/tests/leval.test b/tests/leval.test index 1d924d1..fed6733 100644 --- a/tests/leval.test +++ b/tests/leval.test @@ -56,4 +56,73 @@ test leval-1.7 {expand} -body { } } -result {1 2 1 2 3 4 5 6 7} +test leval-1.8 {empty case} -body { + leval { + # Nothing + } +} -result {} + +test leval-1.9 {backslash escapes} -body { + leval { + # char escapes + \r\n\t + # unicode escapes + \u00b5 + # hex escapes + \x41\x42 + } +} -result [list \r\n\t \u00b5 AB] + +test leval-2.1 {error, missing [} -body { + leval { + # Missing bracket + [string cat + } +} -returnCodes error -result {unmatched "["} + +test leval-2.2 {error, invalid command} -body { + leval { + a + [dummy] + b + } +} -returnCodes error -result {invalid command name "dummy"} + +test leval-2.3 {error, unset variable} -body { + leval { + a + $doesnotexist + b + } +} -returnCodes error -result {can't read "doesnotexist": no such variable} + +test leval-2.4 {break} -body { + leval { + a + [break] + b + } +} -returnCodes error -result {invoked "break" outside of a loop} + +test leval-2.5 {continue} -body { + leval { + a + [continue] + b + } +} -returnCodes error -result {invoked "continue" outside of a loop} + +test leval-3.1 {preservation of line numbers} -body { + set x abc + set src1 [info source $x] + set list [leval { + a + $x + b + }] + if {[info source [lindex $list 1]] ne [info source $x]} { + error "source does not match + } +} -result {} + testreport |