aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
authorNia Waldvogel <[email protected]>2021-12-30 10:17:35 -0500
committerNia <[email protected]>2021-12-30 12:03:12 -0500
commitf9f2349850cd8a7777045dff249f49ede12e3e07 (patch)
tree8ff153b184f25263fa5c9da25a0fdfc173fef5b1 /main.go
parentf1b15db258038d098f3a8ac57afe6266acb48253 (diff)
downloadtinygo-f9f2349850cd8a7777045dff249f49ede12e3e07.tar.gz
tinygo-f9f2349850cd8a7777045dff249f49ede12e3e07.zip
tinygo test: simplify output buffering
Diffstat (limited to 'main.go')
-rw-r--r--main.go32
1 files changed, 14 insertions, 18 deletions
diff --git a/main.go b/main.go
index 92b7713c3..455a33515 100644
--- a/main.go
+++ b/main.go
@@ -1641,15 +1641,13 @@ func (out *testStdout) Write(data []byte) (int, error) {
defer buf.mu.Unlock()
// Append the output.
- var prev []byte
- if len(buf.output) > 0 && !buf.output[len(buf.output)-1].stderr {
- prev = buf.output[len(buf.output)-1].data
- buf.output = buf.output[:len(buf.output)-1]
- }
- buf.output = append(buf.output, outputEntry{
- stderr: false,
- data: append(prev, data...),
- })
+ if len(buf.output) == 0 || buf.output[len(buf.output)-1].stderr {
+ buf.output = append(buf.output, outputEntry{
+ stderr: false,
+ })
+ }
+ last := &buf.output[len(buf.output)-1]
+ last.data = append(last.data, data...)
return len(data), nil
}
@@ -1674,15 +1672,13 @@ func (out *testStderr) Write(data []byte) (int, error) {
defer buf.mu.Unlock()
// Append the output.
- var prev []byte
- if len(buf.output) > 0 && buf.output[len(buf.output)-1].stderr {
- prev = buf.output[len(buf.output)-1].data
- buf.output = buf.output[:len(buf.output)-1]
- }
- buf.output = append(buf.output, outputEntry{
- stderr: true,
- data: append(prev, data...),
- })
+ if len(buf.output) == 0 || !buf.output[len(buf.output)-1].stderr {
+ buf.output = append(buf.output, outputEntry{
+ stderr: true,
+ })
+ }
+ last := &buf.output[len(buf.output)-1]
+ last.data = append(last.data, data...)
return len(data), nil
}