Skip to content

Commit

Permalink
Replace Errorf followed by FailNow with Fatalf
Browse files Browse the repository at this point in the history
When running tests, calling t.Errorf followed by a t.FailNow is pretty
much the same as just calling t.Fatalf. I've also change a couple of
cute error messages.
  • Loading branch information
jstemmer committed Apr 8, 2017
1 parent c2b270e commit 1b6303f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 66 deletions.
6 changes: 2 additions & 4 deletions constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,7 @@ func TestSemverConstraintOps(t *testing.T) {
// still an incomparable type
c1, err := NewSemverConstraint("=1.0.0")
if err != nil {
t.Errorf("Failed to create constraint: %s", err)
t.FailNow()
t.Fatalf("Failed to create constraint: %s", err)
}

if !c1.MatchesAny(any) {
Expand All @@ -610,8 +609,7 @@ func TestSemverConstraintOps(t *testing.T) {

c1, err = NewSemverConstraint(">= 1.0.0")
if err != nil {
t.Errorf("Failed to create constraint: %s", err)
t.FailNow()
t.Fatalf("Failed to create constraint: %s", err)
}

if c1.Matches(v1) {
Expand Down
15 changes: 5 additions & 10 deletions hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func TestHashInputs(t *testing.T) {

s, err := Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}

dig := s.HashInputs()
Expand Down Expand Up @@ -73,8 +72,7 @@ func TestHashInputsReqsIgs(t *testing.T) {

s, err := Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}

dig := s.HashInputs()
Expand Down Expand Up @@ -116,8 +114,7 @@ func TestHashInputsReqsIgs(t *testing.T) {

s, err = Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}

dig = s.HashInputs()
Expand Down Expand Up @@ -157,8 +154,7 @@ func TestHashInputsReqsIgs(t *testing.T) {

s, err = Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}

dig = s.HashInputs()
Expand Down Expand Up @@ -522,8 +518,7 @@ func TestHashInputsOverrides(t *testing.T) {

s, err := Prepare(params, newdepspecSM(basefix.ds, nil))
if err != nil {
t.Errorf("(fix: %q) Unexpected error while prepping solver: %s", fix.name, err)
t.FailNow()
t.Fatalf("(fix: %q) Unexpected error while prepping solver: %s", fix.name, err)
}

h := sha256.New()
Expand Down
18 changes: 6 additions & 12 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ func sv(s string) *semver.Version {
func mkNaiveSM(t *testing.T) (*SourceMgr, func()) {
cpath, err := ioutil.TempDir("", "smcache")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
t.Fatalf("Failed to create temp dir: %s", err)
}

sm, err := NewSourceManager(cpath)
if err != nil {
t.Errorf("Unexpected error on SourceManager creation: %s", err)
t.FailNow()
t.Fatalf("Unexpected error on SourceManager creation: %s", err)
}

return sm, func() {
Expand All @@ -68,8 +66,7 @@ func remakeNaiveSM(osm *SourceMgr, t *testing.T) (*SourceMgr, func()) {

sm, err := NewSourceManager(cpath)
if err != nil {
t.Errorf("unexpected error on SourceManager recreation: %s", err)
t.FailNow()
t.Fatalf("unexpected error on SourceManager recreation: %s", err)
}

return sm, func() {
Expand Down Expand Up @@ -115,8 +112,7 @@ func TestSourceManagerInit(t *testing.T) {
}

if _, err = os.Stat(path.Join(cpath, "sm.lock")); !os.IsNotExist(err) {
t.Errorf("Global cache lock file not cleared correctly on Release()")
t.FailNow()
t.Fatalf("Global cache lock file not cleared correctly on Release()")
}

// Set another one up at the same spot now, just to be sure
Expand All @@ -140,14 +136,12 @@ func TestSourceInit(t *testing.T) {

cpath, err := ioutil.TempDir("", "smcache")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
t.Fatalf("Failed to create temp dir: %s", err)
}

sm, err := NewSourceManager(cpath)
if err != nil {
t.Errorf("Unexpected error on SourceManager creation: %s", err)
t.FailNow()
t.Fatalf("Unexpected error on SourceManager creation: %s", err)
}

defer func() {
Expand Down
15 changes: 5 additions & 10 deletions pkgtree/pkgtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,8 +1352,7 @@ func TestListPackagesNoPerms(t *testing.T) {
}
tmp, err := ioutil.TempDir("", "listpkgsnp")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
t.Fatalf("Failed to create temp dir: %s", err)
}
defer os.RemoveAll(tmp)

Expand All @@ -1364,13 +1363,11 @@ func TestListPackagesNoPerms(t *testing.T) {
// chmod the simple dir and m1p/b.go file so they can't be read
err = os.Chmod(filepath.Join(workdir, "simple"), 0)
if err != nil {
t.Error("Error while chmodding simple dir", err)
t.FailNow()
t.Fatalf("Error while chmodding simple dir: %s", err)
}
os.Chmod(filepath.Join(workdir, "m1p", "b.go"), 0)
if err != nil {
t.Error("Error while chmodding b.go file", err)
t.FailNow()
t.Fatalf("Error while chmodding b.go file: %s", err)
}

want := PackageTree{
Expand Down Expand Up @@ -1398,12 +1395,10 @@ func TestListPackagesNoPerms(t *testing.T) {
got, err := ListPackages(workdir, "ren")

if err != nil {
t.Errorf("Unexpected err from ListPackages: %s", err)
t.FailNow()
t.Fatalf("Unexpected err from ListPackages: %s", err)
}
if want.ImportRoot != got.ImportRoot {
t.Errorf("Expected ImportRoot %s, got %s", want.ImportRoot, got.ImportRoot)
t.FailNow()
t.Fatalf("Expected ImportRoot %s, got %s", want.ImportRoot, got.ImportRoot)
}

if !reflect.DeepEqual(got, want) {
Expand Down
3 changes: 1 addition & 2 deletions result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func testWriteDepTree(t *testing.T) {

tmp, err := ioutil.TempDir("", "writetree")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
t.Fatalf("Failed to create temp dir: %s", err)
}
defer os.RemoveAll(tmp)

Expand Down
6 changes: 2 additions & 4 deletions rootdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ func TestRootdataExternalImports(t *testing.T) {

is, err := Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}
rd := is.(*solver).rd

Expand Down Expand Up @@ -71,8 +70,7 @@ func TestGetApplicableConstraints(t *testing.T) {

is, err := Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}
rd := is.(*solver).rd

Expand Down
33 changes: 11 additions & 22 deletions vcs_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func testGitSourceInteractions(t *testing.T) {
un := "https://" + n
u, err := url.Parse(un)
if err != nil {
t.Errorf("URL was bad, lolwut? errtext: %s", err)
t.FailNow()
t.Fatalf("Error parsing URL %s: %s", un, err)
}
mb := maybeGitSource{
url: u,
Expand All @@ -59,8 +58,7 @@ func testGitSourceInteractions(t *testing.T) {
superv := newSupervisor(ctx)
isrc, state, err := mb.try(ctx, cpath, newMemoryCache(), superv)
if err != nil {
t.Errorf("Unexpected error while setting up gitSource for test repo: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while setting up gitSource for test repo: %s", err)
}

wantstate := sourceIsSetUp | sourceExistsUpstream | sourceHasLatestVersionList
Expand All @@ -70,14 +68,12 @@ func testGitSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Errorf("Error on cloning git repo: %s", err)
t.FailNow()
t.Fatalf("Error on cloning git repo: %s", err)
}

src, ok := isrc.(*gitSource)
if !ok {
t.Errorf("Expected a gitSource, got a %T", isrc)
t.FailNow()
t.Fatalf("Expected a gitSource, got a %T", isrc)
}

if un != src.upstreamURL() {
Expand All @@ -86,8 +82,7 @@ func testGitSourceInteractions(t *testing.T) {

pvlist, err := src.listVersions(ctx)
if err != nil {
t.Errorf("Unexpected error getting version pairs from git repo: %s", err)
t.FailNow()
t.Fatalf("Unexpected error getting version pairs from git repo: %s", err)
}

vlist := hidePair(pvlist)
Expand Down Expand Up @@ -173,8 +168,7 @@ func testGopkginSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Errorf("Error on cloning git repo: %s", err)
t.FailNow()
t.Fatalf("Error on cloning git repo: %s", err)
}

src, ok := isrc.(*gopkginSource)
Expand Down Expand Up @@ -292,8 +286,7 @@ func testBzrSourceInteractions(t *testing.T) {
un := "https://" + n
u, err := url.Parse(un)
if err != nil {
t.Errorf("URL was bad, lolwut? errtext: %s", err)
t.FailNow()
t.Fatalf("Error parsing URL %s: %s", un, err)
}
mb := maybeBzrSource{
url: u,
Expand All @@ -303,8 +296,7 @@ func testBzrSourceInteractions(t *testing.T) {
superv := newSupervisor(ctx)
isrc, state, err := mb.try(ctx, cpath, newMemoryCache(), superv)
if err != nil {
t.Errorf("Unexpected error while setting up bzrSource for test repo: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while setting up bzrSource for test repo: %s", err)
}

wantstate := sourceIsSetUp | sourceExistsUpstream
Expand All @@ -314,14 +306,12 @@ func testBzrSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Errorf("Error on cloning git repo: %s", err)
t.FailNow()
t.Fatalf("Error on cloning git repo: %s", err)
}

src, ok := isrc.(*bzrSource)
if !ok {
t.Errorf("Expected a bzrSource, got a %T", isrc)
t.FailNow()
t.Fatalf("Expected a bzrSource, got a %T", isrc)
}

if state != wantstate {
Expand Down Expand Up @@ -428,8 +418,7 @@ func testHgSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Errorf("Error on cloning git repo: %s", err)
t.FailNow()
t.Fatalf("Error on cloning git repo: %s", err)
}

src, ok := isrc.(*hgSource)
Expand Down
3 changes: 1 addition & 2 deletions version_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ func TestVersionQueueAdvance(t *testing.T) {
// First with no prefv or lockv
vq, err := newVersionQueue(id, nil, nil, fb)
if err != nil {
t.Errorf("Unexpected err on vq create: %s", err)
t.FailNow()
t.Fatalf("Unexpected err on vq create: %s", err)
}

for k, v := range fakevl[1:] {
Expand Down

0 comments on commit 1b6303f

Please sign in to comment.