From a50a9c16b6a3b2522bea3b6562d023a7b87dbd49 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Fri, 16 Aug 2019 11:47:00 -0700 Subject: Forward os.Stdin to child processes. BUG=chromium:773875 TEST=unit tests, build glibc with compiler wrapper Change-Id: I0b5c1f5adaee18499b72747cd6042b00a9d52c1d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1760973 Reviewed-by: George Burgess Tested-by: Tobias Bosch --- compiler_wrapper/testutil_test.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'compiler_wrapper/testutil_test.go') 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) { -- cgit v1.2.3