@@ -986,6 +986,97 @@ final class PackageToolTests: CommandsTestCase {
986
986
}
987
987
}
988
988
989
+ func testOnlyUseVersionsFromResolvedFileFetchesWithExistingState( ) throws {
990
+ func writeResolvedFile( packageDir: AbsolutePath , repositoryURL: String , revision: String , version: String ) throws {
991
+ try localFileSystem. writeFileContents ( packageDir. appending ( component: " Package.resolved " ) ) {
992
+ $0 <<< """
993
+ {
994
+ " object " : {
995
+ " pins " : [
996
+ {
997
+ " package " : " library " ,
998
+ " repositoryURL " : " \( repositoryURL) " ,
999
+ " state " : {
1000
+ " branch " : null,
1001
+ " revision " : " \( revision) " ,
1002
+ " version " : " \( version) "
1003
+ }
1004
+ }
1005
+ ]
1006
+ },
1007
+ " version " : 1
1008
+ }
1009
+ """
1010
+ }
1011
+ }
1012
+
1013
+ try testWithTemporaryDirectory { tmpPath in
1014
+ let packageDir = tmpPath. appending ( components: " library " )
1015
+ try localFileSystem. writeFileContents ( packageDir. appending ( component: " Package.swift " ) ) {
1016
+ $0 <<< """
1017
+ // swift-tools-version:5.0
1018
+ import PackageDescription
1019
+ let package = Package(
1020
+ name: " library " ,
1021
+ products: [ .library(name: " library " , targets: [ " library " ]) ],
1022
+ targets: [ .target(name: " library " ) ]
1023
+ )
1024
+ """
1025
+ }
1026
+ try localFileSystem. writeFileContents ( packageDir. appending ( components: " Sources " , " library " , " library.swift " ) ) {
1027
+ $0 <<< """
1028
+ public func Foo() { }
1029
+ """
1030
+ }
1031
+
1032
+ let depGit = GitRepository ( path: packageDir)
1033
+ try depGit. create ( )
1034
+ try depGit. stageEverything ( )
1035
+ try depGit. commit ( )
1036
+ try depGit. tag ( name: " 1.0.0 " )
1037
+
1038
+ let initialRevision = try depGit. revision ( forTag: " 1.0.0 " )
1039
+ let repositoryURL = " file:// \( packageDir. pathString) "
1040
+
1041
+ let clientDir = tmpPath. appending ( components: " client " )
1042
+ try localFileSystem. writeFileContents ( clientDir. appending ( component: " Package.swift " ) ) {
1043
+ $0 <<< """
1044
+ // swift-tools-version:5.0
1045
+ import PackageDescription
1046
+ let package = Package(
1047
+ name: " client " ,
1048
+ dependencies: [ .package(url: " \( repositoryURL) " , from: " 1.0.0 " ) ],
1049
+ targets: [ .target(name: " client " , dependencies: [ " library " ]) ]
1050
+ )
1051
+ """
1052
+ }
1053
+ try localFileSystem. writeFileContents ( clientDir. appending ( components: " Sources " , " client " , " main.swift " ) ) {
1054
+ $0 <<< """
1055
+ print( " hello " )
1056
+ """
1057
+ }
1058
+
1059
+ // Initial resolution with clean state.
1060
+ try writeResolvedFile ( packageDir: clientDir, repositoryURL: repositoryURL, revision: initialRevision, version: " 1.0.0 " )
1061
+ _ = try execute ( [ " resolve " , " --only-use-versions-from-resolved-file " ] , packagePath: clientDir)
1062
+
1063
+ // Make a change to the dependency and tag a new version.
1064
+ try localFileSystem. writeFileContents ( packageDir. appending ( components: " Sources " , " library " , " library.swift " ) ) {
1065
+ $0 <<< """
1066
+ public func Best() { }
1067
+ """
1068
+ }
1069
+ try depGit. stageEverything ( )
1070
+ try depGit. commit ( )
1071
+ try depGit. tag ( name: " 1.0.1 " )
1072
+ let updatedRevision = try depGit. revision ( forTag: " 1.0.1 " )
1073
+
1074
+ // Require new version but re-use existing state that hasn't fetched the latest revision, yet.
1075
+ try writeResolvedFile ( packageDir: clientDir, repositoryURL: repositoryURL, revision: updatedRevision, version: " 1.0.1 " )
1076
+ _ = try execute ( [ " resolve " , " --only-use-versions-from-resolved-file " ] , packagePath: clientDir)
1077
+ }
1078
+ }
1079
+
989
1080
func testSymlinkedDependency( ) throws {
990
1081
try testWithTemporaryDirectory { path in
991
1082
let fs = localFileSystem
0 commit comments