Skip to content

Commit

Permalink
suppress output for spammy test
Browse files Browse the repository at this point in the history
  • Loading branch information
AriehSchneier committed Nov 18, 2024
1 parent 7ee171b commit c72fa76
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions cmd/sysl/sysl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,32 @@ func TestMain2WithEmptyPbParams(t *testing.T) {

logger, hook := test.NewNullLogger()
memFs, fs := syslutil.WriteToMemOverlayFs("/")

resetOut := suppressStdOut()
defer resetOut()

main2([]string{"sysl", "pb", "-o", " ", "--mode", "", filepath.Join(testDir, "call.sysl")},
fs, logger, os.Stdin, main3)

resetOut()

assert.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level)
assert.Equal(t,
"'output' value passed is empty\n'mode' value passed is empty\n", hook.LastEntry().Message)
syslutil.AssertFsHasExactly(t, memFs)
}

// suppressStdOut will suppress all stdOut and return a function that can be called to restore
func suppressStdOut() func() {
null, _ := os.OpenFile(os.DevNull, os.O_WRONLY, 0) //nolint:errcheck
sOut := os.Stdout
os.Stdout = null
return sync.OnceFunc(func() {
os.Stdout = sOut
_ = null.Close() //nolint:errcheck
})
}

func TestMain2WithEmptyGenParams(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1169,14 +1187,8 @@ func runSyslSuppressStdOut(t *testing.T, expectedRet int, stdin io.Reader, args
stdin = os.Stdin
}

// dump stdout
null, _ := os.OpenFile(os.DevNull, os.O_WRONLY, 0) //nolint:errcheck
sOut := os.Stdout
os.Stdout = null
resetOut := sync.OnceFunc(func() {
os.Stdout = sOut
_ = null.Close() //nolint:errcheck
})
// suppress stdout
resetOut := suppressStdOut()
defer resetOut()

ret := main2(args, afero.NewOsFs(), logger, stdin, main3)
Expand Down

0 comments on commit c72fa76

Please sign in to comment.