@@ -73,6 +73,14 @@ suite("Swiftly Unit Tests", () => {
73
73
// Mock list-available command with JSON output
74
74
const jsonOutput = {
75
75
toolchains : [
76
+ {
77
+ inUse : false ,
78
+ isDefault : false ,
79
+ version : {
80
+ name : "xcode" ,
81
+ type : "system" ,
82
+ } ,
83
+ } ,
76
84
{
77
85
inUse : true ,
78
86
isDefault : true ,
@@ -118,6 +126,100 @@ suite("Swiftly Unit Tests", () => {
118
126
const result = await Swiftly . listAvailableToolchains ( ) ;
119
127
120
128
expect ( result ) . to . deep . equal ( [
129
+ "xcode" ,
130
+ "swift-5.9.0-RELEASE" ,
131
+ "swift-5.8.0-RELEASE" ,
132
+ "swift-DEVELOPMENT-SNAPSHOT-2023-10-15-a" ,
133
+ ] ) ;
134
+
135
+ expect ( mockUtilities . execFile ) . to . have . been . calledWith ( "swiftly" , [ "--version" ] ) ;
136
+ expect ( mockUtilities . execFile ) . to . have . been . calledWith ( "swiftly" , [
137
+ "list" ,
138
+ "--format=json" ,
139
+ ] ) ;
140
+ } ) ;
141
+
142
+ test ( "should be able to parse future additions to the output and ignore unexpected types" , async ( ) => {
143
+ // Mock version check to return 1.1.0
144
+ mockUtilities . execFile . withArgs ( "swiftly" , [ "--version" ] ) . resolves ( {
145
+ stdout : "1.1.0\n" ,
146
+ stderr : "" ,
147
+ } ) ;
148
+
149
+ // Mock list-available command with JSON output
150
+ const jsonOutput = {
151
+ toolchains : [
152
+ {
153
+ inUse : false ,
154
+ isDefault : false ,
155
+ version : {
156
+ name : "xcode" ,
157
+ type : "system" ,
158
+ newProp : 1 , // Try adding a new property.
159
+ } ,
160
+ newProp : 1 , // Try adding a new property.
161
+ } ,
162
+ {
163
+ inUse : false ,
164
+ isDefault : false ,
165
+ version : {
166
+ // Try adding an unexpected version type.
167
+ type : "something_else" ,
168
+ } ,
169
+ newProp : 1 , // Try adding a new property.
170
+ } ,
171
+ {
172
+ inUse : true ,
173
+ isDefault : true ,
174
+ version : {
175
+ major : 5 ,
176
+ minor : 9 ,
177
+ patch : 0 ,
178
+ name : "swift-5.9.0-RELEASE" ,
179
+ type : "stable" ,
180
+ newProp : 1 , // Try adding a new property.
181
+ } ,
182
+ newProp : 1 , // Try adding a new property.
183
+ } ,
184
+ {
185
+ inUse : false ,
186
+ isDefault : false ,
187
+ version : {
188
+ major : 5 ,
189
+ minor : 8 ,
190
+ patch : 0 ,
191
+ name : "swift-5.8.0-RELEASE" ,
192
+ type : "stable" ,
193
+ newProp : 1 , // Try adding a new property.
194
+ } ,
195
+ newProp : "" , // Try adding a new property.
196
+ } ,
197
+ {
198
+ inUse : false ,
199
+ isDefault : false ,
200
+ version : {
201
+ major : 5 ,
202
+ minor : 10 ,
203
+ branch : "development" ,
204
+ date : "2023-10-15" ,
205
+ name : "swift-DEVELOPMENT-SNAPSHOT-2023-10-15-a" ,
206
+ type : "snapshot" ,
207
+ newProp : 1 , // Try adding a new property.
208
+ } ,
209
+ newProp : 1 , // Try adding a new property.
210
+ } ,
211
+ ] ,
212
+ } ;
213
+
214
+ mockUtilities . execFile . withArgs ( "swiftly" , [ "list" , "--format=json" ] ) . resolves ( {
215
+ stdout : JSON . stringify ( jsonOutput ) ,
216
+ stderr : "" ,
217
+ } ) ;
218
+
219
+ const result = await Swiftly . listAvailableToolchains ( ) ;
220
+
221
+ expect ( result ) . to . deep . equal ( [
222
+ "xcode" ,
121
223
"swift-5.9.0-RELEASE" ,
122
224
"swift-5.8.0-RELEASE" ,
123
225
"swift-DEVELOPMENT-SNAPSHOT-2023-10-15-a" ,
@@ -342,6 +444,95 @@ suite("Swiftly Unit Tests", () => {
342
444
] ) ;
343
445
} ) ;
344
446
447
+ test ( "should be able to parse future additions to the output and ignore unexpected types" , async ( ) => {
448
+ mockedPlatform . setValue ( "darwin" ) ;
449
+
450
+ mockUtilities . execFile . withArgs ( "swiftly" , [ "--version" ] ) . resolves ( {
451
+ stdout : "1.1.0\n" ,
452
+ stderr : "" ,
453
+ } ) ;
454
+
455
+ const availableResponse = {
456
+ toolchains : [
457
+ {
458
+ inUse : false ,
459
+ installed : false ,
460
+ isDefault : false ,
461
+ version : {
462
+ // Try adding an unexpected version type.
463
+ type : "something_else" ,
464
+ } ,
465
+ newProp : 1 , // Try adding a new property.
466
+ } ,
467
+ {
468
+ inUse : false ,
469
+ installed : false ,
470
+ isDefault : false ,
471
+ version : {
472
+ type : "stable" ,
473
+ major : 6 ,
474
+ minor : 0 ,
475
+ patch : 0 ,
476
+ name : "6.0.0" ,
477
+ newProp : 1 , // Try adding a new property.
478
+ } ,
479
+ newProp : 1 , // Try adding a new property.
480
+ } ,
481
+ {
482
+ inUse : false ,
483
+ installed : false ,
484
+ isDefault : false ,
485
+ version : {
486
+ type : "snapshot" ,
487
+ major : 6 ,
488
+ minor : 1 ,
489
+ branch : "main" ,
490
+ date : "2025-01-15" ,
491
+ name : "main-snapshot-2025-01-15" ,
492
+ newProp : 1 , // Try adding a new property.
493
+ } ,
494
+ newProp : 1 , // Try adding a new property.
495
+ } ,
496
+ ] ,
497
+ } ;
498
+
499
+ mockUtilities . execFile
500
+ . withArgs ( "swiftly" , [ "list-available" , "--format=json" ] )
501
+ . resolves ( {
502
+ stdout : JSON . stringify ( availableResponse ) ,
503
+ stderr : "" ,
504
+ } ) ;
505
+
506
+ const result = await Swiftly . listAvailable ( ) ;
507
+ expect ( result ) . to . deep . equal ( [
508
+ {
509
+ inUse : false ,
510
+ installed : false ,
511
+ isDefault : false ,
512
+ version : {
513
+ type : "stable" ,
514
+ major : 6 ,
515
+ minor : 0 ,
516
+ patch : 0 ,
517
+ name : "6.0.0" ,
518
+ } ,
519
+ } ,
520
+ {
521
+ inUse : false ,
522
+ installed : false ,
523
+ isDefault : false ,
524
+ version : {
525
+ type : "snapshot" ,
526
+ major : 6 ,
527
+ minor : 1 ,
528
+ branch : "main" ,
529
+ date : "2025-01-15" ,
530
+ name : "main-snapshot-2025-01-15" ,
531
+ } ,
532
+ } ,
533
+ ] ) ;
534
+ } ) ;
535
+
345
536
test ( "should handle errors when fetching available toolchains" , async ( ) => {
346
537
mockedPlatform . setValue ( "darwin" ) ;
347
538
mockUtilities . execFile . withArgs ( "swiftly" , [ "--version" ] ) . resolves ( {
0 commit comments