aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/testutil_test.go
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-08-16 11:47:00 -0700
committerTobias Bosch <tbosch@google.com>2019-08-20 17:48:54 +0000
commita50a9c16b6a3b2522bea3b6562d023a7b87dbd49 (patch)
tree4d17d8e02962ba4e62c66e49f520cb1b310adc7d /compiler_wrapper/testutil_test.go
parent36c19215f13c983c2ae0096ed9170fd064744622 (diff)
downloadtoolchain-utils-a50a9c16b6a3b2522bea3b6562d023a7b87dbd49.tar.gz
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 <gbiv@chromium.org> Tested-by: Tobias Bosch <tbosch@google.com>
Diffstat (limited to 'compiler_wrapper/testutil_test.go')
-rw-r--r--compiler_wrapper/testutil_test.go24
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) {