diff options
Diffstat (limited to 'compiler_wrapper/testutil_test.go')
-rw-r--r-- | compiler_wrapper/testutil_test.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/compiler_wrapper/testutil_test.go b/compiler_wrapper/testutil_test.go index 778c4c26..3e568c77 100644 --- a/compiler_wrapper/testutil_test.go +++ b/compiler_wrapper/testutil_test.go @@ -38,7 +38,8 @@ type testContext struct { inputCmd *command lastCmd *command cmdCount int - cmdMock func(cmd *command, stdout io.Writer, stderr io.Writer) error + cmdMock func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error + stdinBuffer bytes.Buffer stdoutBuffer bytes.Buffer stderrBuffer bytes.Buffer } @@ -83,6 +84,10 @@ func (ctx *testContext) getwd() string { return ctx.wd } +func (ctx *testContext) stdin() io.Reader { + return &ctx.stdinBuffer +} + func (ctx *testContext) stdout() io.Writer { return &ctx.stdoutBuffer } @@ -99,7 +104,7 @@ func (ctx *testContext) stderrString() string { return ctx.stderrBuffer.String() } -func (ctx *testContext) run(cmd *command, stdout io.Writer, stderr io.Writer) error { +func (ctx *testContext) run(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error { // Keep calling the old wrapper when we are comparing the output of the // old wrapper to the new wrapper. if isCompareToOldWrapperCmd(cmd) { @@ -111,7 +116,7 @@ func (ctx *testContext) run(cmd *command, stdout io.Writer, stderr io.Writer) er ctx.cmdCount++ ctx.lastCmd = cmd if ctx.cmdMock != nil { - return ctx.cmdMock(cmd, stdout, stderr) + return ctx.cmdMock(cmd, stdin, stdout, stderr) } return nil } @@ -120,7 +125,7 @@ func (ctx *testContext) exec(cmd *command) error { ctx.cmdCount++ ctx.lastCmd = cmd if ctx.cmdMock != nil { - return ctx.cmdMock(cmd, ctx.stdout(), ctx.stderr()) + return ctx.cmdMock(cmd, ctx.stdin(), ctx.stdout(), ctx.stderr()) } return nil } @@ -188,6 +193,17 @@ func (ctx *testContext) symlink(oldname string, newname string) { } } +func (ctx *testContext) readAllString(r io.Reader) string { + if r == nil { + return "" + } + bytes, err := ioutil.ReadAll(r) + if err != nil { + ctx.t.Fatal(err) + } + return string(bytes) +} + func verifyPath(cmd *command, expectedRegex string) error { compiledRegex := regexp.MustCompile(matchFullString(expectedRegex)) if !compiledRegex.MatchString(cmd.Path) { |