From 6f428f097915ab40fc417713ac613a7fda46b713 Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Tue, 31 Jan 2012 10:37:21 -0500 Subject: [PATCH] cmd/go: clean test directories as they complete A go build currently generates around 400MB of test output prior to cleaning up. With this change we use a maximum of ~15MB. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5588044 --- src/cmd/go/test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go index 5a7f321d23b..e47090582cb 100644 --- a/src/cmd/go/test.go +++ b/src/cmd/go/test.go @@ -442,9 +442,14 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action, p: p, ignoreFail: true, } + cleanAction := &action{ + f: (*builder).cleanTest, + deps: []*action{runAction}, + p: p, + } printAction = &action{ f: (*builder).printTest, - deps: []*action{runAction}, + deps: []*action{cleanAction}, p: p, } } @@ -521,12 +526,22 @@ func (b *builder) runTest(a *action) error { } else { fmt.Fprintf(a.testOutput, "%s\n", err) } + + return nil +} + +// cleanTest is the action for cleaning up after a test. +func (b *builder) cleanTest(a *action) error { + run := a.deps[0] + testDir := filepath.Join(b.work, filepath.FromSlash(run.p.ImportPath+"/_test")) + os.RemoveAll(testDir) return nil } // printTest is the action for printing a test result. func (b *builder) printTest(a *action) error { - run := a.deps[0] + clean := a.deps[0] + run := clean.deps[0] os.Stdout.Write(run.testOutput.Bytes()) run.testOutput = nil return nil