Skip to content

Commit

Permalink
Update tests to use subtests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cweill committed Nov 8, 2016
1 parent 6dada01 commit efeb9cf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
12 changes: 7 additions & 5 deletions gotests/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ func TestRun(t *testing.T) {
},
}
for _, tt := range tests {
out := &bytes.Buffer{}
Run(out, tt.args, tt.opts)
if got := out.String(); got != tt.want {
t.Errorf("%q. Run() =\n%v, want\n%v", tt.name, got, tt.want)
}
t.Run(tt.name, func(t *testing.T) {
out := &bytes.Buffer{}
Run(out, tt.args, tt.opts)
if got := out.String(); got != tt.want {
t.Errorf("Run() =\n%v, want\n%v", got, tt.want)
}
})
}
}
54 changes: 28 additions & 26 deletions gotests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,33 +509,35 @@ func TestGenerateTests(t *testing.T) {
t.Fatalf("ioutil.TempDir: %v", err)
}
for _, tt := range tests {
gts, err := GenerateTests(tt.args.srcPath, &Options{
Only: tt.args.only,
Exclude: tt.args.excl,
Exported: tt.args.exported,
PrintInputs: tt.args.printInputs,
Subtests: tt.args.subtests,
Importer: func() types.Importer { return tt.args.importer },
t.Run(tt.name, func(t *testing.T) {
gts, err := GenerateTests(tt.args.srcPath, &Options{
Only: tt.args.only,
Exclude: tt.args.excl,
Exported: tt.args.exported,
PrintInputs: tt.args.printInputs,
Subtests: tt.args.subtests,
Importer: func() types.Importer { return tt.args.importer },
})
if (err != nil) != tt.wantErr {
t.Errorf("GenerateTests(%v) error = %v, wantErr %v", tt.args.srcPath, err, tt.wantErr)
return
}
if (len(gts) == 0) != tt.wantNoTests {
t.Errorf("GenerateTests(%v) returned no tests", tt.args.srcPath)
return
}
if (len(gts) > 1) != tt.wantMultipleTests {
t.Errorf("GenerateTests(%v) returned too many tests", tt.args.srcPath)
return
}
if tt.wantNoTests || tt.wantMultipleTests {
return
}
if got := string(gts[0].Output); got != tt.want {
t.Errorf("GenerateTests(%v) = \n%v, want \n%v", tt.args.srcPath, got, tt.want)
outputResult(t, tmp, tt.name, gts[0].Output)
}
})
if (err != nil) != tt.wantErr {
t.Errorf("%q. GenerateTests(%v) error = %v, wantErr %v", tt.name, tt.args.srcPath, err, tt.wantErr)
continue
}
if (len(gts) == 0) != tt.wantNoTests {
t.Errorf("%q. GenerateTests(%v) returned no tests", tt.name, tt.args.srcPath)
continue
}
if (len(gts) > 1) != tt.wantMultipleTests {
t.Errorf("%q. GenerateTests(%v) returned too many tests", tt.name, tt.args.srcPath)
continue
}
if tt.wantNoTests || tt.wantMultipleTests {
continue
}
if got := string(gts[0].Output); got != tt.want {
t.Errorf("%q. GenerateTests(%v) = \n%v, want \n%v", tt.name, tt.args.srcPath, got, tt.want)
outputResult(t, tmp, tt.name, gts[0].Output)
}
}
}

Expand Down

0 comments on commit efeb9cf

Please sign in to comment.