test: make cmd testable
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/goplus/llgo/compiler/cmd/internal/base"
|
||||
"github.com/goplus/llgo/compiler/internal/build"
|
||||
"github.com/goplus/llgo/compiler/internal/mockable"
|
||||
)
|
||||
|
||||
// llgo build
|
||||
@@ -47,6 +48,6 @@ func runCmd(cmd *base.Command, args []string) {
|
||||
_, err := build.Do(args, conf)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
mockable.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/goplus/llgo/compiler/cmd/internal/base"
|
||||
"github.com/goplus/llgo/compiler/internal/mockable"
|
||||
)
|
||||
|
||||
// Help implements the 'help' command.
|
||||
@@ -49,7 +50,7 @@ Args:
|
||||
helpSuccess += " " + strings.Join(args[:i], " ")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "llgo help %s: unknown help topic. Run '%s'.\n", strings.Join(args, " "), helpSuccess)
|
||||
os.Exit(2)
|
||||
mockable.Exit(2)
|
||||
}
|
||||
|
||||
if len(cmd.Commands) > 0 {
|
||||
@@ -98,7 +99,7 @@ func tmpl(w io.Writer, text string, data interface{}) {
|
||||
if ew.err != nil {
|
||||
// I/O error writing. Ignore write on closed pipe.
|
||||
if strings.Contains(ew.err.Error(), "pipe") {
|
||||
os.Exit(1)
|
||||
mockable.Exit(1)
|
||||
}
|
||||
log.Fatalf("writing output: %v", ew.err)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/goplus/llgo/compiler/cmd/internal/base"
|
||||
"github.com/goplus/llgo/compiler/internal/build"
|
||||
"github.com/goplus/llgo/compiler/internal/mockable"
|
||||
)
|
||||
|
||||
// llgo install
|
||||
@@ -40,6 +41,6 @@ func runCmd(cmd *base.Command, args []string) {
|
||||
_, err := build.Do(args, conf)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
mockable.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
"github.com/goplus/llgo/compiler/cmd/internal/base"
|
||||
"github.com/goplus/llgo/compiler/internal/build"
|
||||
"github.com/goplus/llgo/compiler/internal/mockable"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -68,7 +69,7 @@ func runCmdEx(_ *base.Command, args []string, mode build.Mode) {
|
||||
_, err = build.Do(args, conf)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
mockable.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user