aboutsummaryrefslogtreecommitdiff
path: root/test/run.go
diff options
context:
space:
mode:
Diffstat (limited to 'test/run.go')
-rw-r--r--test/run.go62
1 files changed, 36 insertions, 26 deletions
diff --git a/test/run.go b/test/run.go
index f2f17c4f20..a460c4d8b6 100644
--- a/test/run.go
+++ b/test/run.go
@@ -59,7 +59,7 @@ var (
// dirs are the directories to look for *.go files in.
// TODO(bradfitz): just use all directories?
- dirs = []string{".", "ken", "chan", "interface", "syntax", "dwarf", "fixedbugs", "codegen", "runtime", "typeparam"}
+ dirs = []string{".", "ken", "chan", "interface", "syntax", "dwarf", "fixedbugs", "codegen", "runtime", "abi", "typeparam"}
// ratec controls the max number of tests running at a time.
ratec chan bool
@@ -467,6 +467,8 @@ func goGcflagsIsEmpty() bool {
return "" == os.Getenv("GO_GCFLAGS")
}
+var errTimeout = errors.New("command exceeded time limit")
+
// run runs a test.
func (t *test) run() {
start := time.Now()
@@ -489,7 +491,7 @@ func (t *test) run() {
// Execution recipe stops at first blank line.
pos := strings.Index(t.src, "\n\n")
if pos == -1 {
- t.err = errors.New("double newline not found")
+ t.err = fmt.Errorf("double newline ending execution recipe not found in %s", t.goFileName())
return
}
action := t.src[:pos]
@@ -642,16 +644,18 @@ func (t *test) run() {
case err = <-done:
// ok
case <-tick.C:
+ cmd.Process.Signal(os.Interrupt)
+ time.Sleep(1 * time.Second)
cmd.Process.Kill()
- err = <-done
- // err = errors.New("Test timeout")
+ <-done
+ err = errTimeout
}
tick.Stop()
}
} else {
err = cmd.Run()
}
- if err != nil {
+ if err != nil && err != errTimeout {
err = fmt.Errorf("%s\n%s", err, buf.Bytes())
}
return buf.Bytes(), err
@@ -731,6 +735,10 @@ func (t *test) run() {
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
return
}
+ if err == errTimeout {
+ t.err = fmt.Errorf("compilation timed out")
+ return
+ }
} else {
if err != nil {
t.err = err
@@ -936,9 +944,7 @@ func (t *test) run() {
t.err = err
return
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
}
}
@@ -978,9 +984,7 @@ func (t *test) run() {
t.err = err
return
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
case "build":
// Build Go file.
@@ -1065,9 +1069,7 @@ func (t *test) run() {
t.err = err
break
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
}
case "buildrun":
@@ -1093,9 +1095,7 @@ func (t *test) run() {
return
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
case "run":
// Run Go file if no special go command flags are provided;
@@ -1138,9 +1138,7 @@ func (t *test) run() {
t.err = err
return
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
case "runoutput":
// Run Go file and write its output into temporary Go file.
@@ -1175,9 +1173,7 @@ func (t *test) run() {
t.err = err
return
}
- if string(out) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
case "errorcheckoutput":
// Run Go file and write its output into temporary Go file.
@@ -1251,12 +1247,24 @@ func (t *test) makeTempDir() {
}
}
-func (t *test) expectedOutput() string {
+// checkExpectedOutput compares the output from compiling and/or running with the contents
+// of the corresponding reference output file, if any (replace ".go" with ".out").
+// If they don't match, fail with an informative message.
+func (t *test) checkExpectedOutput(gotBytes []byte) {
+ got := string(gotBytes)
filename := filepath.Join(t.dir, t.gofile)
filename = filename[:len(filename)-len(".go")]
filename += ".out"
- b, _ := ioutil.ReadFile(filename)
- return string(b)
+ b, err := ioutil.ReadFile(filename)
+ // File is allowed to be missing (err != nil) in which case output should be empty.
+ got = strings.Replace(got, "\r\n", "\n", -1)
+ if got != string(b) {
+ if err == nil {
+ t.err = fmt.Errorf("output does not match expected in %s. Instead saw\n%s", filename, got)
+ } else {
+ t.err = fmt.Errorf("output should be empty when (optional) expected-output file %s is not present. Instead saw\n%s", filename, got)
+ }
+ }
}
func splitOutput(out string, wantAuto bool) []string {
@@ -1930,6 +1938,8 @@ var excluded = map[string]bool{
"const2.go": true, // types2 not run after syntax errors
"ddd1.go": true, // issue #42987
"directive.go": true, // misplaced compiler directive checks
+ "embedfunc.go": true, // error reported by irgen (only runs with -G=3)
+ "embedvers.go": true, // error reported by backend (only runs with -G=3)
"float_lit3.go": true, // types2 reports extra errors
"import1.go": true, // types2 reports extra errors
"import5.go": true, // issue #42988