Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
test with pre and post cmd funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
mtodzo committed Nov 23, 2020
1 parent 224ea4a commit dc24305
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions run_bin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bincover
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -640,6 +641,23 @@ func TestCoverageCollector_RunBinary(t *testing.T) {
wantErr: true,
cmdFuncs: []CoverageCollectorOption{errPostCmdFunc()},
},
{
name: "succeed running binary with pre and post cmdFuncs",
args: args{
binPath: "./set_covermode",
mainTestName: "TestRunMain",
env: nil,
args: nil,
},
fields: fields{
MergedCoverageFilename: "temp_coverage.out",
CollectCoverage: true,
},
wantOutput: "Hello world\n",
wantExitCode: 1,
wantErr: false,
cmdFuncs: []CoverageCollectorOption{nilPreCmdFunc(), nilPostCmdFunc()},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -703,6 +721,22 @@ func errPostCmdFunc() CoverageCollectorOption {
return PreExec(f)
}

func nilPreCmdFunc() CoverageCollectorOption {
f := CmdFunc(func(cmd *exec.Cmd) error {
fmt.Println("PreCmdFunc")
return nil
})
return PreExec(f)
}

func nilPostCmdFunc() CoverageCollectorOption {
f := CmdFunc(func(cmd *exec.Cmd) error {
fmt.Println("PostCmdFunc")
return nil
})
return PreExec(f)
}

func tempFile(t *testing.T) *os.File {
f, err := ioutil.TempFile("", "")
require.NoError(t, err)
Expand Down

0 comments on commit dc24305

Please sign in to comment.