45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package consolekit
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestPrintAboveHook: without a registered printer PrintAbove reports
|
|
// false; with one it forwards the text and its answer; SetPrintAbove(nil)
|
|
// removes it again.
|
|
func TestPrintAboveHook(t *testing.T) {
|
|
t.Cleanup(func() { SetPrintAbove(nil) })
|
|
SetPrintAbove(nil)
|
|
if PrintAbove("x") {
|
|
t.Fatal("PrintAbove without a printer reported true")
|
|
}
|
|
var got []string
|
|
SetPrintAbove(func(s string) bool {
|
|
got = append(got, s)
|
|
return true
|
|
})
|
|
if !PrintAbove("line") || strings.Join(got, ",") != "line" {
|
|
t.Fatalf("PrintAbove with a printer: got %q", got)
|
|
}
|
|
SetPrintAbove(nil)
|
|
if PrintAbove("again") || len(got) != 1 {
|
|
t.Fatalf("PrintAbove after SetPrintAbove(nil): got %q", got)
|
|
}
|
|
}
|
|
|
|
// TestNormalizeAndArgs: Normalize caps the verbosity and lets Quiet imply
|
|
// NoInteraction; Args emits the flags bonfire forwards.
|
|
func TestNormalizeAndArgs(t *testing.T) {
|
|
if g := Normalize(Globals{Verbosity: 9, Quiet: true}); g.Verbosity != MaxVerbosity || !g.NoInteraction {
|
|
t.Errorf("Normalize = %+v", g)
|
|
}
|
|
if g := Normalize(Globals{Verbosity: -2}); g.Verbosity != 0 {
|
|
t.Errorf("Normalize negative = %+v", g)
|
|
}
|
|
g := Globals{Verbosity: 2, Quiet: true, NoInteraction: true, Color: ColorNever, Env: "dev"}
|
|
if got := strings.Join(g.Args(), " "); got != "-vv -q --no-ansi --env=dev" {
|
|
t.Errorf("Args = %q", got)
|
|
}
|
|
}
|