From 66338896329fcf7fc1d847063a7c9acd09f5b13c Mon Sep 17 00:00:00 2001 From: Krzysztof Jurewicz Date: Tue, 12 Dec 2017 21:06:56 +0100 Subject: [PATCH] Short-circuit assertions in test command --- cmd/abci-cli/abci-cli.go | 64 ++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index 47ffd6bc1..32bf2af80 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -300,49 +300,37 @@ func persistentArgs(line []byte) []string { //-------------------------------------------------------------------------------- -func or(err1 error, err2 error) error { - if err1 == nil { - return err2 +func compose(fs []func() error) error { + if len(fs) == 0 { + return nil } else { - return err1 + err := fs[0]() + if err == nil { + return compose(fs[1:]) + } else { + return err + } } } func cmdTest(cmd *cobra.Command, args []string) error { - fmt.Println("Running tests") - - err := servertest.InitChain(client) - fmt.Println("") - err = or(err, servertest.SetOption(client, "serial", "on")) - fmt.Println("") - err = or(err, servertest.Commit(client, nil)) - fmt.Println("") - err = or(err, servertest.DeliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil)) - fmt.Println("") - err = or(err, servertest.Commit(client, nil)) - fmt.Println("") - err = or(err, servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeOK, nil)) - fmt.Println("") - err = or(err, servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})) - fmt.Println("") - err = or(err, servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil)) - fmt.Println("") - err = or(err, servertest.DeliverTx(client, []byte{0x01}, code.CodeTypeOK, nil)) - fmt.Println("") - err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x02}, code.CodeTypeOK, nil)) - fmt.Println("") - err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x03}, code.CodeTypeOK, nil)) - fmt.Println("") - err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x00, 0x04}, code.CodeTypeOK, nil)) - fmt.Println("") - err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil)) - fmt.Println("") - err = or(err, servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})) - - if err != nil { - return errors.New("Some checks didn't pass, please inspect stdout to see the exact failures.") - } - return nil + return compose( + []func() error{ + func() error { return servertest.InitChain(client) }, + func() error { return servertest.SetOption(client, "serial", "on") }, + func() error { return servertest.Commit(client, nil) }, + func() error { return servertest.DeliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil) }, + func() error { return servertest.Commit(client, nil) }, + func() error { return servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeOK, nil) }, + func() error { return servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1}) }, + func() error { return servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil) }, + func() error { return servertest.DeliverTx(client, []byte{0x01}, code.CodeTypeOK, nil) }, + func() error { return servertest.DeliverTx(client, []byte{0x00, 0x02}, code.CodeTypeOK, nil) }, + func() error { return servertest.DeliverTx(client, []byte{0x00, 0x03}, code.CodeTypeOK, nil) }, + func() error { return servertest.DeliverTx(client, []byte{0x00, 0x00, 0x04}, code.CodeTypeOK, nil) }, + func() error { return servertest.DeliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil) }, + func() error { return servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})}, + }) } func cmdBatch(cmd *cobra.Command, args []string) error {