diff --git a/run_bin_test.go b/run_bin_test.go index 681e525..9ed0f62 100644 --- a/run_bin_test.go +++ b/run_bin_test.go @@ -3,6 +3,7 @@ package bincover import ( "bytes" "errors" + "fmt" "io/ioutil" "log" "os" @@ -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) { @@ -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)