mirror of
https://github.com/golang/go
synced 2024-11-22 04:14:42 -07:00
cmd/internal: use t.TempDir in tests
Change-Id: I3d4c66793afa3769a8450e2d65093a0f9115596e Reviewed-on: https://go-review.googlesource.com/c/go/+/611043 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
parent
a77b93c0b2
commit
8f2486d2e0
@ -96,11 +96,7 @@ func TestIssue41621LargeNumberOfRelocations(t *testing.T) {
|
||||
}
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "lotsofrelocs")
|
||||
if err != nil {
|
||||
t.Fatalf("can't create temp directory: %v\n", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
tmpdir := t.TempDir()
|
||||
|
||||
// Emit testcase.
|
||||
var w bytes.Buffer
|
||||
@ -109,7 +105,7 @@ func TestIssue41621LargeNumberOfRelocations(t *testing.T) {
|
||||
fmt.Fprintf(&w, "\t\"%d\",\n", i)
|
||||
}
|
||||
w.WriteString(issue41621epilog)
|
||||
err = os.WriteFile(tmpdir+"/large.go", w.Bytes(), 0666)
|
||||
err := os.WriteFile(tmpdir+"/large.go", w.Bytes(), 0666)
|
||||
if err != nil {
|
||||
t.Fatalf("can't write output: %v\n", err)
|
||||
}
|
||||
|
@ -25,11 +25,7 @@ func TestLargeBranch(t *testing.T) {
|
||||
}
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
dir, err := os.MkdirTemp("", "testlargebranch")
|
||||
if err != nil {
|
||||
t.Fatalf("Could not create directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
// Generate a very large function.
|
||||
buf := bytes.NewBuffer(make([]byte, 0, genBufSize))
|
||||
|
@ -98,14 +98,10 @@ func TestSymbolTooLarge(t *testing.T) { // Issue 42054
|
||||
t.Skip("skip on 32-bit architectures")
|
||||
}
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "TestSymbolTooLarge")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
tmpdir := t.TempDir()
|
||||
|
||||
src := filepath.Join(tmpdir, "p.go")
|
||||
err = os.WriteFile(src, []byte("package p; var x [1<<32]byte"), 0666)
|
||||
err := os.WriteFile(src, []byte("package p; var x [1<<32]byte"), 0666)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to write source file: %v\n", err)
|
||||
}
|
||||
|
@ -167,11 +167,7 @@ PNOP
|
||||
func TestPfxAlign(t *testing.T) {
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
dir, err := os.MkdirTemp("", "testpfxalign")
|
||||
if err != nil {
|
||||
t.Fatalf("could not create directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
pgms := []struct {
|
||||
text []byte
|
||||
@ -188,7 +184,7 @@ func TestPfxAlign(t *testing.T) {
|
||||
|
||||
for _, pgm := range pgms {
|
||||
tmpfile := filepath.Join(dir, "x.s")
|
||||
err = os.WriteFile(tmpfile, pgm.text, 0644)
|
||||
err := os.WriteFile(tmpfile, pgm.text, 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("can't write output: %v\n", err)
|
||||
}
|
||||
@ -217,11 +213,7 @@ func TestLarge(t *testing.T) {
|
||||
}
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
dir, err := os.MkdirTemp("", "testlarge")
|
||||
if err != nil {
|
||||
t.Fatalf("could not create directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
// A few interesting test cases for long conditional branch fixups
|
||||
tests := []struct {
|
||||
@ -281,7 +273,7 @@ func TestLarge(t *testing.T) {
|
||||
gen(buf, test.jmpinsn)
|
||||
|
||||
tmpfile := filepath.Join(dir, "x.s")
|
||||
err = os.WriteFile(tmpfile, buf.Bytes(), 0644)
|
||||
err := os.WriteFile(tmpfile, buf.Bytes(), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("can't write output: %v\n", err)
|
||||
}
|
||||
@ -336,16 +328,12 @@ func TestPCalign(t *testing.T) {
|
||||
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
dir, err := os.MkdirTemp("", "testpcalign")
|
||||
if err != nil {
|
||||
t.Fatalf("could not create directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
// generate a test with valid uses of PCALIGN
|
||||
|
||||
tmpfile := filepath.Join(dir, "x.s")
|
||||
err = os.WriteFile(tmpfile, []byte(validPCAlignSrc), 0644)
|
||||
err := os.WriteFile(tmpfile, []byte(validPCAlignSrc), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("can't write output: %v\n", err)
|
||||
}
|
||||
|
@ -24,11 +24,7 @@ func TestLargeBranch(t *testing.T) {
|
||||
}
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
dir, err := os.MkdirTemp("", "testlargebranch")
|
||||
if err != nil {
|
||||
t.Fatalf("Could not create directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
// Generate a very large function.
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 7000000))
|
||||
@ -67,11 +63,7 @@ func TestLargeCall(t *testing.T) {
|
||||
}
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
dir, err := os.MkdirTemp("", "testlargecall")
|
||||
if err != nil {
|
||||
t.Fatalf("could not create directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module largecall"), 0644); err != nil {
|
||||
t.Fatalf("Failed to write file: %v\n", err)
|
||||
@ -196,11 +188,7 @@ func genLargeJump(buf *bytes.Buffer) {
|
||||
|
||||
// Issue 20348.
|
||||
func TestNoRet(t *testing.T) {
|
||||
dir, err := os.MkdirTemp("", "testnoret")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
tmpfile := filepath.Join(dir, "x.s")
|
||||
if err := os.WriteFile(tmpfile, []byte("TEXT ·stub(SB),$0-0\nNOP\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -213,11 +201,7 @@ func TestNoRet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImmediateSplitting(t *testing.T) {
|
||||
dir, err := os.MkdirTemp("", "testimmsplit")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
tmpfile := filepath.Join(dir, "x.s")
|
||||
asm := `
|
||||
TEXT _stub(SB),$0-0
|
||||
|
@ -83,11 +83,7 @@ func normalize(s string) string {
|
||||
}
|
||||
|
||||
func asmOutput(t *testing.T, s string) []byte {
|
||||
tmpdir, err := os.MkdirTemp("", "progedittest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
tmpdir := t.TempDir()
|
||||
tmpfile, err := os.Create(filepath.Join(tmpdir, "input.s"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -31,12 +31,8 @@ func main() {
|
||||
`
|
||||
|
||||
func objdumpOutput(t *testing.T, mname, source string) []byte {
|
||||
tmpdir, err := os.MkdirTemp("", mname)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
err = os.WriteFile(filepath.Join(tmpdir, "go.mod"), []byte(fmt.Sprintf("module %s\n", mname)), 0666)
|
||||
tmpdir := t.TempDir()
|
||||
err := os.WriteFile(filepath.Join(tmpdir, "go.mod"), []byte(fmt.Sprintf("module %s\n", mname)), 0666)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user