@@ -5,31 +5,29 @@ const umask = process.umask()
55const fs = require ( 'fs' )
66const { readFileSync, statSync, chmodSync } = fs
77
8- t . test ( 'fix windows hashbang' , t => {
8+ t . test ( 'fix windows hashbang' , async t => {
99 const dir = t . testdir ( {
1010 whb : `#!/usr/bin/env node\r\nconsole.log('hello')\r\n` ,
1111 } )
1212 chmodSync ( `${ dir } /whb` , 0o644 )
13- return fixBin ( `${ dir } /whb` ) . then ( ( ) => {
14- t . equal ( ( statSync ( `${ dir } /whb` ) . mode & 0o777 ) , 0o777 & ( ~ umask ) , 'has exec perms' )
15- t . equal ( readFileSync ( `${ dir } /whb` , 'utf8' ) ,
16- `#!/usr/bin/env node\nconsole.log('hello')\r\n` , 'fixed \\r on hashbang line' )
17- } )
13+ await fixBin ( `${ dir } /whb` )
14+ t . equal ( ( statSync ( `${ dir } /whb` ) . mode & 0o777 ) , 0o777 & ( ~ umask ) , 'has exec perms' )
15+ t . equal ( readFileSync ( `${ dir } /whb` , 'utf8' ) ,
16+ `#!/usr/bin/env node\nconsole.log('hello')\r\n` , 'fixed \\r on hashbang line' )
1817} )
1918
20- t . test ( 'dont fix non-windows hashbang file' , t => {
19+ t . test ( 'dont fix non-windows hashbang file' , async t => {
2120 const dir = t . testdir ( {
2221 goodhb : `#!/usr/bin/env node\nconsole.log('hello')\r\n` ,
2322 } )
2423 chmodSync ( `${ dir } /goodhb` , 0o644 )
25- return fixBin ( `${ dir } /goodhb` ) . then ( ( ) => {
26- t . equal ( ( statSync ( `${ dir } /goodhb` ) . mode & 0o777 ) , 0o777 & ( ~ umask ) , 'has exec perms' )
27- t . equal ( readFileSync ( `${ dir } /goodhb` , 'utf8' ) ,
28- `#!/usr/bin/env node\nconsole.log('hello')\r\n` , 'fixed \\r on hashbang line' )
29- } )
24+ await fixBin ( `${ dir } /goodhb` )
25+ t . equal ( ( statSync ( `${ dir } /goodhb` ) . mode & 0o777 ) , 0o777 & ( ~ umask ) , 'has exec perms' )
26+ t . equal ( readFileSync ( `${ dir } /goodhb` , 'utf8' ) ,
27+ `#!/usr/bin/env node\nconsole.log('hello')\r\n` , 'fixed \\r on hashbang line' )
3028} )
3129
32- t . test ( 'failure to read means not a windows hash bang file' , t => {
30+ t . test ( 'failure to read means not a windows hash bang file' , async t => {
3331 const fsMock = {
3432 ...fs ,
3533 read : ( a , b , c , d , e , cb ) => {
@@ -45,15 +43,14 @@ t.test('failure to read means not a windows hash bang file', t => {
4543 whb : `#!/usr/bin/env node\r\nconsole.log('hello')\r\n` ,
4644 } )
4745 chmodSync ( `${ dir } /whb` , 0o644 )
48- return mockedFixBin ( `${ dir } /whb` ) . then ( ( ) => {
49- t . equal ( ( statSync ( `${ dir } /whb` ) . mode & 0o777 ) , 0o777 & ( ~ umask ) , 'has exec perms' )
50- t . equal ( readFileSync ( `${ dir } /whb` , 'utf8' ) ,
51- /* eslint-disable-next-line max-len */
52- `#!/usr/bin/env node\r\nconsole.log('hello')\r\n` , 'did not fix \\r on hashbang line (failed read)' )
53- } )
46+ await mockedFixBin ( `${ dir } /whb` )
47+ t . equal ( ( statSync ( `${ dir } /whb` ) . mode & 0o777 ) , 0o777 & ( ~ umask ) , 'has exec perms' )
48+ t . equal ( readFileSync ( `${ dir } /whb` , 'utf8' ) ,
49+ /* eslint-disable-next-line max-len */
50+ `#!/usr/bin/env node\r\nconsole.log('hello')\r\n` , 'did not fix \\r on hashbang line (failed read)' )
5451} )
5552
56- t . test ( 'failure to close is ignored' , t => {
53+ t . test ( 'failure to close is ignored' , async t => {
5754 const fsMock = {
5855 ...fs ,
5956 close : ( fd , cb ) => {
@@ -69,34 +66,33 @@ t.test('failure to close is ignored', t => {
6966 whb : `#!/usr/bin/env node\r\nconsole.log('hello')\r\n` ,
7067 } )
7168 chmodSync ( `${ dir } /whb` , 0o644 )
72- return mockedFixBin ( `${ dir } /whb` ) . then ( ( ) => {
73- t . equal ( ( statSync ( `${ dir } /whb` ) . mode & 0o777 ) , 0o777 & ( ~ umask ) , 'has exec perms' )
74- t . equal ( readFileSync ( `${ dir } /whb` , 'utf8' ) ,
75- /* eslint-disable-next-line max-len */
76- `#!/usr/bin/env node\nconsole.log('hello')\r\n` , 'fixed \\r on hashbang line (ignored failed close)' )
77- } )
69+ await mockedFixBin ( `${ dir } /whb` )
70+ t . equal ( ( statSync ( `${ dir } /whb` ) . mode & 0o777 ) , 0o777 & ( ~ umask ) , 'has exec perms' )
71+ t . equal (
72+ readFileSync ( `${ dir } /whb` , 'utf8' ) ,
73+ `#!/usr/bin/env node\nconsole.log('hello')\r\n` ,
74+ 'fixed \\r on hashbang line (ignored failed close)'
75+ )
7876} )
7977
80- t . test ( 'custom exec mode' , t => {
78+ t . test ( 'custom exec mode' , async t => {
8179 const dir = t . testdir ( {
8280 goodhb : `#!/usr/bin/env node\nconsole.log('hello')\r\n` ,
8381 } )
8482 chmodSync ( `${ dir } /goodhb` , 0o644 )
85- return fixBin ( `${ dir } /goodhb` , 0o755 ) . then ( ( ) => {
86- t . equal ( ( statSync ( `${ dir } /goodhb` ) . mode & 0o755 ) , 0o755 & ( ~ umask ) , 'has exec perms' )
87- t . equal ( readFileSync ( `${ dir } /goodhb` , 'utf8' ) ,
88- `#!/usr/bin/env node\nconsole.log('hello')\r\n` , 'fixed \\r on hashbang line' )
89- } )
83+ await fixBin ( `${ dir } /goodhb` , 0o755 )
84+ t . equal ( ( statSync ( `${ dir } /goodhb` ) . mode & 0o755 ) , 0o755 & ( ~ umask ) , 'has exec perms' )
85+ t . equal ( readFileSync ( `${ dir } /goodhb` , 'utf8' ) ,
86+ `#!/usr/bin/env node\nconsole.log('hello')\r\n` , 'fixed \\r on hashbang line' )
9087} )
9188
92- t . test ( 'custom exec mode in windows' , t => {
89+ t . test ( 'custom exec mode in windows' , async t => {
9390 const dir = t . testdir ( {
9491 goodhb : `#!/usr/bin/env node\r\nconsole.log('hello')\r\n` ,
9592 } )
9693 chmodSync ( `${ dir } /goodhb` , 0o644 )
97- return fixBin ( `${ dir } /goodhb` , 0o755 ) . then ( ( ) => {
98- t . equal ( ( statSync ( `${ dir } /goodhb` ) . mode & 0o755 ) , 0o755 & ( ~ umask ) , 'has exec perms' )
99- t . equal ( readFileSync ( `${ dir } /goodhb` , 'utf8' ) ,
100- `#!/usr/bin/env node\nconsole.log('hello')\r\n` , 'fixed \\r on hashbang line' )
101- } )
94+ await fixBin ( `${ dir } /goodhb` , 0o755 )
95+ t . equal ( ( statSync ( `${ dir } /goodhb` ) . mode & 0o755 ) , 0o755 & ( ~ umask ) , 'has exec perms' )
96+ t . equal ( readFileSync ( `${ dir } /goodhb` , 'utf8' ) ,
97+ `#!/usr/bin/env node\nconsole.log('hello')\r\n` , 'fixed \\r on hashbang line' )
10298} )
0 commit comments