@@ -6,12 +6,11 @@ package testing
6
6
import (
7
7
"fmt"
8
8
"os"
9
- "strings"
10
9
"time"
11
10
)
12
11
13
12
func runExample (eg InternalExample ) (ok bool ) {
14
- if * chatty {
13
+ if chatty . on {
15
14
fmt .Printf ("=== RUN %s\n " , eg .Name )
16
15
}
17
16
@@ -24,12 +23,12 @@ func runExample(eg InternalExample) (ok bool) {
24
23
}
25
24
os .Stdout = w
26
25
26
+ finished := false
27
27
start := time .Now ()
28
- ok = true
29
28
30
29
// Clean up in a deferred call so we can recover if the example panics.
31
30
defer func () {
32
- dstr := fmtDuration ( time .Now (). Sub ( start ) )
31
+ timeSpent := time .Since ( start )
33
32
34
33
// Close file, restore stdout, get output.
35
34
w .Close ()
@@ -41,31 +40,12 @@ func runExample(eg InternalExample) (ok bool) {
41
40
os .Exit (1 )
42
41
}
43
42
44
- var fail string
45
43
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\n want (unordered):\n %s\n " , string (out ), eg .Output )
51
- }
52
- } else {
53
- if got != want && err == nil {
54
- fail = fmt .Sprintf ("got:\n %s\n want:\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 )
66
45
}()
67
46
68
47
// Run example.
69
48
eg .F ()
49
+ finished = true
70
50
return
71
51
}
0 commit comments