summaryrefslogtreecommitdiff
path: root/src/cmd/gotest/gotest.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/gotest/gotest.go')
-rw-r--r--src/cmd/gotest/gotest.go29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/cmd/gotest/gotest.go b/src/cmd/gotest/gotest.go
index 138216e68..a7ba8dd11 100644
--- a/src/cmd/gotest/gotest.go
+++ b/src/cmd/gotest/gotest.go
@@ -16,6 +16,7 @@ import (
"path/filepath"
"runtime"
"strings"
+ "time"
"unicode"
"utf8"
)
@@ -51,6 +52,13 @@ var (
xFlag bool
)
+// elapsed returns time elapsed since gotest started.
+func elapsed() float64 {
+ return float64(time.Nanoseconds()-start) / 1e9
+}
+
+var start = time.Nanoseconds()
+
// File represents a file that contains tests.
type File struct {
name string
@@ -80,6 +88,9 @@ func main() {
if !cFlag {
runTestWithArgs("./" + O + ".out")
}
+ if xFlag {
+ fmt.Printf("gotest %.2fs: done\n", elapsed())
+ }
}
// needMakefile tests that we have a Makefile in this directory.
@@ -119,7 +130,10 @@ func setEnvironment() {
// Basic environment.
GOROOT = runtime.GOROOT()
addEnv("GOROOT", GOROOT)
- GOARCH = runtime.GOARCH
+ GOARCH = os.Getenv("GOARCH")
+ if GOARCH == "" {
+ GOARCH = runtime.GOARCH
+ }
addEnv("GOARCH", GOARCH)
O = theChar[GOARCH]
if O == "" {
@@ -254,7 +268,12 @@ func runTestWithArgs(binary string) {
// retrieve standard output.
func doRun(argv []string, returnStdout bool) string {
if xFlag {
- fmt.Printf("gotest: %s\n", strings.Join(argv, " "))
+ fmt.Printf("gotest %.2fs: %s\n", elapsed(), strings.Join(argv, " "))
+ t := -time.Nanoseconds()
+ defer func() {
+ t += time.Nanoseconds()
+ fmt.Printf(" [+%.2fs]\n", float64(t)/1e9)
+ }()
}
command := argv[0]
if runtime.GOOS == "windows" && command == "gomake" {
@@ -266,7 +285,7 @@ func doRun(argv []string, returnStdout bool) string {
}
cmd += `"` + v + `"`
}
- argv = []string{"cmd", "/c", "sh", "-c", cmd}
+ argv = []string{"sh", "-c", cmd}
}
var err os.Error
argv[0], err = exec.LookPath(argv[0])
@@ -359,7 +378,7 @@ func writeTestmainGo() {
fmt.Fprintf(b, "import %q\n", "./_xtest_")
}
fmt.Fprintf(b, "import %q\n", "testing")
- fmt.Fprintf(b, "import __os__ %q\n", "os") // rename in case tested package is called os
+ fmt.Fprintf(b, "import __os__ %q\n", "os") // rename in case tested package is called os
fmt.Fprintf(b, "import __regexp__ %q\n", "regexp") // rename in case tested package is called regexp
fmt.Fprintln(b) // for gofmt
@@ -374,7 +393,7 @@ func writeTestmainGo() {
fmt.Fprintln(b)
// Benchmarks.
- fmt.Fprintln(b, "var benchmarks = []testing.InternalBenchmark{")
+ fmt.Fprintf(b, "var benchmarks = []testing.InternalBenchmark{")
for _, f := range files {
for _, bm := range f.benchmarks {
fmt.Fprintf(b, "\t{\"%s.%s\", %s.%s},\n", f.pkg, bm, notMain(f.pkg), bm)