@@ -38,6 +38,7 @@ describe('macOS toolchain installation verification', () => {
38
38
const installer = new XcodeToolchainInstaller ( toolchain )
39
39
jest . spyOn ( fs , 'access' ) . mockResolvedValue ( )
40
40
jest . spyOn ( exec , 'exec' ) . mockResolvedValue ( 0 )
41
+ jest . spyOn ( core , 'getBooleanInput' ) . mockReturnValue ( false )
41
42
jest . spyOn ( exec , 'getExecOutput' ) . mockResolvedValue ( {
42
43
exitCode : 0 ,
43
44
stdout : `swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)\nTarget: arm64-apple-macosx13.0` ,
@@ -55,6 +56,48 @@ describe('macOS toolchain installation verification', () => {
55
56
expect ( process . env . DEVELOPER_DIR ) . toBe ( toolchain . xcodePath )
56
57
} )
57
58
59
+ it ( 'tests toolchain preinstalled not preferred' , async ( ) => {
60
+ const installer = new XcodeToolchainInstaller ( toolchain )
61
+ const identifier = 'org.swift.581202305171a'
62
+ jest . spyOn ( fs , 'access' ) . mockResolvedValue ( )
63
+ jest . spyOn ( exec , 'exec' ) . mockResolvedValue ( 0 )
64
+ jest . spyOn ( core , 'getBooleanInput' ) . mockReturnValue ( true )
65
+ jest . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( undefined )
66
+ jest . spyOn ( toolCache , 'find' ) . mockReturnValue ( '' )
67
+ jest . spyOn ( cache , 'saveCache' ) . mockResolvedValue ( 1 )
68
+ jest . spyOn ( fs , 'access' ) . mockResolvedValue ( )
69
+ jest . spyOn ( fs , 'readFile' ) . mockResolvedValue ( '' )
70
+ jest . spyOn ( fs , 'cp' ) . mockResolvedValue ( )
71
+ jest . spyOn ( plist , 'parse' ) . mockReturnValue ( { CFBundleIdentifier : identifier } )
72
+ jest . spyOn ( exec , 'getExecOutput' ) . mockResolvedValue ( {
73
+ exitCode : 0 ,
74
+ stdout : `swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)\nTarget: arm64-apple-macosx13.0` ,
75
+ stderr : ''
76
+ } )
77
+ const download = path . resolve ( 'tool' , 'download' , 'path' )
78
+ const extracted = path . resolve ( 'tool' , 'extracted' , 'path' )
79
+ const deployed = path . resolve ( 'tool' , 'deployed' , 'path' )
80
+ const cached = path . resolve ( 'tool' , 'cached' , 'path' )
81
+ const installationNeededSpy = jest . spyOn ( installer , 'isInstallationNeeded' )
82
+ const downloadSpy = jest
83
+ . spyOn ( toolCache , 'downloadTool' )
84
+ . mockResolvedValue ( download )
85
+ const extractXarSpy = jest
86
+ . spyOn ( toolCache , 'extractXar' )
87
+ . mockResolvedValue ( extracted )
88
+ const extractTarSpy = jest
89
+ . spyOn ( toolCache , 'extractTar' )
90
+ . mockResolvedValue ( deployed )
91
+ const cacheSpy = jest . spyOn ( toolCache , 'cacheDir' ) . mockResolvedValue ( cached )
92
+ await installer . install ( 'x86_64' )
93
+ await installer . install ( 'aarch64' )
94
+ for ( const spy of [ downloadSpy , extractXarSpy , extractTarSpy , cacheSpy ] ) {
95
+ expect ( spy ) . toHaveBeenCalled ( )
96
+ }
97
+ expect ( installationNeededSpy ) . toHaveBeenCalled ( )
98
+ expect ( process . env . DEVELOPER_DIR ) . toBe ( toolchain . xcodePath )
99
+ } )
100
+
58
101
it ( 'tests download' , async ( ) => {
59
102
const installer = new XcodeToolchainInstaller ( toolchain )
60
103
expect ( installer [ 'version' ] ) . toStrictEqual ( parseSemVer ( '5.8.1' ) )
@@ -185,6 +228,7 @@ describe('macOS toolchain installation verification', () => {
185
228
jest . spyOn ( toolCache , 'find' ) . mockReturnValue ( '' )
186
229
jest . spyOn ( fs , 'access' ) . mockResolvedValue ( )
187
230
jest . spyOn ( exec , 'exec' ) . mockResolvedValue ( 0 )
231
+ jest . spyOn ( core , 'getBooleanInput' ) . mockReturnValue ( false )
188
232
jest . spyOn ( exec , 'getExecOutput' ) . mockResolvedValue ( {
189
233
exitCode : 0 ,
190
234
stdout : `swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)\nTarget: arm64-apple-macosx13.0` ,
0 commit comments