mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
f91a3b87c1
It's pretty common to want to apply the various fmt.Fprint... functions to our two output streams, and so to make that much less noisy at the callsite here we have a small number of very thin wrappers around the underlying fmt package functionality. Although we're aiming to not have too much abstraction in this "terminal" package, this seems justified in that it is only a very thin wrapper around functionality that most Go programmers are already familiar with, and so the risk of this causing any surprises is low and the improvement to readability of callers seems worth it.
39 lines
786 B
Go
39 lines
786 B
Go
package terminal
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
)
|
|
|
|
func TestStreamsFmtHelpers(t *testing.T) {
|
|
streams, close := StreamsForTesting(t)
|
|
|
|
streams.Print("stdout print ", 5, "\n")
|
|
streams.Eprint("stderr print ", 6, "\n")
|
|
streams.Println("stdout println", 7)
|
|
streams.Eprintln("stderr println", 8)
|
|
streams.Printf("stdout printf %d\n", 9)
|
|
streams.Eprintf("stderr printf %d\n", 10)
|
|
|
|
outp := close(t)
|
|
|
|
gotOut := outp.Stdout()
|
|
wantOut := `stdout print 5
|
|
stdout println 7
|
|
stdout printf 9
|
|
`
|
|
if diff := cmp.Diff(wantOut, gotOut); diff != "" {
|
|
t.Errorf("wrong stdout\n%s", diff)
|
|
}
|
|
|
|
gotErr := outp.Stderr()
|
|
wantErr := `stderr print 6
|
|
stderr println 8
|
|
stderr printf 10
|
|
`
|
|
if diff := cmp.Diff(wantErr, gotErr); diff != "" {
|
|
t.Errorf("wrong stderr\n%s", diff)
|
|
}
|
|
}
|