@@ -95,49 +95,68 @@ t.test('wrong libc with overridden libc', async t =>
95
95
} ) , { code : 'EBADPLATFORM' } ) )
96
96
97
97
t . test ( 'libc' , ( t ) => {
98
- let PLATFORM = ''
99
-
100
- const _processPlatform = Object . getOwnPropertyDescriptor ( process , 'platform' )
101
- Object . defineProperty ( process , 'platform' , {
102
- enumerable : true ,
103
- configurable : true ,
104
- get : ( ) => PLATFORM ,
105
- } )
106
-
98
+ let noCacheChckPtfm
99
+ let PLATFORM = 'linux'
107
100
let REPORT = { }
108
- const _processReport = process . report . getReport
109
- process . report . getReport = ( ) => REPORT
110
- process . report . forceCheck = true
111
-
112
- t . teardown ( ( ) => {
113
- Object . defineProperty ( process , 'platform' , _processPlatform )
114
- process . report . getReport = _processReport
115
- } )
101
+ let readFileSync
102
+
103
+ function withoutLibcCache ( ) {
104
+ readFileSync = ( ) => {
105
+ throw new Error ( 'File not found' )
106
+ }
107
+ noCacheChckPtfm = ( ...args ) => {
108
+ const original = t . mock ( '..' , {
109
+ '../lib/current-env' : t . mock ( '../lib/current-env' , {
110
+ 'node:fs' : {
111
+ readFileSync,
112
+ } ,
113
+ 'node:process' : {
114
+ platform : PLATFORM ,
115
+ report : {
116
+ getReport : ( ) => REPORT ,
117
+ } ,
118
+ } ,
119
+ } ) ,
120
+ } ) . checkPlatform
121
+ withoutLibcCache ( )
122
+ return original ( ...args )
123
+ }
124
+ }
125
+
126
+ withoutLibcCache ( )
116
127
117
128
t . test ( 'fails when not in linux' , ( t ) => {
118
129
PLATFORM = 'darwin'
119
130
120
- t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
131
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
121
132
'fails for glibc when not in linux' )
122
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
133
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
123
134
'fails for musl when not in linux' )
124
135
t . end ( )
125
136
} )
126
137
127
138
t . test ( 'glibc' , ( t ) => {
128
139
PLATFORM = 'linux'
129
140
141
+ readFileSync = ( ) => 'this ldd file contains GNU C Library'
142
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , 'allows glibc on glibc from ldd file' )
143
+
130
144
REPORT = { }
131
- t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
145
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
132
146
'fails when report is missing header property' )
133
147
134
148
REPORT = { header : { } }
135
- t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
149
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
136
150
'fails when header is missing glibcVersionRuntime property' )
137
151
138
152
REPORT = { header : { glibcVersionRuntime : '1' } }
139
- t . doesNotThrow ( ( ) => checkPlatform ( { libc : 'glibc' } ) , 'allows glibc on glibc' )
140
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
153
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , 'allows glibc on glibc' )
154
+
155
+ readFileSync = ( ) => 'this ldd file is unsupported'
156
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
157
+ 'fails when ldd file exists but is not something known' )
158
+
159
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
141
160
'does not allow musl on glibc' )
142
161
143
162
t . end ( )
@@ -146,25 +165,28 @@ t.test('libc', (t) => {
146
165
t . test ( 'musl' , ( t ) => {
147
166
PLATFORM = 'linux'
148
167
168
+ readFileSync = ( ) => 'this ldd file contains musl'
169
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , 'allows musl on musl from ldd file' )
170
+
149
171
REPORT = { }
150
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
172
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
151
173
'fails when report is missing sharedObjects property' )
152
174
153
175
REPORT = { sharedObjects : { } }
154
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
176
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
155
177
'fails when sharedObjects property is not an array' )
156
178
157
179
REPORT = { sharedObjects : [ ] }
158
- t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
180
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
159
181
'fails when sharedObjects does not contain musl' )
160
182
161
183
REPORT = { sharedObjects : [ 'ld-musl-foo' ] }
162
- t . doesNotThrow ( ( ) => checkPlatform ( { libc : 'musl' } ) , 'allows musl on musl as ld-musl-' )
184
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , 'allows musl on musl as ld-musl-' )
163
185
164
186
REPORT = { sharedObjects : [ 'libc.musl-' ] }
165
- t . doesNotThrow ( ( ) => checkPlatform ( { libc : 'musl' } ) , 'allows musl on musl as libc.musl-' )
187
+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'musl' } ) , 'allows musl on musl as libc.musl-' )
166
188
167
- t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
189
+ t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
168
190
'does not allow glibc on musl' )
169
191
170
192
t . end ( )
0 commit comments