@@ -46,7 +46,8 @@ describe('macOS toolchain installation verification', () => {
4646 const installationNeededSpy = jest . spyOn ( installer , 'isInstallationNeeded' )
4747 const downloadSpy = jest . spyOn ( toolCache , 'downloadTool' )
4848 const extractSpy = jest . spyOn ( toolCache , 'extractXar' )
49- await installer . install ( )
49+ await installer . install ( 'x86_64' )
50+ await installer . install ( 'aarch64' )
5051 for ( const spy of [ downloadSpy , extractSpy ] ) {
5152 expect ( spy ) . not . toHaveBeenCalled ( )
5253 }
@@ -96,39 +97,58 @@ describe('macOS toolchain installation verification', () => {
9697 expect ( process . env . TOOLCHAINS ) . toBe ( identifier )
9798 } )
9899
99- it ( 'tests installation with download' , async ( ) => {
100- const installer = new XcodeToolchainInstaller ( toolchain )
101- const download = path . resolve ( 'tool' , 'download' , 'path' )
102- const extracted = path . resolve ( 'tool' , 'extracted' , 'path' )
103- const deployed = path . resolve ( 'tool' , 'deployed' , 'path' )
104- const cached = path . resolve ( 'tool' , 'cached' , 'path' )
105- const swiftPath = path . join ( cached , 'usr' , 'bin' )
106- const identifier = 'org.swift.581202305171a'
107- jest . spyOn ( installer , 'isInstallationNeeded' ) . mockResolvedValue ( true )
108- jest . spyOn ( core , 'getBooleanInput' ) . mockReturnValue ( true )
109- jest . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( undefined )
110- jest . spyOn ( cache , 'saveCache' ) . mockResolvedValue ( 1 )
111- jest . spyOn ( toolCache , 'find' ) . mockReturnValue ( '' )
112- jest . spyOn ( exec , 'exec' ) . mockResolvedValue ( 0 )
113- jest . spyOn ( fs , 'cp' ) . mockResolvedValue ( )
114- const downloadSpy = jest . spyOn ( toolCache , 'downloadTool' )
115- downloadSpy . mockResolvedValue ( download )
116- const extractSpy = jest . spyOn ( toolCache , 'extractXar' )
117- extractSpy . mockResolvedValue ( extracted )
118- const deploySpy = jest . spyOn ( toolCache , 'extractTar' )
119- deploySpy . mockResolvedValue ( deployed )
120- const cacheSpy = jest . spyOn ( toolCache , 'cacheDir' )
121- cacheSpy . mockResolvedValue ( cached )
122- jest . spyOn ( fs , 'access' ) . mockResolvedValue ( )
123- jest . spyOn ( fs , 'readFile' ) . mockResolvedValue ( '' )
124- jest . spyOn ( plist , 'parse' ) . mockReturnValue ( { CFBundleIdentifier : identifier } )
125- await installer . install ( )
126- expect ( process . env . PATH ?. includes ( swiftPath ) ) . toBeTruthy ( )
127- expect ( process . env . TOOLCHAINS ) . toBe ( identifier )
128- for ( const spy of [ downloadSpy , extractSpy , deploySpy , cacheSpy ] ) {
129- expect ( spy ) . toHaveBeenCalled ( )
100+ it . each ( [ 'aarch64' , 'x86_64' ] ) (
101+ 'tests installation with download for %s' ,
102+ async arch => {
103+ const installer = new XcodeToolchainInstaller ( toolchain )
104+ const download = path . resolve ( 'tool' , 'download' , 'path' )
105+ const extracted = path . resolve ( 'tool' , 'extracted' , 'path' )
106+ const deployed = path . resolve ( 'tool' , 'deployed' , 'path' )
107+ const cached = path . resolve ( 'tool' , 'cached' , 'path' )
108+ const swiftPath = path . join ( cached , 'usr' , 'bin' )
109+ const identifier = 'org.swift.581202305171a'
110+ jest . spyOn ( installer , 'isInstallationNeeded' ) . mockResolvedValue ( true )
111+ jest . spyOn ( core , 'getBooleanInput' ) . mockReturnValue ( true )
112+ jest . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( undefined )
113+ jest . spyOn ( toolCache , 'find' ) . mockReturnValue ( '' )
114+ jest . spyOn ( exec , 'exec' ) . mockResolvedValue ( 0 )
115+ jest . spyOn ( fs , 'cp' ) . mockResolvedValue ( )
116+ const downloadSpy = jest . spyOn ( toolCache , 'downloadTool' )
117+ downloadSpy . mockResolvedValue ( download )
118+ const extractSpy = jest . spyOn ( toolCache , 'extractXar' )
119+ extractSpy . mockResolvedValue ( extracted )
120+ const deploySpy = jest . spyOn ( toolCache , 'extractTar' )
121+ deploySpy . mockResolvedValue ( deployed )
122+ const toolCacheSpy = jest . spyOn ( toolCache , 'cacheDir' )
123+ toolCacheSpy . mockResolvedValue ( cached )
124+ const actionCacheSpy = jest . spyOn ( cache , 'saveCache' )
125+ actionCacheSpy . mockResolvedValue ( 1 )
126+ jest . spyOn ( fs , 'access' ) . mockResolvedValue ( )
127+ jest . spyOn ( fs , 'readFile' ) . mockResolvedValue ( '' )
128+ jest
129+ . spyOn ( plist , 'parse' )
130+ . mockReturnValue ( { CFBundleIdentifier : identifier } )
131+ await installer . install ( arch )
132+ expect ( process . env . PATH ?. includes ( swiftPath ) ) . toBeTruthy ( )
133+ expect ( process . env . TOOLCHAINS ) . toBe ( identifier )
134+ for ( const spy of [
135+ downloadSpy ,
136+ extractSpy ,
137+ deploySpy ,
138+ toolCacheSpy ,
139+ actionCacheSpy
140+ ] ) {
141+ expect ( spy ) . toHaveBeenCalled ( )
142+ }
143+ const toolCacheKey = `${ toolchain . dir } -${ toolchain . platform } `
144+ const actionCacheKey = `${ toolCacheKey } -${ arch } `
145+ expect ( toolCacheSpy . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( deployed )
146+ expect ( toolCacheSpy . mock . calls [ 0 ] ?. [ 1 ] ) . toBe ( toolCacheKey )
147+ expect ( toolCacheSpy . mock . calls [ 0 ] ?. [ 2 ] ) . toBe ( '5.8.1' )
148+ expect ( toolCacheSpy . mock . calls [ 0 ] ?. [ 3 ] ) . toBe ( arch )
149+ expect ( actionCacheSpy . mock . calls [ 0 ] ?. [ 1 ] ) . toBe ( actionCacheKey )
130150 }
131- } )
151+ )
132152
133153 it ( 'tests installation with cache' , async ( ) => {
134154 const installer = new XcodeToolchainInstaller ( toolchain )
@@ -152,7 +172,7 @@ describe('macOS toolchain installation verification', () => {
152172 jest . spyOn ( fs , 'access' ) . mockResolvedValue ( )
153173 jest . spyOn ( fs , 'readFile' ) . mockResolvedValue ( '' )
154174 jest . spyOn ( plist , 'parse' ) . mockReturnValue ( { CFBundleIdentifier : identifier } )
155- await installer . install ( )
175+ await installer . install ( 'aarch64' )
156176 expect ( process . env . PATH ?. includes ( swiftPath ) ) . toBeTruthy ( )
157177 expect ( process . env . TOOLCHAINS ) . toBe ( identifier )
158178 for ( const spy of [ downloadSpy , extractSpy , deploySpy ] ) {
@@ -170,7 +190,7 @@ describe('macOS toolchain installation verification', () => {
170190 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` ,
171191 stderr : ''
172192 } )
173- await expect ( installer . install ( ) ) . resolves
193+ await expect ( installer . install ( 'aarch64' ) ) . resolves
174194 expect ( process . env . DEVELOPER_DIR ) . toBe ( toolchain . xcodePath )
175195 } )
176196
0 commit comments