go.dedis.ch/onet/v3@v3.2.11-0.20210930124529-e36530bca7ef/log/ui_test.go (about) 1 package log 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "golang.org/x/xerrors" 8 ) 9 10 func TestMain(m *testing.M) { 11 OutputToBuf() 12 MainTest(m) 13 } 14 15 func TestInfo(t *testing.T) { 16 SetDebugVisible(FormatPython) 17 Info("Python") 18 assert.True(t, containsStdOut("[+] Python\n")) 19 SetDebugVisible(FormatNone) 20 Info("None") 21 assert.True(t, containsStdOut("None\n")) 22 Info("None", "Python") 23 assert.True(t, containsStdOut("None Python\n")) 24 SetDebugVisible(1) 25 } 26 27 func TestError(t *testing.T) { 28 SetDebugVisible(1) 29 Error(xerrors.New("error with stack")) 30 assert.Contains(t, GetStdErr(), "/log/ui_test.go:") 31 32 Error(xerrors.New("test"), "and another message") 33 assert.NotContains(t, GetStdErr(), "/log/ui_test.go:") 34 } 35 36 func TestLvl(t *testing.T) { 37 SetDebugVisible(1) 38 Info("TestLvl") 39 assert.Contains(t, GetStdOut(), "I : fake_name.go:0 (log.TestLvl) - TestLvl\n") 40 Print("TestLvl") 41 assert.Contains(t, GetStdOut(), "I : fake_name.go:0 (log.TestLvl) - TestLvl\n") 42 Warn("TestLvl") 43 assert.Contains(t, GetStdErr(), "W : fake_name.go:0 (log.TestLvl) - TestLvl\n") 44 } 45 46 func TestPanic(t *testing.T) { 47 assert.PanicsWithValue(t, "", func() { 48 Panic() 49 }) 50 assert.PanicsWithValue(t, "the number is 1", func() { 51 Panic("the number is ", 1) 52 }) 53 }