@@ -42,3 +42,81 @@ t.test('os wrong (negation)', async t =>
42
42
43
43
t . test ( 'nothing wrong (negation)' , async t =>
44
44
checkPlatform ( { cpu : '!enten-cpu' , os : '!enten-os' } ) )
45
+
46
+ t . test ( 'libc' , ( t ) => {
47
+ let PLATFORM = ''
48
+
49
+ const _processPlatform = Object . getOwnPropertyDescriptor ( process , 'platform' )
50
+ Object . defineProperty ( process , 'platform' , {
51
+ enumerable : true ,
52
+ configurable : true ,
53
+ get : ( ) => PLATFORM ,
54
+ } )
55
+
56
+ let REPORT = { }
57
+ const _processReport = process . report . getReport
58
+ process . report . getReport = ( ) => REPORT
59
+
60
+ t . teardown ( ( ) => {
61
+ Object . defineProperty ( process , 'platform' , _processPlatform )
62
+ process . report . getReport = _processReport
63
+ } )
64
+
65
+ t . test ( 'fails when not in linux' , ( t ) => {
66
+ PLATFORM = 'darwin'
67
+
68
+ t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
69
+ 'fails for glibc when not in linux' )
70
+ t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
71
+ 'fails for musl when not in linux' )
72
+ t . end ( )
73
+ } )
74
+
75
+ t . test ( 'glibc' , ( t ) => {
76
+ PLATFORM = 'linux'
77
+
78
+ REPORT = { }
79
+ t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
80
+ 'fails when report is missing header property' )
81
+
82
+ REPORT = { header : { } }
83
+ t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
84
+ 'fails when header is missing glibcRuntimeVersion property' )
85
+
86
+ REPORT = { header : { glibcRuntimeVersion : '1' } }
87
+ t . doesNotThrow ( ( ) => checkPlatform ( { libc : 'glibc' } ) , 'allows glibc on glibc' )
88
+ t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
89
+ 'does not allow musl on glibc' )
90
+
91
+ t . end ( )
92
+ } )
93
+
94
+ t . test ( 'musl' , ( t ) => {
95
+ PLATFORM = 'linux'
96
+
97
+ REPORT = { }
98
+ t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
99
+ 'fails when report is missing sharedObjects property' )
100
+
101
+ REPORT = { sharedObjects : { } }
102
+ t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
103
+ 'fails when sharedObjects property is not an array' )
104
+
105
+ REPORT = { sharedObjects : [ ] }
106
+ t . throws ( ( ) => checkPlatform ( { libc : 'musl' } ) , { code : 'EBADPLATFORM' } ,
107
+ 'fails when sharedObjects does not contain musl' )
108
+
109
+ REPORT = { sharedObjects : [ 'ld-musl-foo' ] }
110
+ t . doesNotThrow ( ( ) => checkPlatform ( { libc : 'musl' } ) , 'allows musl on musl as ld-musl-' )
111
+
112
+ REPORT = { sharedObjects : [ 'libc.musl-' ] }
113
+ t . doesNotThrow ( ( ) => checkPlatform ( { libc : 'musl' } ) , 'allows musl on musl as libc.musl-' )
114
+
115
+ t . throws ( ( ) => checkPlatform ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
116
+ 'does not allow glibc on musl' )
117
+
118
+ t . end ( )
119
+ } )
120
+
121
+ t . end ( )
122
+ } )
0 commit comments