Skip to content

Commit

Permalink
Refactor to pass subtest before the pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
tm-jdelapuente committed Oct 7, 2024
1 parent 01ff2d5 commit ceee6be
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/remote/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,25 @@ func (c *Client) stampedBuildEnvironment(state *core.BuildState, target *core.Bu
return core.StampedBuildEnvironment(state, target, hash, ".", stamp && target.Stamp)
}

// constructTestCommand returns the cmd string.
func constructTestCommand(state *core.BuildState, target *core.BuildTarget) string {
baseCmd := target.GetTestCommand(state)
parts := strings.SplitN(baseCmd, "|", 2)

if len(parts) != 2 {
// If there's no pipe, just append the test args
return baseCmd + " " + strings.Join(state.TestArgs, " ")
}

// Insert the subtest args before the pipe
cmdBeforePipe := strings.TrimSpace(parts[0])
if len(state.TestArgs) > 0 {
cmdBeforePipe += " " + strings.Join(state.TestArgs, " ")
}

return cmdBeforePipe + " | " + parts[1]
}

// buildTestCommand builds a command for a target when testing.
func (c *Client) buildTestCommand(state *core.BuildState, target *core.BuildTarget, run int) (*pb.Command, error) {
paths := target.Test.Outputs
Expand All @@ -157,10 +176,7 @@ func (c *Client) buildTestCommand(state *core.BuildState, target *core.BuildTarg
if outs := target.Outputs(); len(outs) > 0 {
commandPrefix += `export TEST="$TEST_DIR/` + outs[0] + `" && `
}
cmd, err := core.ReplaceTestSequences(state, target, target.GetTestCommand(state))
if len(state.TestArgs) != 0 {
cmd += " " + strings.Join(state.TestArgs, " ")
}
cmd, err := core.ReplaceTestSequences(state, target, constructTestCommand(state, target))
return &pb.Command{
Platform: &pb.Platform{
Properties: []*pb.Platform_Property{
Expand Down

0 comments on commit ceee6be

Please sign in to comment.