Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Add satisfiability check for case variants #1079

Merged
merged 14 commits into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tests for combined source & case variance
  • Loading branch information
sdboyer committed Sep 10, 2017
commit 70d2f5b6950c69d130d12cfb96f91dbe9c80d2be
62 changes: 45 additions & 17 deletions internal/gps/solve_bimodal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,38 +847,56 @@ var bimodalFixtures = map[string]bimodalFixture{
),
},
"simple case-only variations plus source variance": {
// COPYPASTA BELOW, FIX IT
ds: []depspec{
dsp(mkDepspec("root 0.0.0"),
pkg("root", "foo", "Bar")), // TODO align the froms
pkg("root", "foo", "bar")),
dsp(mkDepspec("foo 1.0.0", "Bar from quux 1.0.0"),
pkg("foo", "Bar")),
dsp(mkDepspec("bar 1.0.0"),
pkg("bar")),
dsp(mkDepspec("quux 1.0.0"),
pkg("bar")),
},
r: mksolution(
"foo 1.0.0",
"Bar from quux 1.0.0",
),
fail: &noVersionError{
pn: mkPI("foo"),
fails: []failedVersion{
{
v: NewVersion("1.0.0"),
f: &caseMismatchFailure{
goal: mkDep("foo 1.0.0", "Bar from quux 1.0.0", "Bar"),
current: ProjectRoot("bar"),
failsib: []dependency{mkDep("root", "bar 1.0.0", "bar")},
},
},
},
},
},
"case-only variations plus source variance with internal canonicality": {
// COPYPASTA BELOW, FIX IT
ds: []depspec{
dsp(mkDepspec("root 0.0.0"),
dsp(mkDepspec("root 0.0.0", "Bar from quux 1.0.0"),
pkg("root", "foo", "Bar")),
dsp(mkDepspec("foo 1.0.0", "Bar from quux 1.0.0"),
pkg("foo", "Bar")),
dsp(mkDepspec("bar 1.0.0"),
pkg("bar")),
pkg("bar", "bar/subpkg"),
pkg("bar/subpkg")),
dsp(mkDepspec("quux 1.0.0"),
pkg("bar")),
pkg("bar", "bar/subpkg"),
pkg("bar/subpkg")),
},
fail: &noVersionError{
pn: mkPI("Bar"),
fails: []failedVersion{
{
v: NewVersion("1.0.0"),
f: &wrongCaseFailure{
correct: ProjectRoot("bar"),
goal: mkDep("Bar from quux 1.0.0", "bar 1.0.0", "bar"),
badcase: []dependency{mkDep("root", "Bar 1.0.0", "Bar/subpkg")},
},
},
},
},
r: mksolution(
"foo 1.0.0",
"Bar from quux 1.0.0",
),
},
"alternate net address": {
ds: []depspec{
Expand Down Expand Up @@ -1387,12 +1405,22 @@ func newbmSM(bmf bimodalFixture) *bmSourceManager {
}

func (sm *bmSourceManager) ListPackages(id ProjectIdentifier, v Version) (pkgtree.PackageTree, error) {
src, fsrc := id.normalizedSource(), toFold(id.normalizedSource())
// Deal with address-based root-switching with both case folding and
// alternate sources.
var src, fsrc, root, froot string
src, fsrc = id.normalizedSource(), toFold(id.normalizedSource())
if id.Source != "" {
root = string(id.ProjectRoot)
froot = toFold(root)
} else {
root, froot = src, fsrc
}

for k, ds := range sm.specs {
// Cheat for root, otherwise we blow up b/c version is empty
if fsrc == string(ds.n) && (k == 0 || ds.v.Matches(v)) {
var replace bool
if src != string(ds.n) {
if root != string(ds.n) {
// We're in a case-varying lookup; ensure we replace the actual
// leading ProjectRoot portion of import paths with the literal
// string from the input.
Expand All @@ -1405,7 +1433,7 @@ func (sm *bmSourceManager) ListPackages(id ProjectIdentifier, v Version) (pkgtre
}
for _, pkg := range ds.pkgs {
if replace {
pkg.path = strings.Replace(pkg.path, fsrc, src, 1)
pkg.path = strings.Replace(pkg.path, froot, root, 1)
}
ptree.Packages[pkg.path] = pkgtree.PackageOrErr{
P: pkgtree.Package{
Expand Down
4 changes: 2 additions & 2 deletions internal/gps/solve_failures.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ type wrongCaseFailure struct {

func (e *wrongCaseFailure) Error() string {
if len(e.badcase) == 1 {
str := "Could not introduce %s; mutual imports by its packages establish %q as the canonical casing for root, but %s tried to import it as %q"
str := "Could not introduce %s; imports amongst its packages establish %q as the canonical casing for root, but %s tried to import it as %q"
return fmt.Sprintf(str, a2vs(e.goal.depender), e.correct, a2vs(e.badcase[0].depender), e.badcase[0].dep.Ident.ProjectRoot)
}

var buf bytes.Buffer

str := "Could not introduce %s; mutual imports by its packages establish %q as the canonical casing for root, but the following projects tried to import it as %q"
str := "Could not introduce %s; imports amongst its packages establish %q as the canonical casing for root, but the following projects tried to import it as %q"
fmt.Fprintf(&buf, str, a2vs(e.goal.depender), e.correct, e.badcase[0].dep.Ident.ProjectRoot)

for _, c := range e.badcase {
Expand Down