Documentation
¶
Index ¶
- Constants
- Variables
- func AppendTestNameOff(b *strings.Builder)
- func AppendTestNameOn(b *strings.Builder)
- func Bad(s string, args ...any) string
- func BadUsage(usage string, param any, pos int, kind bool) string
- func FromEnv(env, defaultColor string) (string, string, string)
- func Init()
- func On() bool
- func SaveState(on ...bool) func()
- func TooManyParams(usage string) string
- func UnBad(s string) string
Constants ¶
const ( // EnvColor is the name of the environment variable allowing to // enable/disable coloring feature. EnvColor = "TESTDEEP_COLOR" // EnvColorTestName is the name of the environment variable // containing the color of test names in error reports. EnvColorTestName = "TESTDEEP_COLOR_TEST_NAME" // EnvColorTitle is the name of the environment variable // containing the color of failure reason in error reports. EnvColorTitle = "TESTDEEP_COLOR_TITLE" // EnvColorOK is the name of the environment variable // containing the color of "expected" in error reports. EnvColorOK = "TESTDEEP_COLOR_OK" // EnvColorBad is the name of the environment variable // containing the color of "got" in error reports. EnvColorBad = "TESTDEEP_COLOR_BAD" )
Variables ¶
var ( // TestNameOn contains the ANSI color escape sequence to turn test // name color on. TestNameOn string // TestNameOff contains the ANSI color escape sequence to turn test // name color off. TestNameOff string // TitleOn contains the ANSI color escape sequence to turn title color on. TitleOn string // TitleOff contains the ANSI color escape sequence to turn title color off. TitleOff string // OKOn contains the ANSI color escape sequence to turn "expected" color on. OKOn string // OKOnBold contains the ANSI color escape sequence to turn // "expected" color and bold on. OKOnBold string // OKOff contains the ANSI color escape sequence to turn "expected" color off. OKOff string // BadOn contains the ANSI color escape sequence to turn "got" color on. BadOn string // BadOnBold contains the ANSI color escape sequence to turn "got" // color and bold on. BadOnBold string // BadOff contains the ANSI color escape sequence to turn "got" color off. BadOff string )
Functions ¶
func AppendTestNameOff ¶
AppendTestNameOff disables test name color in b.
func AppendTestNameOn ¶
AppendTestNameOn enables test name color in b.
func Bad ¶
Bad returns a string surrounded by BAD color. If len(args) is > 0, s and args are given to fmt.Sprintf.
Typically used in panic() when the user made a mistake.
func BadUsage ¶
BadUsage returns a string surrounded by BAD color to notice the user he passes a bad parameter to a function. Typically used in a panic().
func FromEnv ¶
FromEnv returns the light, bold and end ANSI sequences for the color contained in the environment variable env. defaultColor is used if the environment variable does exist or is empty.
If coloring is disabled, returns "", "", "".
func Init ¶
func Init()
Init initializes all the colors from the environment. It can be called several times concurrently, but only the first call is effective.
func SaveState ¶
func SaveState(on ...bool) func()
SaveState saves the "TESTDEEP_COLOR" environment variable value, sets it to "on" (if true passed as on) or "off" (if on not passed or set to false), resets the colors initialization and returns a function to be called in a defer statement. Only intended to be used in tests like:
defer color.SaveState()()
It is not thread-safe.
func TooManyParams ¶
TooManyParams returns a string surrounded by BAD color to notice the user he called a variadic function with too many parameters. Typically used in a panic().
Types ¶
This section is empty.