github.com/tiagovtristao/plz@v13.4.0+incompatible/src/query/changes_test.go (about) 1 package query 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/thought-machine/please/src/core" 9 ) 10 11 func TestTargetsChanged(t *testing.T) { 12 s1 := core.NewDefaultBuildState() 13 s2 := core.NewDefaultBuildState() 14 t1 := addTarget(s1, "//src/query:changes", nil, "src/query/changes.go") 15 t2 := addTarget(s2, "//src/query:changes", nil, "src/query/changes.go") 16 addTarget(s1, "//src/query:changes_test", t1, "src/query/changes_test.go") 17 t4 := addTarget(s2, "//src/query:changes_test", t2, "src/query/changes_test.go") 18 assert.EqualValues(t, []core.BuildLabel{}, DiffGraphs(s1, s2, nil)) 19 20 t2.Command = "nope nope nope" 21 assert.EqualValues(t, []core.BuildLabel{t2.Label, t4.Label}, DiffGraphs(s1, s2, nil)) 22 23 t2.AddLabel("nope") 24 s2.SetIncludeAndExclude(nil, []string{"nope"}) 25 assert.EqualValues(t, []core.BuildLabel{}, DiffGraphs(s1, s2, nil)) 26 } 27 28 func addTarget(state *core.BuildState, label string, dep *core.BuildTarget, sources ...string) *core.BuildTarget { 29 t := core.NewBuildTarget(core.ParseBuildLabel(label, "")) 30 for _, src := range sources { 31 t.AddSource(core.FileLabel{ 32 File: src, 33 Package: t.Label.PackageName, 34 }) 35 } 36 state.Graph.AddTarget(t) 37 if dep != nil { 38 t.AddDependency(dep.Label) 39 state.Graph.AddDependency(t.Label, dep.Label) 40 } 41 return t 42 }