Skip to content

Commit

Permalink
SubTests for TestDeduceFromPath
Browse files Browse the repository at this point in the history
  • Loading branch information
zbintliff committed Mar 5, 2017
1 parent 39533be commit f672656
Showing 1 changed file with 88 additions and 84 deletions.
172 changes: 88 additions & 84 deletions deduce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,98 +467,102 @@ var pathDeductionFixtures = map[string][]pathDeductionFixture{

func TestDeduceFromPath(t *testing.T) {
for typ, fixtures := range pathDeductionFixtures {
var deducer pathDeducer
switch typ {
case "github":
deducer = githubDeducer{regexp: ghRegex}
case "gopkg.in":
deducer = gopkginDeducer{regexp: gpinNewRegex}
case "jazz":
deducer = jazzDeducer{regexp: jazzRegex}
case "bitbucket":
deducer = bitbucketDeducer{regexp: bbRegex}
case "launchpad":
deducer = launchpadDeducer{regexp: lpRegex}
case "git.launchpad":
deducer = launchpadGitDeducer{regexp: glpRegex}
case "apache":
deducer = apacheDeducer{regexp: apacheRegex}
case "vcsext":
deducer = vcsExtensionDeducer{regexp: vcsExtensionRegex}
default:
// Should just be the vanity imports, which we do elsewhere
continue
}

var printmb func(mb maybeSource) string
printmb = func(mb maybeSource) string {
switch tmb := mb.(type) {
case maybeSources:
var buf bytes.Buffer
fmt.Fprintf(&buf, "%v maybeSources:", len(tmb))
for _, elem := range tmb {
fmt.Fprintf(&buf, "\n\t\t%s", printmb(elem))
}
return buf.String()
case maybeGitSource:
return fmt.Sprintf("%T: %s", tmb, ufmt(tmb.url))
case maybeBzrSource:
return fmt.Sprintf("%T: %s", tmb, ufmt(tmb.url))
case maybeHgSource:
return fmt.Sprintf("%T: %s", tmb, ufmt(tmb.url))
case maybeGopkginSource:
return fmt.Sprintf("%T: %s (v%v) %s ", tmb, tmb.opath, tmb.major, ufmt(tmb.url))
t.Run(fmt.Sprintf("%s", typ), func(t *testing.T) {
var deducer pathDeducer
switch typ {
case "github":
deducer = githubDeducer{regexp: ghRegex}
case "gopkg.in":
deducer = gopkginDeducer{regexp: gpinNewRegex}
case "jazz":
deducer = jazzDeducer{regexp: jazzRegex}
case "bitbucket":
deducer = bitbucketDeducer{regexp: bbRegex}
case "launchpad":
deducer = launchpadDeducer{regexp: lpRegex}
case "git.launchpad":
deducer = launchpadGitDeducer{regexp: glpRegex}
case "apache":
deducer = apacheDeducer{regexp: apacheRegex}
case "vcsext":
deducer = vcsExtensionDeducer{regexp: vcsExtensionRegex}
default:
t.Errorf("Unknown maybeSource type: %T", mb)
t.FailNow()
// Should just be the vanity imports, which we do elsewhere
t.Log("skipping")
t.SkipNow()
}
return ""
}

for _, fix := range fixtures {
u, in, uerr := normalizeURI(fix.in)
if uerr != nil {
if fix.rerr == nil {
t.Errorf("(in: %s) bad input URI %s", fix.in, uerr)
var printmb func(mb maybeSource, t *testing.T) string
printmb = func(mb maybeSource, t *testing.T) string {
switch tmb := mb.(type) {
case maybeSources:
var buf bytes.Buffer
fmt.Fprintf(&buf, "%v maybeSources:", len(tmb))
for _, elem := range tmb {
fmt.Fprintf(&buf, "\n\t\t%s", printmb(elem, t))
}
return buf.String()
case maybeGitSource:
return fmt.Sprintf("%T: %s", tmb, ufmt(tmb.url))
case maybeBzrSource:
return fmt.Sprintf("%T: %s", tmb, ufmt(tmb.url))
case maybeHgSource:
return fmt.Sprintf("%T: %s", tmb, ufmt(tmb.url))
case maybeGopkginSource:
return fmt.Sprintf("%T: %s (v%v) %s ", tmb, tmb.opath, tmb.major, ufmt(tmb.url))
default:
t.Errorf("Unknown maybeSource type: %T", mb)
}
continue
return ""
}

root, rerr := deducer.deduceRoot(in)
if fix.rerr != nil {
if rerr == nil {
t.Errorf("(in: %s, %T) Expected error on deducing root, got none:\n\t(WNT) %s", in, deducer, fix.rerr)
} else if fix.rerr.Error() != rerr.Error() {
t.Errorf("(in: %s, %T) Got unexpected error on deducing root:\n\t(GOT) %s\n\t(WNT) %s", in, deducer, rerr, fix.rerr)
}
} else if rerr != nil {
t.Errorf("(in: %s, %T) Got unexpected error on deducing root:\n\t(GOT) %s", in, deducer, rerr)
} else if root != fix.root {
t.Errorf("(in: %s, %T) Deducer did not return expected root:\n\t(GOT) %s\n\t(WNT) %s", in, deducer, root, fix.root)
}
for _, fix := range fixtures {
t.Run(fmt.Sprintf("(in: %s)", fix.in), func(t *testing.T) {
u, in, uerr := normalizeURI(fix.in)
if uerr != nil {
if fix.rerr == nil {
t.Errorf("bad input URI %s", fix.in, uerr)
}
t.SkipNow()
}

mb, mberr := deducer.deduceSource(in, u)
if fix.srcerr != nil {
if mberr == nil {
t.Errorf("(in: %s, %T) Expected error on deducing source, got none:\n\t(WNT) %s", in, deducer, fix.srcerr)
} else if fix.srcerr.Error() != mberr.Error() {
t.Errorf("(in: %s, %T) Got unexpected error on deducing source:\n\t(GOT) %s\n\t(WNT) %s", in, deducer, mberr, fix.srcerr)
}
} else if mberr != nil {
// don't complain the fix already expected an rerr
if fix.rerr == nil {
t.Errorf("(in: %s, %T) Got unexpected error on deducing source:\n\t(GOT) %s", in, deducer, mberr)
}
} else if !reflect.DeepEqual(mb, fix.mb) {
if mb == nil {
t.Errorf("(in: %s, %T) Deducer returned source maybes, but none expected:\n\t(GOT) (none)\n\t(WNT) %s", in, deducer, printmb(fix.mb))
} else if fix.mb == nil {
t.Errorf("(in: %s, %T) Deducer returned source maybes, but none expected:\n\t(GOT) %s\n\t(WNT) (none)", in, deducer, printmb(mb))
} else {
t.Errorf("(in: %s, %T) Deducer did not return expected source:\n\t(GOT) %s\n\t(WNT) %s", in, deducer, printmb(mb), printmb(fix.mb))
}
root, rerr := deducer.deduceRoot(in)
if fix.rerr != nil {
if rerr == nil {
t.Errorf("Expected error on deducing root, got none:\n\t(WNT) %s", fix.rerr)
} else if fix.rerr.Error() != rerr.Error() {
t.Errorf("Got unexpected error on deducing root:\n\t(GOT) %s\n\t(WNT) %s", rerr, fix.rerr)
}
} else if rerr != nil {
t.Errorf("Got unexpected error on deducing root:\n\t(GOT) %s", rerr)
} else if root != fix.root {
t.Errorf("Deducer did not return expected root:\n\t(GOT) %s\n\t(WNT) %s", root, fix.root)
}

mb, mberr := deducer.deduceSource(in, u)
if fix.srcerr != nil {
if mberr == nil {
t.Errorf("Expected error on deducing source, got none:\n\t(WNT) %s", fix.srcerr)
} else if fix.srcerr.Error() != mberr.Error() {
t.Errorf("Got unexpected error on deducing source:\n\t(GOT) %s\n\t(WNT) %s", mberr, fix.srcerr)
}
} else if mberr != nil {
// don't complain the fix already expected an rerr
if fix.rerr == nil {
t.Errorf("Got unexpected error on deducing source:\n\t(GOT) %s", mberr)
}
} else if !reflect.DeepEqual(mb, fix.mb) {
if mb == nil {
t.Errorf("Deducer returned source maybes, but none expected:\n\t(GOT) (none)\n\t(WNT) %s", printmb(fix.mb, t))
} else if fix.mb == nil {
t.Errorf("Deducer returned source maybes, but none expected:\n\t(GOT) %s\n\t(WNT) (none)", printmb(mb, t))
} else {
t.Errorf("Deducer did not return expected source:\n\t(GOT) %s\n\t(WNT) %s", printmb(mb, t), printmb(fix.mb, t))
}
}
})
}
}
})
}
}

Expand Down

0 comments on commit f672656

Please sign in to comment.