@@ -74,10 +74,10 @@ type Parser interface {
74
74
// An error return should only be used in case an unrecoverable error
75
75
// occurred; failing to encode to TOML is not an error, but the encoder
76
76
// unexpectedly panicking is.
77
- Encode (ctx context.Context , jsonInput string ) (output string , outputIsError bool , err error )
77
+ Encode (ctx context.Context , jsonInput string ) (pid int , output string , outputIsError bool , err error )
78
78
79
79
// Decode a TOML string to JSON. The same semantics as Encode apply.
80
- Decode (ctx context.Context , tomlInput string ) (output string , outputIsError bool , err error )
80
+ Decode (ctx context.Context , tomlInput string ) (pid int , output string , outputIsError bool , err error )
81
81
}
82
82
83
83
// CommandParser calls an external command.
@@ -111,6 +111,7 @@ type Test struct {
111
111
Output string // Output from the external program.
112
112
Want string // The output we want.
113
113
OutputFromStderr bool // The Output came from stderr, not stdout.
114
+ PID int // PID from test run.
114
115
Timeout time.Duration // Maximum time for parse.
115
116
IntAsFloat bool // Int values have type=float.
116
117
}
@@ -359,7 +360,7 @@ func (r Runner) hasSkip(path string) bool {
359
360
return false
360
361
}
361
362
362
- func (c CommandParser ) Encode (ctx context.Context , input string ) (output string , outputIsError bool , err error ) {
363
+ func (c CommandParser ) Encode (ctx context.Context , input string ) (pid int , output string , outputIsError bool , err error ) {
363
364
stdout , stderr := new (bytes.Buffer ), new (bytes.Buffer )
364
365
cmd := exec .CommandContext (ctx , c .cmd [0 ])
365
366
cmd .Args = c .cmd
@@ -374,13 +375,16 @@ func (c CommandParser) Encode(ctx context.Context, input string) (output string,
374
375
}
375
376
}
376
377
378
+ if cmd .Process != nil {
379
+ pid = cmd .Process .Pid
380
+ }
377
381
if stderr .Len () > 0 {
378
- return strings .TrimSpace (stderr .String ()) + "\n " , true , err
382
+ return pid , strings .TrimSpace (stderr .String ()) + "\n " , true , err
379
383
}
380
- return strings .TrimSpace (stdout .String ()) + "\n " , false , err
384
+ return pid , strings .TrimSpace (stdout .String ()) + "\n " , false , err
381
385
}
382
386
func NewCommandParser (fsys fs.FS , cmd []string ) CommandParser { return CommandParser {fsys , cmd } }
383
- func (c CommandParser ) Decode (ctx context.Context , input string ) (string , bool , error ) {
387
+ func (c CommandParser ) Decode (ctx context.Context , input string ) (int , string , bool , error ) {
384
388
return c .Encode (ctx , input )
385
389
}
386
390
@@ -403,9 +407,9 @@ func (t Test) runInvalid(p Parser, fsys fs.FS) Test {
403
407
defer cancel ()
404
408
405
409
if t .Encoder {
406
- t .Output , t .OutputFromStderr , err = p .Encode (ctx , t .Input )
410
+ t .PID , t . Output , t .OutputFromStderr , err = p .Encode (ctx , t .Input )
407
411
} else {
408
- t .Output , t .OutputFromStderr , err = p .Decode (ctx , t .Input )
412
+ t .PID , t . Output , t .OutputFromStderr , err = p .Decode (ctx , t .Input )
409
413
}
410
414
if ctx .Err () != nil {
411
415
err = timeoutError {t .Timeout }
@@ -430,9 +434,9 @@ func (t Test) runValid(p Parser, fsys fs.FS) Test {
430
434
defer cancel ()
431
435
432
436
if t .Encoder {
433
- t .Output , t .OutputFromStderr , err = p .Encode (ctx , t .Input )
437
+ t .PID , t . Output , t .OutputFromStderr , err = p .Encode (ctx , t .Input )
434
438
} else {
435
- t .Output , t .OutputFromStderr , err = p .Decode (ctx , t .Input )
439
+ t .PID , t . Output , t .OutputFromStderr , err = p .Decode (ctx , t .Input )
436
440
}
437
441
if ctx .Err () != nil {
438
442
err = timeoutError {t .Timeout }
0 commit comments