@@ -81,34 +81,21 @@ type tester struct {
81
81
worklist []* work
82
82
}
83
83
84
+ // work tracks command execution for a test.
84
85
type work struct {
85
- dt * distTest
86
- cmd * exec.Cmd // Must write stdout/stderr to work. out
87
- flush func () // If non-nil, called after cmd.Run
88
- start chan bool
89
- out bytes.Buffer
90
- err error
91
- end chan bool
86
+ dt * distTest // unique test name, etc.
87
+ cmd * exec.Cmd // must write stdout/stderr to out
88
+ flush func () // if non-nil, called after cmd.Run
89
+ start chan bool // a true means to start, a false means to skip
90
+ out bytes.Buffer // combined stdout/stderr from cmd
91
+ err error // work result
92
+ end chan struct {} // a value means cmd ended (or was skipped)
92
93
}
93
94
94
95
// printSkip prints a skip message for all of work.
95
96
func (w * work ) printSkip (t * tester , msg string ) {
96
97
if t .json {
97
- type event struct {
98
- Time time.Time
99
- Action string
100
- Package string
101
- Output string `json:",omitempty"`
102
- }
103
- enc := json .NewEncoder (& w .out )
104
- ev := event {Time : time .Now (), Package : w .dt .name , Action : "start" }
105
- enc .Encode (ev )
106
- ev .Action = "output"
107
- ev .Output = msg
108
- enc .Encode (ev )
109
- ev .Action = "skip"
110
- ev .Output = ""
111
- enc .Encode (ev )
98
+ synthesizeSkipEvent (json .NewEncoder (& w .out ), w .dt .name , msg )
112
99
return
113
100
}
114
101
fmt .Fprintln (& w .out , msg )
@@ -525,6 +512,18 @@ func (opts *goTest) packages() []string {
525
512
return pkgs
526
513
}
527
514
515
+ // printSkip prints a skip message for all of goTest.
516
+ func (opts * goTest ) printSkip (t * tester , msg string ) {
517
+ if t .json {
518
+ enc := json .NewEncoder (os .Stdout )
519
+ for _ , pkg := range opts .packages () {
520
+ synthesizeSkipEvent (enc , pkg , msg )
521
+ }
522
+ return
523
+ }
524
+ fmt .Println (msg )
525
+ }
526
+
528
527
// ranGoTest and stdMatches are state closed over by the stdlib
529
528
// testing func in registerStdTest below. The tests are run
530
529
// sequentially, so there's no need for locks.
@@ -955,7 +954,7 @@ func (t *tester) registerTest(heading string, test *goTest, opts ...registerTest
955
954
if skipFunc != nil {
956
955
msg , skip := skipFunc (dt )
957
956
if skip {
958
- t .printSkip (test , msg )
957
+ test .printSkip (t , msg )
959
958
return nil
960
959
}
961
960
}
@@ -983,30 +982,6 @@ func (t *tester) registerTest(heading string, test *goTest, opts ...registerTest
983
982
}
984
983
}
985
984
986
- func (t * tester ) printSkip (test * goTest , msg string ) {
987
- if ! t .json {
988
- fmt .Println (msg )
989
- return
990
- }
991
- type event struct {
992
- Time time.Time
993
- Action string
994
- Package string
995
- Output string `json:",omitempty"`
996
- }
997
- out := json .NewEncoder (os .Stdout )
998
- for _ , pkg := range test .packages () {
999
- ev := event {Time : time .Now (), Package : testName (pkg , test .variant ), Action : "start" }
1000
- out .Encode (ev )
1001
- ev .Action = "output"
1002
- ev .Output = msg
1003
- out .Encode (ev )
1004
- ev .Action = "skip"
1005
- ev .Output = ""
1006
- out .Encode (ev )
1007
- }
1008
- }
1009
-
1010
985
// dirCmd constructs a Cmd intended to be run in the foreground.
1011
986
// The command will be run in dir, and Stdout and Stderr will go to os.Stdout
1012
987
// and os.Stderr.
@@ -1268,8 +1243,8 @@ func (t *tester) registerCgoTests(heading string) {
1268
1243
}
1269
1244
}
1270
1245
1271
- // run pending test commands, in parallel, emitting headers as appropriate.
1272
- // When finished, emit header for nextTest, which is going to run after the
1246
+ // runPending runs pending test commands, in parallel, emitting headers as appropriate.
1247
+ // When finished, it emits header for nextTest, which is going to run after the
1273
1248
// pending commands are done (and runPending returns).
1274
1249
// A test should call runPending if it wants to make sure that it is not
1275
1250
// running in parallel with earlier tests, or if it has some other reason
@@ -1279,7 +1254,7 @@ func (t *tester) runPending(nextTest *distTest) {
1279
1254
t .worklist = nil
1280
1255
for _ , w := range worklist {
1281
1256
w .start = make (chan bool )
1282
- w .end = make (chan bool )
1257
+ w .end = make (chan struct {} )
1283
1258
// w.cmd must be set up to write to w.out. We can't check that, but we
1284
1259
// can check for easy mistakes.
1285
1260
if w .cmd .Stdout == nil || w .cmd .Stdout == os .Stdout || w .cmd .Stderr == nil || w .cmd .Stderr == os .Stderr {
@@ -1305,7 +1280,7 @@ func (t *tester) runPending(nextTest *distTest) {
1305
1280
}
1306
1281
}
1307
1282
timelog ("end" , w .dt .name )
1308
- w .end <- true
1283
+ w .end <- struct {}{}
1309
1284
}(w )
1310
1285
}
1311
1286
0 commit comments