This repository has been archived by the owner on Feb 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsolve_basic_test.go
1648 lines (1538 loc) · 42.1 KB
/
solve_basic_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package gps
import (
"fmt"
"regexp"
"strings"
"github.com/Masterminds/semver"
"github.com/sdboyer/gps/pkgtree"
)
var regfrom = regexp.MustCompile(`^(\w*) from (\w*) ([0-9\.\*]*)`)
// nvSplit splits an "info" string on " " into the pair of name and
// version/constraint, and returns each individually.
//
// This is for narrow use - panics if there are less than two resulting items in
// the slice.
func nvSplit(info string) (id ProjectIdentifier, version string) {
if strings.Contains(info, " from ") {
parts := regfrom.FindStringSubmatch(info)
info = parts[1] + " " + parts[3]
id.Source = parts[2]
}
s := strings.SplitN(info, " ", 2)
if len(s) < 2 {
panic(fmt.Sprintf("Malformed name/version info string '%s'", info))
}
id.ProjectRoot, version = ProjectRoot(s[0]), s[1]
return
}
// nvrSplit splits an "info" string on " " into the triplet of name,
// version/constraint, and revision, and returns each individually.
//
// It will work fine if only name and version/constraint are provided.
//
// This is for narrow use - panics if there are less than two resulting items in
// the slice.
func nvrSplit(info string) (id ProjectIdentifier, version string, revision Revision) {
if strings.Contains(info, " from ") {
parts := regfrom.FindStringSubmatch(info)
info = fmt.Sprintf("%s %s", parts[1], parts[3])
id.Source = parts[2]
}
s := strings.SplitN(info, " ", 3)
if len(s) < 2 {
panic(fmt.Sprintf("Malformed name/version info string '%s'", info))
}
id.ProjectRoot, version = ProjectRoot(s[0]), s[1]
if len(s) == 3 {
revision = Revision(s[2])
}
return
}
// mkAtom splits the input string on a space, and uses the first two elements as
// the project identifier and version, respectively.
//
// The version segment may have a leading character indicating the type of
// version to create:
//
// p: create a "plain" (non-semver) version.
// b: create a branch version.
// r: create a revision.
//
// No prefix is assumed to indicate a semver version.
//
// If a third space-delimited element is provided, it will be interepreted as a
// revision, and used as the underlying version in a PairedVersion. No prefix
// should be provided in this case. It is an error (and will panic) to try to
// pass a revision with an underlying revision.
func mkAtom(info string) atom {
// if info is "root", special case it to use the root "version"
if info == "root" {
return atom{
id: ProjectIdentifier{
ProjectRoot: ProjectRoot("root"),
},
v: rootRev,
}
}
id, ver, rev := nvrSplit(info)
var v Version
switch ver[0] {
case 'r':
if rev != "" {
panic("Cannot pair a revision with a revision")
}
v = Revision(ver[1:])
case 'p':
v = NewVersion(ver[1:])
case 'b':
v = NewBranch(ver[1:])
default:
_, err := semver.NewVersion(ver)
if err != nil {
// don't want to allow bad test data at this level, so just panic
panic(fmt.Sprintf("Error when converting '%s' into semver: %s", ver, err))
}
v = NewVersion(ver)
}
if rev != "" {
v = v.(UnpairedVersion).Is(rev)
}
return atom{
id: id,
v: v,
}
}
// mkPCstrnt splits the input string on a space, and uses the first two elements
// as the project identifier and constraint body, respectively.
//
// The constraint body may have a leading character indicating the type of
// version to create:
//
// p: create a "plain" (non-semver) version.
// b: create a branch version.
// r: create a revision.
//
// If no leading character is used, a semver constraint is assumed.
func mkPCstrnt(info string) ProjectConstraint {
id, ver, rev := nvrSplit(info)
var c Constraint
switch ver[0] {
case 'r':
c = Revision(ver[1:])
case 'p':
c = NewVersion(ver[1:])
case 'b':
c = NewBranch(ver[1:])
default:
// Without one of those leading characters, we know it's a proper semver
// expression, so use the other parser that doesn't look for a rev
rev = ""
id, ver = nvSplit(info)
var err error
c, err = NewSemverConstraint(ver)
if err != nil {
// don't want bad test data at this level, so just panic
panic(fmt.Sprintf("Error when converting '%s' into semver constraint: %s (full info: %s)", ver, err, info))
}
}
// There's no practical reason that a real tool would need to produce a
// constraint that's a PairedVersion, but it is a possibility admitted by the
// system, so we at least allow for it in our testing harness.
if rev != "" {
// Of course, this *will* panic if the predicate is a revision or a
// semver constraint, neither of which implement UnpairedVersion. This
// is as intended, to prevent bad data from entering the system.
c = c.(UnpairedVersion).Is(rev)
}
return ProjectConstraint{
Ident: id,
Constraint: c,
}
}
// mkCDep composes a completeDep struct from the inputs.
//
// The only real work here is passing the initial string to mkPDep. All the
// other args are taken as package names.
func mkCDep(pdep string, pl ...string) completeDep {
pc := mkPCstrnt(pdep)
return completeDep{
workingConstraint: workingConstraint{
Ident: pc.Ident,
Constraint: pc.Constraint,
},
pl: pl,
}
}
// A depspec is a fixture representing all the information a SourceManager would
// ordinarily glean directly from interrogating a repository.
type depspec struct {
n ProjectRoot
v Version
deps []ProjectConstraint
devdeps []ProjectConstraint
pkgs []tpkg
}
// mkDepspec creates a depspec by processing a series of strings, each of which
// contains an identiifer and version information.
//
// The first string is broken out into the name and version of the package being
// described - see the docs on mkAtom for details. subsequent strings are
// interpreted as dep constraints of that dep at that version. See the docs on
// mkPDep for details.
//
// If a string other than the first includes a "(dev) " prefix, it will be
// treated as a test-only dependency.
func mkDepspec(pi string, deps ...string) depspec {
pa := mkAtom(pi)
if string(pa.id.ProjectRoot) != pa.id.Source && pa.id.Source != "" {
panic("alternate source on self makes no sense")
}
ds := depspec{
n: pa.id.ProjectRoot,
v: pa.v,
}
for _, dep := range deps {
var sl *[]ProjectConstraint
if strings.HasPrefix(dep, "(dev) ") {
dep = strings.TrimPrefix(dep, "(dev) ")
sl = &ds.devdeps
} else {
sl = &ds.deps
}
*sl = append(*sl, mkPCstrnt(dep))
}
return ds
}
func mkDep(atom, pdep string, pl ...string) dependency {
return dependency{
depender: mkAtom(atom),
dep: mkCDep(pdep, pl...),
}
}
func mkADep(atom, pdep string, c Constraint, pl ...string) dependency {
return dependency{
depender: mkAtom(atom),
dep: completeDep{
workingConstraint: workingConstraint{
Ident: ProjectIdentifier{
ProjectRoot: ProjectRoot(pdep),
},
Constraint: c,
},
pl: pl,
},
}
}
// mkPI creates a ProjectIdentifier with the ProjectRoot as the provided
// string, and the Source unset.
//
// Call normalize() on the returned value if you need the Source to be be
// equal to the ProjectRoot.
func mkPI(root string) ProjectIdentifier {
return ProjectIdentifier{
ProjectRoot: ProjectRoot(root),
}
}
// mkSVC creates a new semver constraint, panicking if an error is returned.
func mkSVC(body string) Constraint {
c, err := NewSemverConstraint(body)
if err != nil {
panic(fmt.Sprintf("Error while trying to create semver constraint from %s: %s", body, err.Error()))
}
return c
}
// mklock makes a fixLock, suitable to act as a lock file
func mklock(pairs ...string) fixLock {
l := make(fixLock, 0)
for _, s := range pairs {
pa := mkAtom(s)
l = append(l, NewLockedProject(pa.id, pa.v, nil))
}
return l
}
// mkrevlock makes a fixLock, suitable to act as a lock file, with only a name
// and a rev
func mkrevlock(pairs ...string) fixLock {
l := make(fixLock, 0)
for _, s := range pairs {
pa := mkAtom(s)
l = append(l, NewLockedProject(pa.id, pa.v.(PairedVersion).Underlying(), nil))
}
return l
}
// mksolution creates a map of project identifiers to their LockedProject
// result, which is sufficient to act as a solution fixture for the purposes of
// most tests.
//
// Either strings or LockedProjects can be provided. If a string is provided, it
// is assumed that we're in the default, "basic" case where there is exactly one
// package in a project, and it is the root of the project - meaning that only
// the "." package should be listed. If a LockedProject is provided (e.g. as
// returned from mklp()), then it's incorporated directly.
//
// If any other type is provided, the func will panic.
func mksolution(inputs ...interface{}) map[ProjectIdentifier]LockedProject {
m := make(map[ProjectIdentifier]LockedProject)
for _, in := range inputs {
switch t := in.(type) {
case string:
a := mkAtom(t)
m[a.id] = NewLockedProject(a.id, a.v, []string{"."})
case LockedProject:
m[t.pi] = t
default:
panic(fmt.Sprintf("unexpected input to mksolution: %T %s", in, in))
}
}
return m
}
// mklp creates a LockedProject from string inputs
func mklp(pair string, pkgs ...string) LockedProject {
a := mkAtom(pair)
return NewLockedProject(a.id, a.v, pkgs)
}
// computeBasicReachMap takes a depspec and computes a reach map which is
// identical to the explicit depgraph.
//
// Using a reachMap here is overkill for what the basic fixtures actually need,
// but we use it anyway for congruence with the more general cases.
func computeBasicReachMap(ds []depspec) reachMap {
rm := make(reachMap)
for k, d := range ds {
n := string(d.n)
lm := map[string][]string{
n: nil,
}
v := d.v
if k == 0 {
// Put the root in with a nil rev, to accommodate the solver
v = nil
}
rm[pident{n: d.n, v: v}] = lm
for _, dep := range d.deps {
lm[n] = append(lm[n], string(dep.Ident.ProjectRoot))
}
// first is root
if k == 0 {
for _, dep := range d.devdeps {
lm[n] = append(lm[n], string(dep.Ident.ProjectRoot))
}
}
}
return rm
}
type pident struct {
n ProjectRoot
v Version
}
type specfix interface {
name() string
rootmanifest() RootManifest
rootTree() pkgtree.PackageTree
specs() []depspec
maxTries() int
solution() map[ProjectIdentifier]LockedProject
failure() error
}
// A basicFixture is a declarative test fixture that can cover a wide variety of
// solver cases. All cases, however, maintain one invariant: package == project.
// There are no subpackages, and so it is impossible for them to trigger or
// require bimodal solving.
//
// This type is separate from bimodalFixture in part for legacy reasons - many
// of these were adapted from similar tests in dart's pub lib, where there is no
// such thing as "bimodal solving".
//
// But it's also useful to keep them separate because bimodal solving involves
// considerably more complexity than simple solving, both in terms of fixture
// declaration and actual solving mechanics. Thus, we gain a lot of value for
// contributors and maintainers by keeping comprehension costs relatively low
// while still covering important cases.
type basicFixture struct {
// name of this fixture datum
n string
// depspecs. always treat first as root
ds []depspec
// results; map of name/atom pairs
r map[ProjectIdentifier]LockedProject
// max attempts the solver should need to find solution. 0 means no limit
maxAttempts int
// Use downgrade instead of default upgrade sorter
downgrade bool
// lock file simulator, if one's to be used at all
l fixLock
// solve failure expected, if any
fail error
// overrides, if any
ovr ProjectConstraints
// request up/downgrade to all projects
changeall bool
// individual projects to change
changelist []ProjectRoot
}
func (f basicFixture) name() string {
return f.n
}
func (f basicFixture) specs() []depspec {
return f.ds
}
func (f basicFixture) maxTries() int {
return f.maxAttempts
}
func (f basicFixture) solution() map[ProjectIdentifier]LockedProject {
return f.r
}
func (f basicFixture) rootmanifest() RootManifest {
return simpleRootManifest{
c: pcSliceToMap(f.ds[0].deps),
tc: pcSliceToMap(f.ds[0].devdeps),
ovr: f.ovr,
}
}
func (f basicFixture) rootTree() pkgtree.PackageTree {
var imp, timp []string
for _, dep := range f.ds[0].deps {
imp = append(imp, string(dep.Ident.ProjectRoot))
}
for _, dep := range f.ds[0].devdeps {
timp = append(timp, string(dep.Ident.ProjectRoot))
}
n := string(f.ds[0].n)
pt := pkgtree.PackageTree{
ImportRoot: n,
Packages: map[string]pkgtree.PackageOrErr{
string(n): {
P: pkgtree.Package{
ImportPath: n,
Name: n,
Imports: imp,
TestImports: timp,
},
},
},
}
return pt
}
func (f basicFixture) failure() error {
return f.fail
}
// A table of basicFixtures, used in the basic solving test set.
var basicFixtures = map[string]basicFixture{
// basic fixtures
"no dependencies": {
ds: []depspec{
mkDepspec("root 0.0.0"),
},
r: mksolution(),
},
"simple dependency tree": {
ds: []depspec{
mkDepspec("root 0.0.0", "a 1.0.0", "b 1.0.0"),
mkDepspec("a 1.0.0", "aa 1.0.0", "ab 1.0.0"),
mkDepspec("aa 1.0.0"),
mkDepspec("ab 1.0.0"),
mkDepspec("b 1.0.0", "ba 1.0.0", "bb 1.0.0"),
mkDepspec("ba 1.0.0"),
mkDepspec("bb 1.0.0"),
},
r: mksolution(
"a 1.0.0",
"aa 1.0.0",
"ab 1.0.0",
"b 1.0.0",
"ba 1.0.0",
"bb 1.0.0",
),
},
"shared dependency with overlapping constraints": {
ds: []depspec{
mkDepspec("root 0.0.0", "a 1.0.0", "b 1.0.0"),
mkDepspec("a 1.0.0", "shared >=2.0.0, <4.0.0"),
mkDepspec("b 1.0.0", "shared >=3.0.0, <5.0.0"),
mkDepspec("shared 2.0.0"),
mkDepspec("shared 3.0.0"),
mkDepspec("shared 3.6.9"),
mkDepspec("shared 4.0.0"),
mkDepspec("shared 5.0.0"),
},
r: mksolution(
"a 1.0.0",
"b 1.0.0",
"shared 3.6.9",
),
},
"downgrade on overlapping constraints": {
ds: []depspec{
mkDepspec("root 0.0.0", "a 1.0.0", "b 1.0.0"),
mkDepspec("a 1.0.0", "shared >=2.0.0, <=4.0.0"),
mkDepspec("b 1.0.0", "shared >=3.0.0, <5.0.0"),
mkDepspec("shared 2.0.0"),
mkDepspec("shared 3.0.0"),
mkDepspec("shared 3.6.9"),
mkDepspec("shared 4.0.0"),
mkDepspec("shared 5.0.0"),
},
r: mksolution(
"a 1.0.0",
"b 1.0.0",
"shared 3.0.0",
),
downgrade: true,
},
"shared dependency where dependent version in turn affects other dependencies": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo <=1.0.2", "bar 1.0.0"),
mkDepspec("foo 1.0.0"),
mkDepspec("foo 1.0.1", "bang 1.0.0"),
mkDepspec("foo 1.0.2", "whoop 1.0.0"),
mkDepspec("foo 1.0.3", "zoop 1.0.0"),
mkDepspec("bar 1.0.0", "foo <=1.0.1"),
mkDepspec("bang 1.0.0"),
mkDepspec("whoop 1.0.0"),
mkDepspec("zoop 1.0.0"),
},
r: mksolution(
"foo 1.0.1",
"bar 1.0.0",
"bang 1.0.0",
),
},
"removed dependency": {
ds: []depspec{
mkDepspec("root 1.0.0", "foo 1.0.0", "bar *"),
mkDepspec("foo 1.0.0"),
mkDepspec("foo 2.0.0"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 2.0.0", "baz 1.0.0"),
mkDepspec("baz 1.0.0", "foo 2.0.0"),
},
r: mksolution(
"foo 1.0.0",
"bar 1.0.0",
),
maxAttempts: 2,
},
// fixtures with locks
"with compatible locked dependency": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.1", "bar 1.0.1"),
mkDepspec("foo 1.0.2", "bar 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
},
l: mklock(
"foo 1.0.1",
),
r: mksolution(
"foo 1.0.1",
"bar 1.0.1",
),
},
"upgrade through lock": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.1", "bar 1.0.1"),
mkDepspec("foo 1.0.2", "bar 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
},
l: mklock(
"foo 1.0.1",
),
r: mksolution(
"foo 1.0.2",
"bar 1.0.2",
),
changeall: true,
},
"downgrade through lock": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.1", "bar 1.0.1"),
mkDepspec("foo 1.0.2", "bar 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
},
l: mklock(
"foo 1.0.1",
),
r: mksolution(
"foo 1.0.0",
"bar 1.0.0",
),
changeall: true,
downgrade: true,
},
"update one with only one": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *"),
mkDepspec("foo 1.0.0"),
mkDepspec("foo 1.0.1"),
mkDepspec("foo 1.0.2"),
},
l: mklock(
"foo 1.0.1",
),
r: mksolution(
"foo 1.0.2",
),
changelist: []ProjectRoot{"foo"},
},
"update one of multi": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *", "bar *"),
mkDepspec("foo 1.0.0"),
mkDepspec("foo 1.0.1"),
mkDepspec("foo 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
},
l: mklock(
"foo 1.0.1",
"bar 1.0.1",
),
r: mksolution(
"foo 1.0.2",
"bar 1.0.1",
),
changelist: []ProjectRoot{"foo"},
},
"update both of multi": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *", "bar *"),
mkDepspec("foo 1.0.0"),
mkDepspec("foo 1.0.1"),
mkDepspec("foo 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
},
l: mklock(
"foo 1.0.1",
"bar 1.0.1",
),
r: mksolution(
"foo 1.0.2",
"bar 1.0.2",
),
changelist: []ProjectRoot{"foo", "bar"},
},
"update two of more": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *", "bar *", "baz *"),
mkDepspec("foo 1.0.0"),
mkDepspec("foo 1.0.1"),
mkDepspec("foo 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
mkDepspec("baz 1.0.0"),
mkDepspec("baz 1.0.1"),
mkDepspec("baz 1.0.2"),
},
l: mklock(
"foo 1.0.1",
"bar 1.0.1",
"baz 1.0.1",
),
r: mksolution(
"foo 1.0.2",
"bar 1.0.2",
"baz 1.0.1",
),
changelist: []ProjectRoot{"foo", "bar"},
},
"break other lock with targeted update": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *", "baz *"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.1", "bar 1.0.1"),
mkDepspec("foo 1.0.2", "bar 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
mkDepspec("baz 1.0.0"),
mkDepspec("baz 1.0.1"),
mkDepspec("baz 1.0.2"),
},
l: mklock(
"foo 1.0.1",
"bar 1.0.1",
"baz 1.0.1",
),
r: mksolution(
"foo 1.0.2",
"bar 1.0.2",
"baz 1.0.1",
),
changelist: []ProjectRoot{"foo", "bar"},
},
"with incompatible locked dependency": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo >1.0.1"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.1", "bar 1.0.1"),
mkDepspec("foo 1.0.2", "bar 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
},
l: mklock(
"foo 1.0.1",
),
r: mksolution(
"foo 1.0.2",
"bar 1.0.2",
),
},
"with unrelated locked dependency": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.1", "bar 1.0.1"),
mkDepspec("foo 1.0.2", "bar 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
mkDepspec("baz 1.0.0 bazrev"),
},
l: mklock(
"baz 1.0.0 bazrev",
),
r: mksolution(
"foo 1.0.2",
"bar 1.0.2",
),
},
"unlocks dependencies if necessary to ensure that a new dependency is satisfied": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *", "newdep *"),
mkDepspec("foo 1.0.0 foorev", "bar <2.0.0"),
mkDepspec("bar 1.0.0 barrev", "baz <2.0.0"),
mkDepspec("baz 1.0.0 bazrev", "qux <2.0.0"),
mkDepspec("qux 1.0.0 quxrev"),
mkDepspec("foo 2.0.0", "bar <3.0.0"),
mkDepspec("bar 2.0.0", "baz <3.0.0"),
mkDepspec("baz 2.0.0", "qux <3.0.0"),
mkDepspec("qux 2.0.0"),
mkDepspec("newdep 2.0.0", "baz >=1.5.0"),
},
l: mklock(
"foo 1.0.0 foorev",
"bar 1.0.0 barrev",
"baz 1.0.0 bazrev",
"qux 1.0.0 quxrev",
),
r: mksolution(
"foo 2.0.0",
"bar 2.0.0",
"baz 2.0.0",
"qux 1.0.0 quxrev",
"newdep 2.0.0",
),
maxAttempts: 4,
},
"break lock when only the deps necessitate it": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *", "bar *"),
mkDepspec("foo 1.0.0 foorev", "bar <2.0.0"),
mkDepspec("foo 2.0.0", "bar <3.0.0"),
mkDepspec("bar 2.0.0", "baz <3.0.0"),
mkDepspec("baz 2.0.0", "foo >1.0.0"),
},
l: mklock(
"foo 1.0.0 foorev",
),
r: mksolution(
"foo 2.0.0",
"bar 2.0.0",
"baz 2.0.0",
),
maxAttempts: 4,
},
"locked atoms are matched on both local and net name": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo *"),
mkDepspec("foo 1.0.0 foorev"),
mkDepspec("foo 2.0.0 foorev2"),
},
l: mklock(
"foo from baz 1.0.0 foorev",
),
r: mksolution(
"foo 2.0.0 foorev2",
),
},
"pairs bare revs in lock with versions": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo ~1.0.1"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.1 foorev", "bar 1.0.1"),
mkDepspec("foo 1.0.2", "bar 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
},
l: mkrevlock(
"foo 1.0.1 foorev", // mkrevlock drops the 1.0.1
),
r: mksolution(
"foo 1.0.1 foorev",
"bar 1.0.1",
),
},
// This fixture describes a situation that should be impossible with a
// real-world VCS (contents of dep at same rev are different, as indicated
// by different constraints on bar). But, that's not the SUT here, so it's
// OK.
"pairs bare revs in lock with all versions": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo ~1.0.1"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.1 foorev", "bar 1.0.1"),
mkDepspec("foo 1.0.2 foorev", "bar 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
},
l: mkrevlock(
"foo 1.0.1 foorev", // mkrevlock drops the 1.0.1
),
r: mksolution(
"foo 1.0.2 foorev",
"bar 1.0.2",
),
},
"does not pair bare revs in manifest with unpaired lock version": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo ~1.0.1"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.1 foorev", "bar 1.0.1"),
mkDepspec("foo 1.0.2", "bar 1.0.2"),
mkDepspec("bar 1.0.0"),
mkDepspec("bar 1.0.1"),
mkDepspec("bar 1.0.2"),
},
l: mkrevlock(
"foo 1.0.1 foorev", // mkrevlock drops the 1.0.1
),
r: mksolution(
"foo 1.0.1 foorev",
"bar 1.0.1",
),
},
"lock to branch on old rev keeps old rev": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo bmaster"),
mkDepspec("foo bmaster newrev"),
},
l: mklock(
"foo bmaster oldrev",
),
r: mksolution(
"foo bmaster oldrev",
),
},
// Whereas this is a normal situation for a branch, when it occurs for a
// tag, it means someone's been naughty upstream. Still, though, the outcome
// is the same.
//
// TODO(sdboyer) this needs to generate a warning, once we start doing that
"lock to now-moved tag on old rev keeps old rev": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo ptaggerino"),
mkDepspec("foo ptaggerino newrev"),
},
l: mklock(
"foo ptaggerino oldrev",
),
r: mksolution(
"foo ptaggerino oldrev",
),
},
"includes root package's dev dependencies": {
ds: []depspec{
mkDepspec("root 1.0.0", "(dev) foo 1.0.0", "(dev) bar 1.0.0"),
mkDepspec("foo 1.0.0"),
mkDepspec("bar 1.0.0"),
},
r: mksolution(
"foo 1.0.0",
"bar 1.0.0",
),
},
"includes dev dependency's transitive dependencies": {
ds: []depspec{
mkDepspec("root 1.0.0", "(dev) foo 1.0.0"),
mkDepspec("foo 1.0.0", "bar 1.0.0"),
mkDepspec("bar 1.0.0"),
},
r: mksolution(
"foo 1.0.0",
"bar 1.0.0",
),
},
"ignores transitive dependency's dev dependencies": {
ds: []depspec{
mkDepspec("root 1.0.0", "(dev) foo 1.0.0"),
mkDepspec("foo 1.0.0", "(dev) bar 1.0.0"),
mkDepspec("bar 1.0.0"),
},
r: mksolution(
"foo 1.0.0",
),
},
"no version that matches requirement": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo ^1.0.0"),
mkDepspec("foo 2.0.0"),
mkDepspec("foo 2.1.3"),
},
fail: &noVersionError{
pn: mkPI("foo"),
fails: []failedVersion{
{
v: NewVersion("2.1.3"),
f: &versionNotAllowedFailure{
goal: mkAtom("foo 2.1.3"),
failparent: []dependency{mkDep("root", "foo ^1.0.0", "foo")},
c: mkSVC("^1.0.0"),
},
},
{
v: NewVersion("2.0.0"),
f: &versionNotAllowedFailure{
goal: mkAtom("foo 2.0.0"),
failparent: []dependency{mkDep("root", "foo ^1.0.0", "foo")},
c: mkSVC("^1.0.0"),
},
},
},
},
},
"no version that matches combined constraint": {
ds: []depspec{
mkDepspec("root 0.0.0", "foo 1.0.0", "bar 1.0.0"),
mkDepspec("foo 1.0.0", "shared >=2.0.0, <3.0.0"),
mkDepspec("bar 1.0.0", "shared >=2.9.0, <4.0.0"),
mkDepspec("shared 2.5.0"),
mkDepspec("shared 3.5.0"),
},
fail: &noVersionError{
pn: mkPI("shared"),
fails: []failedVersion{
{
v: NewVersion("3.5.0"),
f: &versionNotAllowedFailure{
goal: mkAtom("shared 3.5.0"),
failparent: []dependency{mkDep("foo 1.0.0", "shared >=2.0.0, <3.0.0", "shared")},
c: mkSVC(">=2.9.0, <3.0.0"),
},
},
{
v: NewVersion("2.5.0"),
f: &versionNotAllowedFailure{
goal: mkAtom("shared 2.5.0"),
failparent: []dependency{mkDep("bar 1.0.0", "shared >=2.9.0, <4.0.0", "shared")},
c: mkSVC(">=2.9.0, <3.0.0"),