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

Commit

Permalink
make fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mtodzo committed Dec 7, 2020
1 parent 8a9d5d3 commit 1d2d631
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions run_bin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bincover
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -410,33 +409,33 @@ func TestPreExec(t *testing.T) {
)

tests := []struct {
name string
preCmdFuncs []PreCmdFunc
expected string
args args
wantErr bool
wantErrMsg string
buffer *string
name string
preCmdFuncs []PreCmdFunc
expected string
args args
wantErr bool
wantErrMsg string
buffer *string
}{
{
name: "test running one prefunc",
args: args{
binPath: "./test_bins/read_stdin.sh",
mainTestName: "TestRunMain",
},
buffer: &buffer1,
buffer: &buffer1,
preCmdFuncs: []PreCmdFunc{printToBufferPreFunc(&buffer1)},
expected: "Hello from prefunc\n",
expected: "Hello from prefunc\n",
},
{
name: "test running two prefuncs",
args: args{
binPath: "./test_bins/read_stdin.sh",
mainTestName: "TestRunMain",
},
buffer: &buffer2,
buffer: &buffer2,
preCmdFuncs: []PreCmdFunc{printToBufferPreFunc(&buffer2), printToBufferPreFunc(&buffer2)},
expected: "Hello from prefunc\nHello from prefunc\n",
expected: "Hello from prefunc\nHello from prefunc\n",
},
{
name: "test error in prefuncs",
Expand All @@ -445,8 +444,8 @@ func TestPreExec(t *testing.T) {
mainTestName: "TestRunMain",
},
preCmdFuncs: []PreCmdFunc{errPreCmdFunc()},
wantErr: true,
wantErrMsg: "oh no!",
wantErr: true,
wantErrMsg: "oh no!",
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -478,32 +477,32 @@ func TestPostExec(t *testing.T) {

tests := []struct {
name string
postCmdFuncs []PostCmdFunc
expected string
args args
wantErr bool
wantErrMsg string
buffer *string
postCmdFuncs []PostCmdFunc
expected string
args args
wantErr bool
wantErrMsg string
buffer *string
}{
{
name: "test running one postfunc",
args: args{
binPath: "./set_covermode",
mainTestName: "TestRunMain",
},
buffer: &buffer1,
buffer: &buffer1,
postCmdFuncs: []PostCmdFunc{printCommandOutputToBuffer(&buffer1)},
expected: "Hello world\n",
expected: "Hello world\n",
},
{
name: "test running two prefuncs",
args: args{
binPath: "./set_covermode",
mainTestName: "TestRunMain",
},
buffer: &buffer2,
buffer: &buffer2,
postCmdFuncs: []PostCmdFunc{printCommandOutputToBuffer(&buffer2), printCommandOutputToBuffer(&buffer2)},
expected: "Hello world\nHello world\n",
expected: "Hello world\nHello world\n",
},
{
name: "test error in prefuncs",
Expand All @@ -512,8 +511,8 @@ func TestPostExec(t *testing.T) {
mainTestName: "TestRunMain",
},
postCmdFuncs: []PostCmdFunc{errPostCmdFunc()},
wantErr: true,
wantErrMsg: "oh no!",
wantErr: true,
wantErrMsg: "oh no!",
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -687,8 +686,8 @@ func TestCoverageCollector_RunBinary(t *testing.T) {
},
wantOutput: "Hello from prefunc\n",
wantExitCode: 1,
wantErr: false,
cmdFuncs: []CoverageCollectorOption{stdinPipePreFuncCovCollectorOption()},
wantErr: false,
cmdFuncs: []CoverageCollectorOption{stdinPipePreFuncCovCollectorOption()},
},
{
name: "fail running binary with error in preCmdFunc",
Expand All @@ -700,10 +699,10 @@ func TestCoverageCollector_RunBinary(t *testing.T) {
MergedCoverageFilename: "temp_coverage.out",
CollectCoverage: false,
},
errMessage: "oh no!",
errMessage: "oh no!",
wantExitCode: -1,
wantErr: true,
cmdFuncs: []CoverageCollectorOption{errPreCmdFuncCovCollectorOption()},
wantErr: true,
cmdFuncs: []CoverageCollectorOption{errPreCmdFuncCovCollectorOption()},
},
{
name: "fail running binary with error in postCmdFunc",
Expand All @@ -717,10 +716,10 @@ func TestCoverageCollector_RunBinary(t *testing.T) {
MergedCoverageFilename: "temp_coverage.out",
CollectCoverage: false,
},
errMessage: "oh no!",
errMessage: "oh no!",
wantExitCode: -1,
wantErr: true,
cmdFuncs: []CoverageCollectorOption{errPostCmdFuncCovCollectorOption()},
wantErr: true,
cmdFuncs: []CoverageCollectorOption{errPostCmdFuncCovCollectorOption()},
},
{
name: "succeed running binary with pre and post cmdFuncs",
Expand All @@ -734,10 +733,10 @@ func TestCoverageCollector_RunBinary(t *testing.T) {
MergedCoverageFilename: "temp_coverage.out",
CollectCoverage: true,
},
wantOutput: "Hello world\n",
wantOutput: "Hello world\n",
wantExitCode: 1,
wantErr: false,
cmdFuncs: []CoverageCollectorOption{nilPreCmdFunc(), nilPostCmdFunc()},
wantErr: false,
cmdFuncs: []CoverageCollectorOption{nilPreCmdFunc(), nilPostCmdFunc()},
},
}
for _, tt := range tests {
Expand All @@ -750,7 +749,9 @@ func TestCoverageCollector_RunBinary(t *testing.T) {
if tt.wantPanic {
require.PanicsWithValue(t,
tt.panicMessage,
func() { _, _, _ = c.RunBinary(tt.args.binPath, tt.args.mainTestName, tt.args.env, tt.args.args, tt.cmdFuncs...)},
func() {
_, _, _ = c.RunBinary(tt.args.binPath, tt.args.mainTestName, tt.args.env, tt.args.args, tt.cmdFuncs...)
},
)
return
}
Expand Down Expand Up @@ -799,7 +800,6 @@ func errPostCmdFuncCovCollectorOption() CoverageCollectorOption {

func nilPreCmdFunc() CoverageCollectorOption {
f := PreCmdFunc(func(cmd *exec.Cmd) error {
fmt.Println("PreCmdFunc")
return nil
})
return PreExec(f)
Expand Down Expand Up @@ -836,7 +836,6 @@ func errPostCmdFunc() PostCmdFunc {

func nilPostCmdFunc() CoverageCollectorOption {
f := PostCmdFunc(func(cmd *exec.Cmd, output string, err error) error {
fmt.Println("PostCmdFunc")
return nil
})
return PostExec(f)
Expand Down

0 comments on commit 1d2d631

Please sign in to comment.