Add invalid input node in testdata

This commit is contained in:
lash 2023-04-06 10:55:11 +01:00
parent a3073f6189
commit 7c1bc78c98
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 19 additions and 6 deletions

View File

@ -43,12 +43,11 @@ func main() {
in = strings.TrimSpace(in)
running, err = en.Exec([]byte(in), ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "execution terminated: %v\n", err)
fmt.Fprintf(os.Stderr, "unexpected termination: %v\n", err)
os.Exit(1)
}
b := bytes.NewBuffer(nil)
en.WriteResult(b)
fmt.Println(b.String())
}
}

View File

@ -86,13 +86,24 @@ func baz() error {
return out("baz", b, tpl)
}
func defaultCatch() error {
b := []byte{}
b = vm.NewLine(b, vm.MOUT, []string{"0", "back"}, nil, nil)
b = vm.NewLine(b, vm.HALT, nil, nil, nil)
b = vm.NewLine(b, vm.MOVE, []string{"_"}, nil, nil)
tpl := "invalid input"
return out("_catch", b, tpl)
}
func generate() error {
err := os.MkdirAll(DataDir, 0755)
if err != nil {
return err
}
fns := []genFunc{root, foo, bar, baz}
fns := []genFunc{root, foo, bar, baz, defaultCatch}
for _, fn := range fns {
err = fn()
if err != nil {

View File

@ -94,8 +94,6 @@ func RunDeadCheck(b []byte, st *state.State, rs resource.Resource, ctx context.C
return b, fmt.Errorf("dead runner with no current location")
}
b = NewLine(nil, MOVE, []string{"_catch"}, nil, nil)
b = NewLine(b, HALT, nil, nil, nil)
b = NewLine(b, MOVE, []string{location}, nil, nil)
log.Printf("code is now %x", b)
return b, nil
}
@ -180,7 +178,12 @@ func RunMove(b []byte, st *state.State, rs resource.Resource, ctx context.Contex
if err != nil {
return b, err
}
if sym == "_" {
st.Up()
sym = st.Where()
} else {
st.Down(sym)
}
code, err := rs.GetCode(sym)
if err != nil {
return b, err