@@ -15,6 +15,7 @@ process.env['RUNNER_TOOL_CACHE'] = cachePath
15
15
import * as tc from '../src/tool-cache'
16
16
17
17
const IS_WINDOWS = process . platform === 'win32'
18
+ const IS_MAC = process . platform === 'darwin'
18
19
19
20
describe ( '@actions/tool-cache' , function ( ) {
20
21
beforeAll ( function ( ) {
@@ -346,6 +347,110 @@ describe('@actions/tool-cache', function() {
346
347
await io . rmRF ( tempDir )
347
348
}
348
349
} )
350
+ } else if ( IS_MAC ) {
351
+ it ( 'extract .xar' , async ( ) => {
352
+ const tempDir = path . join ( tempPath , 'test-install.xar' )
353
+ const sourcePath = path . join ( __dirname , 'data' , 'archive-content' )
354
+ const targetPath = path . join ( tempDir , 'test.xar' )
355
+ await io . mkdirP ( tempDir )
356
+
357
+ // Create test archive
358
+ const xarPath = await io . which ( 'xar' , true )
359
+ await exec . exec ( `${ xarPath } ` , [ '-cf' , targetPath , '.' ] , {
360
+ cwd : sourcePath
361
+ } )
362
+
363
+ // extract/cache
364
+ const extPath : string = await tc . extractXar ( targetPath , undefined , '-x' )
365
+ await tc . cacheDir ( extPath , 'my-xar-contents' , '1.1.0' )
366
+ const toolPath : string = tc . find ( 'my-xar-contents' , '1.1.0' )
367
+
368
+ expect ( fs . existsSync ( toolPath ) ) . toBeTruthy ( )
369
+ expect ( fs . existsSync ( `${ toolPath } .complete` ) ) . toBeTruthy ( )
370
+ expect ( fs . existsSync ( path . join ( toolPath , 'file.txt' ) ) ) . toBeTruthy ( )
371
+ expect (
372
+ fs . existsSync ( path . join ( toolPath , 'file-with-ç-character.txt' ) )
373
+ ) . toBeTruthy ( )
374
+ expect (
375
+ fs . existsSync ( path . join ( toolPath , 'folder' , 'nested-file.txt' ) )
376
+ ) . toBeTruthy ( )
377
+ expect (
378
+ fs . readFileSync (
379
+ path . join ( toolPath , 'folder' , 'nested-file.txt' ) ,
380
+ 'utf8'
381
+ )
382
+ ) . toBe ( 'folder/nested-file.txt contents' )
383
+ } )
384
+
385
+ it ( 'extract .xar to a directory that does not exist' , async ( ) => {
386
+ const tempDir = path . join ( tempPath , 'test-install.xar' )
387
+ const sourcePath = path . join ( __dirname , 'data' , 'archive-content' )
388
+ const targetPath = path . join ( tempDir , 'test.xar' )
389
+ await io . mkdirP ( tempDir )
390
+
391
+ const destDir = path . join ( tempDir , 'not-exist' )
392
+
393
+ // Create test archive
394
+ const xarPath = await io . which ( 'xar' , true )
395
+ await exec . exec ( `${ xarPath } ` , [ '-cf' , targetPath , '.' ] , {
396
+ cwd : sourcePath
397
+ } )
398
+
399
+ // extract/cache
400
+ const extPath : string = await tc . extractXar ( targetPath , destDir , '-x' )
401
+ await tc . cacheDir ( extPath , 'my-xar-contents' , '1.1.0' )
402
+ const toolPath : string = tc . find ( 'my-xar-contents' , '1.1.0' )
403
+
404
+ expect ( fs . existsSync ( toolPath ) ) . toBeTruthy ( )
405
+ expect ( fs . existsSync ( `${ toolPath } .complete` ) ) . toBeTruthy ( )
406
+ expect ( fs . existsSync ( path . join ( toolPath , 'file.txt' ) ) ) . toBeTruthy ( )
407
+ expect (
408
+ fs . existsSync ( path . join ( toolPath , 'file-with-ç-character.txt' ) )
409
+ ) . toBeTruthy ( )
410
+ expect (
411
+ fs . existsSync ( path . join ( toolPath , 'folder' , 'nested-file.txt' ) )
412
+ ) . toBeTruthy ( )
413
+ expect (
414
+ fs . readFileSync (
415
+ path . join ( toolPath , 'folder' , 'nested-file.txt' ) ,
416
+ 'utf8'
417
+ )
418
+ ) . toBe ( 'folder/nested-file.txt contents' )
419
+ } )
420
+
421
+ it ( 'extract .xar without flags' , async ( ) => {
422
+ const tempDir = path . join ( tempPath , 'test-install.xar' )
423
+ const sourcePath = path . join ( __dirname , 'data' , 'archive-content' )
424
+ const targetPath = path . join ( tempDir , 'test.xar' )
425
+ await io . mkdirP ( tempDir )
426
+
427
+ // Create test archive
428
+ const xarPath = await io . which ( 'xar' , true )
429
+ await exec . exec ( `${ xarPath } ` , [ '-cf' , targetPath , '.' ] , {
430
+ cwd : sourcePath
431
+ } )
432
+
433
+ // extract/cache
434
+ const extPath : string = await tc . extractXar ( targetPath , undefined )
435
+ await tc . cacheDir ( extPath , 'my-xar-contents' , '1.1.0' )
436
+ const toolPath : string = tc . find ( 'my-xar-contents' , '1.1.0' )
437
+
438
+ expect ( fs . existsSync ( toolPath ) ) . toBeTruthy ( )
439
+ expect ( fs . existsSync ( `${ toolPath } .complete` ) ) . toBeTruthy ( )
440
+ expect ( fs . existsSync ( path . join ( toolPath , 'file.txt' ) ) ) . toBeTruthy ( )
441
+ expect (
442
+ fs . existsSync ( path . join ( toolPath , 'file-with-ç-character.txt' ) )
443
+ ) . toBeTruthy ( )
444
+ expect (
445
+ fs . existsSync ( path . join ( toolPath , 'folder' , 'nested-file.txt' ) )
446
+ ) . toBeTruthy ( )
447
+ expect (
448
+ fs . readFileSync (
449
+ path . join ( toolPath , 'folder' , 'nested-file.txt' ) ,
450
+ 'utf8'
451
+ )
452
+ ) . toBe ( 'folder/nested-file.txt contents' )
453
+ } )
349
454
}
350
455
351
456
it ( 'extract .tar.gz' , async ( ) => {
0 commit comments