-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhost-targets-test.js
More file actions
128 lines (111 loc) · 3.28 KB
/
Copy pathhost-targets-test.js
File metadata and controls
128 lines (111 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'use strict';
let HostTargets = require('./host-targets.js');
function parseUa(ua) {
let terms = [];
let parts = ua.split(/\s+/g);
for (let part of parts) {
let _terms = part.split(/\//g);
terms = terms.concat(_terms);
}
let target = {};
HostTargets.termsToTarget(target, terms);
return target;
}
function assertField(ua, target, field, expected) {
let actual = target[field];
if (actual !== expected) {
throw new Error(
`[${field}] expected '${expected}' but got '${actual}' for UA:\n ${ua}`,
);
}
}
function testCase(ua, expected) {
let target = parseUa(ua);
for (let [field, value] of Object.entries(expected)) {
assertField(ua, target, field, value);
}
}
async function main() {
// Cygwin on 32-bit Windows (reports 'gnu')
testCase('webi/curl+wget i686/unknown CYGWIN_NT-10.0-WOW/3.3.5(0.341/5/3) gnu', {
os: 'windows',
arch: 'x86',
vendor: 'pc',
});
// Cygwin on 32-bit Windows, legacy curl-only UA
testCase('curl CYGWIN_NT-10.0-WOW/3.3.5(0.341/5/3) i686/unknown gnu', {
os: 'windows',
arch: 'x86',
vendor: 'pc',
});
// Cygwin on 64-bit Windows (reports 'libc'), "Cygwin" prefix variant
testCase('webi/curl x86_64/unknown Cygwin/CYGWIN_NT-10.0/3.3.4(0.341/5/3) libc', {
os: 'windows',
arch: 'x86_64',
vendor: 'pc',
});
// Cygwin on 64-bit Windows 10 (build 19045)
testCase('webi/curl+wget x86_64/unknown Cygwin/CYGWIN_NT-10.0-19045/3.4.10-1.x86_64 libc', {
os: 'windows',
arch: 'x86_64',
vendor: 'pc',
});
// Cygwin on 64-bit Windows 11 (build 26200) — from issue #1083
testCase('webi/curl+wget x86_64/unknown Cygwin/CYGWIN_NT-10.0-26200/3.4.10-1.x86_64 libc', {
os: 'windows',
arch: 'x86_64',
vendor: 'pc',
});
// Cygwin UA with GNU/Linux prefix (webi.sh quirk on some Cygwin installs)
testCase('webi/curl+wget i686/unknown GNU/Linux/CYGWIN_NT-10.0-WOW/3.3.5(0.341/5/3) libc', {
os: 'windows',
arch: 'x86',
vendor: 'pc',
});
// MINGW (Git Bash) on 64-bit Windows, webi UA
testCase('webi/curl x86_64/unknown MINGW64_NT-10.0-19045/3.3.6-341.x86_64 libc', {
os: 'windows',
arch: 'x86_64',
vendor: 'pc',
});
// MINGW (Git Bash), legacy curl-only UA
testCase('curl MINGW64_NT-10.0-19045/3.3.6-341.x86_64 x86_64/unknown libc', {
os: 'windows',
arch: 'x86_64',
vendor: 'pc',
});
// MINGW with Linux prefix in UA path (older Git Bash format)
testCase('curl Linux/MINGW64_NT-10.0-19045/3.3.6-341.x86_64 x86_64/unknown libc', {
os: 'windows',
arch: 'x86_64',
vendor: 'pc',
});
// MINGW with Msys prefix (Msys2 variant)
testCase('webi/curl x86_64/unknown Msys/MINGW64_NT-10.0-19045/3.3.6-341.x86_64 libc', {
os: 'windows',
arch: 'x86_64',
vendor: 'pc',
});
// Sanity: real Linux should NOT be classified as Windows
testCase('webi/curl+wget x86_64/unknown Linux/6.2.0-1012-aws gnu', {
os: 'linux',
arch: 'x86_64',
vendor: 'unknown',
});
// Sanity: Darwin should NOT be classified as Windows
testCase('webi/curl arm64/unknown Darwin/22.6.0', {
os: 'darwin',
arch: 'aarch64',
vendor: 'apple',
});
}
main()
.then(function () {
console.error('');
console.error('PASS');
process.exit(0);
})
.catch(function (e) {
console.error(e.stack);
process.exit(1);
});