mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
Add more tests to core/swag_test.go
Trivial, but bumps coverage for core from 79.3% to 94.8%. (Local coverage reporting seems to differ from coveralls)
This commit is contained in:
parent
ca978cc445
commit
45dc257aad
1 changed files with 37 additions and 1 deletions
|
@ -1,6 +1,22 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsDumbTerminal(t *testing.T) {
|
||||||
|
term := os.Getenv("TERM")
|
||||||
|
os.Setenv("TERM", "dumb")
|
||||||
|
if !isDumbTerminal() {
|
||||||
|
t.Fatal("Expected false when TERM==dumb")
|
||||||
|
}
|
||||||
|
os.Setenv("TERM", "")
|
||||||
|
if !isDumbTerminal() {
|
||||||
|
t.Fatal("Expected false when TERM empty")
|
||||||
|
}
|
||||||
|
os.Setenv("TERM", term)
|
||||||
|
}
|
||||||
|
|
||||||
func TestW(t *testing.T) {
|
func TestW(t *testing.T) {
|
||||||
exp := "<3\033[0m"
|
exp := "<3\033[0m"
|
||||||
|
@ -57,3 +73,23 @@ func TestYellow(t *testing.T) {
|
||||||
t.Fatalf("expected path '%s', got '%s'", exp, got)
|
t.Fatalf("expected path '%s', got '%s'", exp, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInitSwag(t *testing.T) {
|
||||||
|
// Run after other tests to avoid breaking globals
|
||||||
|
// Test InitSwag unsets globals when set
|
||||||
|
BOLD = "\033[1m"
|
||||||
|
InitSwag(true)
|
||||||
|
if BOLD != "" {
|
||||||
|
t.Fatal("expected BOLD to be empty string")
|
||||||
|
}
|
||||||
|
term := os.Getenv("TERM")
|
||||||
|
os.Setenv("TERM", "dumb")
|
||||||
|
BOLD = "\033[1m"
|
||||||
|
InitSwag(false)
|
||||||
|
if BOLD != "" {
|
||||||
|
t.Fatal("expected BOLD to be empty string")
|
||||||
|
}
|
||||||
|
os.Setenv("TERM", term)
|
||||||
|
// Would be good to test BOLD *isn't* unset when we have a TTY
|
||||||
|
// but less trivial to stub os.File.Fd() without complicating architecture
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue