Skip to content

Commit 7550d27

Browse files
author
Randy Becker
authored
Add a test for WorkspaceState serialization stability (#3788)
1 parent 522d8c7 commit 7550d27

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import TSCBasic
12+
@testable import Workspace
13+
import XCTest
14+
15+
final class WorkspaceStateTests: XCTestCase {
16+
func testSavedDependenciesAreSorted() throws {
17+
let fs = InMemoryFileSystem()
18+
19+
let buildDir = AbsolutePath("/.build")
20+
let statePath = buildDir.appending(component: "workspace-state.json")
21+
22+
try fs.writeFileContents(statePath) {
23+
$0 <<<
24+
"""
25+
{
26+
"object": {
27+
"artifacts": [],
28+
"dependencies": [
29+
{
30+
"basedOn": null,
31+
"packageRef": {
32+
"identity": "yams",
33+
"kind": "remoteSourceControl",
34+
"location": "https://github.com/jpsim/Yams.git",
35+
"name": "Yams"
36+
},
37+
"state": {
38+
"checkoutState": {
39+
"revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa",
40+
"version": "4.0.6"
41+
},
42+
"name": "checkout"
43+
},
44+
"subpath": "Yams"
45+
},
46+
{
47+
"basedOn": null,
48+
"packageRef": {
49+
"identity": "swift-argument-parser",
50+
"kind": "remoteSourceControl",
51+
"location": "https://github.com/apple/swift-argument-parser.git",
52+
"name": "swift-argument-parser"
53+
},
54+
"state": {
55+
"checkoutState": {
56+
"revision": "83b23d940471b313427da226196661856f6ba3e0",
57+
"version": "0.4.4"
58+
},
59+
"name": "checkout"
60+
},
61+
"subpath": "swift-argument-parser"
62+
}
63+
]
64+
},
65+
"version": 4
66+
}
67+
"""
68+
}
69+
70+
let state = WorkspaceState(dataPath: buildDir, fileSystem: fs)
71+
try state.save()
72+
73+
let serialized = try fs.readFileContents(statePath).description
74+
75+
let argpRange = try XCTUnwrap(serialized.range(of: "swift-argument-parser"))
76+
let yamsRange = try XCTUnwrap(serialized.range(of: "yams"))
77+
78+
XCTAssertTrue(argpRange.lowerBound < yamsRange.lowerBound)
79+
}
80+
}

0 commit comments

Comments
 (0)