@@ -3237,7 +3237,10 @@ final class WorkspaceTests: XCTestCase {
3237
3237
}
3238
3238
}
3239
3239
3240
- func testDependencySwitchWithSameIdentity( ) throws {
3240
+
3241
+ // Test that switching between two same local packages placed at
3242
+ // different locations works correctly.
3243
+ func testDependencySwitchLocalWithSameIdentity( ) throws {
3241
3244
let sandbox = AbsolutePath ( " /tmp/ws/ " )
3242
3245
let fs = InMemoryFileSystem ( )
3243
3246
@@ -3279,9 +3282,6 @@ final class WorkspaceTests: XCTestCase {
3279
3282
]
3280
3283
)
3281
3284
3282
- // Test that switching between two same local packages placed at
3283
- // different locations works correctly.
3284
-
3285
3285
var deps : [ MockDependency ] = [
3286
3286
. fileSystem( path: " ./Foo " , products: . specific( [ " Foo " ] ) ) ,
3287
3287
]
@@ -3315,6 +3315,84 @@ final class WorkspaceTests: XCTestCase {
3315
3315
}
3316
3316
}
3317
3317
3318
+ // Test that switching between two remote packages at
3319
+ // different locations works correctly.
3320
+ func testDependencySwitchRemoteWithSameIdentity( ) throws {
3321
+ let sandbox = AbsolutePath ( " /tmp/ws/ " )
3322
+ let fs = InMemoryFileSystem ( )
3323
+
3324
+ let workspace = try MockWorkspace (
3325
+ sandbox: sandbox,
3326
+ fs: fs,
3327
+ roots: [
3328
+ MockPackage (
3329
+ name: " Root " ,
3330
+ targets: [
3331
+ MockTarget ( name: " Root " , dependencies: [ ] ) ,
3332
+ ] ,
3333
+ products: [ ] ,
3334
+ dependencies: [ ]
3335
+ ) ,
3336
+ ] ,
3337
+ packages: [
3338
+ MockPackage (
3339
+ name: " Foo " ,
3340
+ url: " https://scm.com/org/foo " ,
3341
+ targets: [
3342
+ MockTarget ( name: " Foo " ) ,
3343
+ ] ,
3344
+ products: [
3345
+ MockProduct ( name: " Foo " , targets: [ " Foo " ] ) ,
3346
+ ] ,
3347
+ versions: [ " 1.0.0 " ]
3348
+ ) ,
3349
+ MockPackage (
3350
+ name: " Foo " ,
3351
+ url: " https://scm.com/other/foo " ,
3352
+ targets: [
3353
+ MockTarget ( name: " OtherFoo " ) ,
3354
+ ] ,
3355
+ products: [
3356
+ MockProduct ( name: " OtherFoo " , targets: [ " OtherFoo " ] ) ,
3357
+ ] ,
3358
+ versions: [ " 1.1.0 " ]
3359
+ ) ,
3360
+ ]
3361
+ )
3362
+
3363
+ var deps : [ MockDependency ] = [
3364
+ . sourceControl( url: " https://scm.com/org/foo " , requirement: . exact( " 1.0.0 " ) ) ,
3365
+ ]
3366
+ try workspace. checkPackageGraph ( roots: [ " Root " ] , deps: deps) { graph, diagnostics in
3367
+ XCTAssertNoDiagnostics ( diagnostics)
3368
+ PackageGraphTester ( graph) { result in
3369
+ result. check ( roots: " Root " )
3370
+ result. check ( packages: " Foo " , " Root " )
3371
+ }
3372
+ }
3373
+ workspace. checkManagedDependencies { result in
3374
+ result. check ( dependency: " foo " , at: . checkout( . version( " 1.0.0 " ) ) )
3375
+ }
3376
+ do {
3377
+ let ws = try workspace. getOrCreateWorkspace ( )
3378
+ XCTAssertEqual ( ws. state. dependencies [ . plain( " foo " ) ] ? . packageRef. locationString, " https://scm.com/org/foo " )
3379
+ }
3380
+
3381
+ deps = [
3382
+ . sourceControl( url: " https://scm.com/other/foo " , requirement: . exact( " 1.1.0 " ) )
3383
+ ]
3384
+ try workspace. checkPackageGraph ( roots: [ " Root " ] , deps: deps) { _, diagnostics in
3385
+ XCTAssertNoDiagnostics ( diagnostics)
3386
+ }
3387
+ workspace. checkManagedDependencies { result in
3388
+ result. check ( dependency: " foo " , at: . checkout( . version( " 1.1.0 " ) ) )
3389
+ }
3390
+ do {
3391
+ let ws = try workspace. getOrCreateWorkspace ( )
3392
+ XCTAssertEqual ( ws. state. dependencies [ . plain( " foo " ) ] ? . packageRef. locationString, " https://scm.com/other/foo " )
3393
+ }
3394
+ }
3395
+
3318
3396
func testResolvedFileUpdate( ) throws {
3319
3397
let sandbox = AbsolutePath ( " /tmp/ws/ " )
3320
3398
let fs = InMemoryFileSystem ( )
@@ -3525,6 +3603,9 @@ final class WorkspaceTests: XCTestCase {
3525
3603
}
3526
3604
}
3527
3605
3606
+ // In this test, we get into a state where an entry in the resolved
3607
+ // file for a transitive dependency whose URL is later changed to
3608
+ // something else, while keeping the same package identity.
3528
3609
func testTransitiveDependencySwitchWithSameIdentity( ) throws {
3529
3610
let sandbox = AbsolutePath ( " /tmp/ws/ " )
3530
3611
let fs = InMemoryFileSystem ( )
@@ -3536,44 +3617,59 @@ final class WorkspaceTests: XCTestCase {
3536
3617
MockPackage (
3537
3618
name: " Root " ,
3538
3619
targets: [
3539
- MockTarget ( name: " Root " , dependencies: [ " Bar " ] ) ,
3620
+ MockTarget (
3621
+ name: " Root " ,
3622
+ dependencies: [
3623
+ . product( name: " Bar " , package : " bar " )
3624
+ ] ) ,
3540
3625
] ,
3541
3626
products: [ ] ,
3542
3627
dependencies: [
3543
- . sourceControl( path : " ./Bar " , requirement: . upToNextMajor( from: " 1.0.0 " ) ) ,
3628
+ . sourceControl( url : " https://scm.com/org/bar " , requirement: . upToNextMajor( from: " 1.0.0 " ) ) ,
3544
3629
]
3545
3630
) ,
3546
3631
] ,
3547
3632
packages: [
3548
3633
MockPackage (
3549
3634
name: " Bar " ,
3635
+ url: " https://scm.com/org/bar " ,
3550
3636
targets: [
3551
- MockTarget ( name: " Bar " , dependencies: [ " Foo " ] ) ,
3637
+ MockTarget (
3638
+ name: " Bar " ,
3639
+ dependencies: [
3640
+ . product( name: " Foo " , package : " foo " )
3641
+ ] ) ,
3552
3642
] ,
3553
3643
products: [
3554
3644
MockProduct ( name: " Bar " , targets: [ " Bar " ] ) ,
3555
3645
] ,
3556
3646
dependencies: [
3557
- . sourceControl( path : " ./Foo " , requirement: . upToNextMajor( from: " 1.0.0 " ) ) ,
3647
+ . sourceControl( url : " https://scm.com/org/foo " , requirement: . upToNextMajor( from: " 1.0.0 " ) ) ,
3558
3648
] ,
3559
3649
versions: [ " 1.0.0 " ]
3560
3650
) ,
3561
3651
MockPackage (
3562
3652
name: " Bar " ,
3653
+ url: " https://scm.com/org/bar " ,
3563
3654
targets: [
3564
- MockTarget ( name: " Bar " , dependencies: [ " Nested/Foo " ] ) ,
3655
+ MockTarget (
3656
+ name: " Bar " ,
3657
+ dependencies: [
3658
+ . product( name: " OtherFoo " , package : " foo " )
3659
+ ] ) ,
3565
3660
] ,
3566
3661
products: [
3567
3662
MockProduct ( name: " Bar " , targets: [ " Bar " ] ) ,
3568
3663
] ,
3569
3664
dependencies: [
3570
- . sourceControl( path : " Nested/Foo " , requirement: . upToNextMajor( from: " 1.0.0 " ) ) ,
3665
+ . sourceControl( url : " https://scm.com/other/foo " , requirement: . upToNextMajor( from: " 1.0.0 " ) ) ,
3571
3666
] ,
3572
3667
versions: [ " 1.1.0 " ] ,
3573
3668
toolsVersion: . v5
3574
3669
) ,
3575
3670
MockPackage (
3576
3671
name: " Foo " ,
3672
+ url: " https://scm.com/org/foo " ,
3577
3673
targets: [
3578
3674
MockTarget ( name: " Foo " ) ,
3579
3675
] ,
@@ -3584,40 +3680,27 @@ final class WorkspaceTests: XCTestCase {
3584
3680
) ,
3585
3681
MockPackage (
3586
3682
name: " Foo " ,
3587
- path : " Nested/Foo " ,
3683
+ url : " https://scm.com/other/foo " ,
3588
3684
targets: [
3589
- MockTarget ( name: " Foo " ) ,
3685
+ MockTarget ( name: " OtherFoo " ) ,
3590
3686
] ,
3591
3687
products: [
3592
- MockProduct ( name: " Nested/Foo " , targets: [ " Foo " ] ) ,
3688
+ MockProduct ( name: " OtherFoo " , targets: [ " OtherFoo " ] ) ,
3593
3689
] ,
3594
3690
versions: [ " 1.0.0 " ]
3595
3691
) ,
3596
3692
]
3597
3693
)
3598
3694
3599
- // In this test, we get into a state where add an entry in the resolved
3600
- // file for a transitive dependency whose URL is later changed to
3601
- // something else, while keeping the same package identity.
3602
- //
3603
- // This is normally detected during pins validation before the
3604
- // dependency resolution process even begins but if we're starting with
3605
- // a clean slate, we don't even know about the correct urls of the
3606
- // transitive dependencies. We will end up fetching the wrong
3607
- // dependency as we prefetch the pins. If we get into this case, it
3608
- // should kick off another dependency resolution operation which will
3609
- // have enough information to remove the invalid pins of transitive
3610
- // dependencies.
3611
-
3612
3695
var deps : [ MockDependency ] = [
3613
- . sourceControl( path : " ./Bar " , requirement: . exact( " 1.0.0 " ) , products : . specific ( [ " Bar " ] ) ) ,
3696
+ . sourceControl( url : " https://scm.com/org/bar " , requirement: . exact( " 1.0.0 " ) ) ,
3614
3697
]
3615
3698
try workspace. checkPackageGraph ( roots: [ " Root " ] , deps: deps) { graph, diagnostics in
3699
+ XCTAssertNoDiagnostics ( diagnostics)
3616
3700
PackageGraphTester ( graph) { result in
3617
3701
result. check ( roots: " Root " )
3618
3702
result. check ( packages: " Bar " , " Foo " , " Root " )
3619
3703
}
3620
- XCTAssertNoDiagnostics ( diagnostics)
3621
3704
}
3622
3705
workspace. checkManagedDependencies { result in
3623
3706
result. check ( dependency: " foo " , at: . checkout( . version( " 1.0.0 " ) ) )
@@ -3626,22 +3709,22 @@ final class WorkspaceTests: XCTestCase {
3626
3709
3627
3710
do {
3628
3711
let ws = try workspace. getOrCreateWorkspace ( )
3629
- XCTAssertEqual ( ws. state. dependencies [ . plain( " foo " ) ] ? . packageRef. locationString, " /tmp/ws/pkgs/Foo " )
3712
+ XCTAssertEqual ( ws. state. dependencies [ . plain( " foo " ) ] ? . packageRef. locationString, " https://scm.com/org/foo " )
3630
3713
}
3631
3714
3632
3715
workspace. checkReset { diagnostics in
3633
3716
XCTAssertNoDiagnostics ( diagnostics)
3634
3717
}
3635
3718
3636
3719
deps = [
3637
- . sourceControl( path : " ./Bar " , requirement: . exact( " 1.1.0 " ) , products : . specific ( [ " Bar " ] ) ) ,
3720
+ . sourceControl( url : " https://scm.com/org/bar " , requirement: . exact( " 1.1.0 " ) ) ,
3638
3721
]
3639
3722
try workspace. checkPackageGraph ( roots: [ " Root " ] , deps: deps) { graph, diagnostics in
3723
+ XCTAssertNoDiagnostics ( diagnostics)
3640
3724
PackageGraphTester ( graph) { result in
3641
3725
result. check ( roots: " Root " )
3642
3726
result. check ( packages: " Bar " , " Foo " , " Root " )
3643
3727
}
3644
- XCTAssertNoDiagnostics ( diagnostics)
3645
3728
}
3646
3729
workspace. checkManagedDependencies { result in
3647
3730
result. check ( dependency: " foo " , at: . checkout( . version( " 1.0.0 " ) ) )
@@ -3650,7 +3733,7 @@ final class WorkspaceTests: XCTestCase {
3650
3733
3651
3734
do {
3652
3735
let ws = try workspace. getOrCreateWorkspace ( )
3653
- XCTAssertEqual ( ws. state. dependencies [ . plain( " foo " ) ] ? . packageRef. locationString, " /tmp/ws/pkgs/Nested/Foo " )
3736
+ XCTAssertEqual ( ws. state. dependencies [ . plain( " foo " ) ] ? . packageRef. locationString, " https://scm.com/other/foo " )
3654
3737
}
3655
3738
}
3656
3739
0 commit comments