Skip to content

Commit

Permalink
test: add regression test from #41474
Browse files Browse the repository at this point in the history
This issue was fixed with multiple individual compiler optimizations,
each of which had their own respective test cases. This CL just adds
the capstone test case to demonstrate that the issue has been fixed
and doesn't regress again.

Updates #41474.

Change-Id: Iae752d4b0e7b83ee356b946843340a4fbc254058
Reviewed-on: https://go-review.googlesource.com/c/go/+/263097
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
ALTree committed Oct 17, 2020
1 parent 5faa828 commit c8f6135
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/os/os_test.go
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"flag"
"fmt"
"internal/race"
"internal/testenv"
"io"
"io/ioutil"
Expand Down Expand Up @@ -2579,3 +2580,20 @@ func TestOpenFileKeepsPermissions(t *testing.T) {
t.Errorf("Stat after OpenFile is %v, should be writable", fi.Mode())
}
}

// Issue 41474.
func TestStdoutWriteDoesNotHeapAllocate(t *testing.T) {
if runtime.GOOS == "js" || runtime.GOOS == "windows" {
t.Skip("Still heap allocates on js/wasm and windows, but it used to too")
}
if race.Enabled {
t.Skip("Heap allocates in race mode")
}

n := testing.AllocsPerRun(10, func() {
Stdout.Write([]byte{'h', 'e', 'l', 'l', 'o', '\n'})
})
if n != 0 {
t.Errorf("AllocsPerRun = %v, want 0", n)
}
}

0 comments on commit c8f6135

Please sign in to comment.