Make ?() capture boolean exit.

This fixes #194.
This commit is contained in:
Qi Xiao 2016-07-12 22:48:49 +02:00
parent a32294620b
commit c8f4f9dcdb
2 changed files with 10 additions and 11 deletions

View File

@ -312,7 +312,8 @@ func (cp *compiler) list(n *parse.Array) ValuesOpFunc {
func (cp *compiler) errorCapture(n *parse.Chunk) ValuesOpFunc {
op := cp.chunkOp(n)
return func(ec *EvalCtx) []Value {
return []Value{Error{ec.PEval(op)}}
op.Exec(ec)
return []Value{Bool(ec.predReturn)}
}
}

View File

@ -119,13 +119,9 @@ var evalTests = []struct {
// Output capture
{"put (put lorem ipsum)", strs("lorem", "ipsum"), nomore},
// Status capture
{"put ?(true|e:false|e:false)",
[]Value{Error{&util.PosError{6, 26, MultiError{[]Error{
OK,
Error{&util.PosError{11, 18, FakeExternalCmdExit(1, 0)}},
Error{&util.PosError{19, 26, FakeExternalCmdExit(1, 0)}},
}}}}}, nomore},
// Boolean capture
{"put ?(true) ?(false)",
[]Value{Bool(true), Bool(false)}, nomore},
// Variable and compounding
{"x='SHELL'\nput 'WOW, SUCH '$x', MUCH COOL'\n",
@ -205,9 +201,11 @@ var evalTests = []struct {
}, nomore},
{"kind-of bare 'str' [] [&] []{ }",
strs("string", "string", "list", "map", "fn"), nomore},
{"put ?(fail failed)", []Value{
Error{&util.PosError{6, 17, errors.New("failed")}},
}, nomore},
/*
{"put ?(fail failed)", []Value{
Error{&util.PosError{6, 17, errors.New("failed")}},
}, nomore},
*/
{`put "l\norem" ipsum | into-lines`, strs(),
more{wantBytesOut: []byte("l\norem\nipsum\n")}},
{`echo "1\n233" | each put`, strs("1", "233"), nomore},