-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
56 lines (44 loc) · 1.22 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package test
import (
"bufio"
"fmt"
"os"
"testing"
)
// Logf writes to stdout and flushes. Applicable for when t.Logf can't be used.
func Logf(template string, args ...interface{}) {
f := bufio.NewWriter(os.Stdout)
_, err := f.WriteString(fmt.Sprintf(template, args...))
if err != nil {
panic(fmt.Sprintf("writing to output failed: %s", err))
}
err = f.WriteByte('\n')
if err != nil {
panic(fmt.Sprintf("writing to output failed: %s", err))
}
err = f.Flush()
if err != nil {
panic(fmt.Sprintf("writing to output failed: %s", err))
}
}
// Failf - as t.Fatalf is not goroutine safe, this function behaves like t.Fatalf.
func Failf(t *testing.T, template string, args ...interface{}) {
f := bufio.NewWriter(os.Stdout)
_, err := f.WriteString(fmt.Sprintf(template, args...))
if err != nil {
panic(fmt.Sprintf("writing to output failed: %s", err))
}
err = f.WriteByte('\n')
if err != nil {
panic(fmt.Sprintf("writing to output failed: %s", err))
}
err = f.Flush()
if err != nil {
panic(fmt.Sprintf("writing to output failed: %s", err))
}
t.Fail()
}