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

Collect Applicable Constraints #1480

Merged
merged 4 commits into from
Dec 29, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 5 additions & 0 deletions cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,11 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) (con
// Iterate through the project constraints to get individual dependency
// project and constraint values.
for pr, pp := range pc {
// Check if the project constraint is imported in the root project
if _, ok := directDeps[string(pr)]; !ok {
continue
}

tempCC := append(
constraintCollection[string(pr)],
projectConstraint{proj.Ident().ProjectRoot, pp.Constraint},
Expand Down
32 changes: 32 additions & 0 deletions cmd/dep/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ func TestCollectConstraints(t *testing.T) {
ver1, _ := gps.NewSemverConstraintIC("v1.0.0")
ver08, _ := gps.NewSemverConstraintIC("v0.8.0")
ver2, _ := gps.NewSemverConstraintIC("v2.0.0")
master := gps.NewBranch("master")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be used inline. Other's are not inline because they do not return single value.


cases := []struct {
name string
Expand Down Expand Up @@ -382,13 +383,44 @@ func TestCollectConstraints(t *testing.T) {
},
wantErr: true,
},
{
name: "collect only applicable constraints",
lock: dep.Lock{
P: []gps.LockedProject{
gps.NewLockedProject(
gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot("github.com/JackyChiu/dep-applicable-constraints")},
gps.NewVersion("v1.0.0"),
[]string{"."},
),
},
},
wantConstraints: constraintsCollection{
"github.com/boltdb/bolt": []projectConstraint{
{"github.com/JackyChiu/dep-applicable-constraints", master},
},
"github.com/sdboyer/deptest": []projectConstraint{
{"github.com/JackyChiu/dep-applicable-constraints", ver08},
},
},
},
}

h := test.NewHelper(t)
defer h.Cleanup()

h.TempDir("src")
pwd := h.Path(".")
h.TempFile(filepath.Join("src", "dep.go"), `
package dep
import (
_ "github.com/boltdb/bolt"
_ "github.com/sdboyer/deptest"
_ "github.com/sdboyer/dep-test"
_ "github.com/sdboyer/deptestdos"
)
type FooBar int
`)

discardLogger := log.New(ioutil.Discard, "", 0)

ctx := &dep.Ctx{
Expand Down