diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-10-21 20:47:02 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-10-21 20:47:02 +0900 |
| commit | 42e0b168e3d75389dfb968aebf9f5629d64782f9 (patch) | |
| tree | e6b430205213c62bc06275c6d84e6037d40f5c3f /internal/verbose/print_test.go | |
| parent | 380d1f45851b7dffb963c51da96a17ba41f3cfb8 (diff) | |
fmsg: produce all output through fmsg
The behaviour of print functions from package fmt is not thread safe. Functions provided by fmsg wrap around Logger methods. This makes prefix much cleaner and makes it easy to deal with future changes to logging.
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/verbose/print_test.go')
| -rw-r--r-- | internal/verbose/print_test.go | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/internal/verbose/print_test.go b/internal/verbose/print_test.go deleted file mode 100644 index d74b70ed..00000000 --- a/internal/verbose/print_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package verbose_test - -import ( - "os" - "os/exec" - "strconv" - "strings" - "testing" - - "git.ophivana.moe/security/fortify/internal/verbose" -) - -const ( - testVerbose = "GO_TEST_VERBOSE" - wantStdout = "fortify: println\nfortify: printf" -) - -func TestPrinter(t *testing.T) { - switch os.Getenv(testVerbose) { - case "0": - verbose.Set(false) - case "1": - verbose.Set(true) - default: - return - } - - verbose.Println("println") - verbose.Printf("%s", "printf") -} - -func TestPrintf_Println(t *testing.T) { - testPrintfPrintln(t, false) - testPrintfPrintln(t, true) - - // make -cover happy - stdout := os.Stdout - t.Cleanup(func() { - os.Stdout = stdout - }) - os.Stdout = nil - verbose.Set(true) - verbose.Printf("") - verbose.Println() -} - -func testPrintfPrintln(t *testing.T, v bool) { - t.Run("start verbose printer with verbose "+strconv.FormatBool(v), func(t *testing.T) { - stdout, stderr := new(strings.Builder), new(strings.Builder) - stdout.Grow(len(wantStdout)) - cmd := exec.Command(os.Args[0], "-test.run=TestPrinter") - cmd.Stdout, cmd.Stderr = stdout, stderr - if v { - cmd.Env = append(cmd.Env, testVerbose+"=1") - } else { - cmd.Env = append(cmd.Env, testVerbose+"=0") - } - if err := cmd.Run(); err != nil { - panic("cannot run printer process: " + err.Error() + " stderr: " + stderr.String()) - } - - if got := stdout.String(); strings.Contains(got, wantStdout) != v { - t.Errorf("Print: got %v; want %t", - got, v) - } - }) -} |
