Skip to content

Commit 70aef04

Browse files
authored
Merge pull request #1296 from Workiva/updateTestRunExample
[go1.20] Update test run example native override
2 parents 2b435e6 + 0fcb7ec commit 70aef04

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

compiler/natives/src/testing/example.go

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ package testing
66
import (
77
"fmt"
88
"os"
9-
"strings"
109
"time"
1110
)
1211

1312
func runExample(eg InternalExample) (ok bool) {
14-
if *chatty {
13+
if chatty.on {
1514
fmt.Printf("=== RUN %s\n", eg.Name)
1615
}
1716

@@ -24,12 +23,12 @@ func runExample(eg InternalExample) (ok bool) {
2423
}
2524
os.Stdout = w
2625

26+
finished := false
2727
start := time.Now()
28-
ok = true
2928

3029
// Clean up in a deferred call so we can recover if the example panics.
3130
defer func() {
32-
dstr := fmtDuration(time.Now().Sub(start))
31+
timeSpent := time.Since(start)
3332

3433
// Close file, restore stdout, get output.
3534
w.Close()
@@ -41,31 +40,12 @@ func runExample(eg InternalExample) (ok bool) {
4140
os.Exit(1)
4241
}
4342

44-
var fail string
4543
err := recover()
46-
got := strings.TrimSpace(string(out))
47-
want := strings.TrimSpace(eg.Output)
48-
if eg.Unordered {
49-
if sortLines(got) != sortLines(want) && err == nil {
50-
fail = fmt.Sprintf("got:\n%s\nwant (unordered):\n%s\n", string(out), eg.Output)
51-
}
52-
} else {
53-
if got != want && err == nil {
54-
fail = fmt.Sprintf("got:\n%s\nwant:\n%s\n", got, want)
55-
}
56-
}
57-
if fail != "" || err != nil {
58-
fmt.Printf("--- FAIL: %s (%s)\n%s", eg.Name, dstr, fail)
59-
ok = false
60-
} else if *chatty {
61-
fmt.Printf("--- PASS: %s (%s)\n", eg.Name, dstr)
62-
}
63-
if err != nil {
64-
panic(err)
65-
}
44+
ok = eg.processRunResult(string(out), timeSpent, finished, err)
6645
}()
6746

6847
// Run example.
6948
eg.F()
49+
finished = true
7050
return
7151
}

0 commit comments

Comments
 (0)