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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
local stub = require "luassert.stub"
local spy = require "luassert.spy"
local match = require "luassert.match"
describe("platform", function()
local function platform()
package.loaded["mason-core.platform"] = nil
return require "mason-core.platform"
end
local function stub_mac(arch)
arch = arch or "x86_64"
stub(vim.fn, "has")
stub(vim.loop, "os_uname")
vim.loop.os_uname.returns { machine = arch }
vim.fn.has.on_call_with("mac").returns(1)
vim.fn.has.on_call_with("unix").returns(1)
vim.fn.has.on_call_with(match._).returns(0)
end
local function stub_linux()
stub(vim.fn, "has")
vim.fn.has.on_call_with("mac").returns(0)
vim.fn.has.on_call_with("unix").returns(1)
vim.fn.has.on_call_with(match._).returns(0)
end
local function stub_windows()
stub(vim.fn, "has")
vim.fn.has.on_call_with("win32").returns(1)
vim.fn.has.on_call_with(match._).returns(0)
end
it("should be able to detect platform and arch", function()
stub_mac "arm64"
assert.is_true(platform().is.mac_arm64)
assert.is_false(platform().is.mac_x64)
assert.is_false(platform().is.nothing)
end)
it("should be able to detect macos", function()
stub_mac()
assert.is_true(platform().is_mac)
assert.is_true(platform().is.mac)
assert.is_true(platform().is_unix)
assert.is_true(platform().is.unix)
assert.is_false(platform().is_linux)
assert.is_false(platform().is.linux)
assert.is_false(platform().is_win)
assert.is_false(platform().is.win)
end)
it("should be able to detect linux", function()
stub_linux()
assert.is_false(platform().is_mac)
assert.is_false(platform().is.mac)
assert.is_true(platform().is_unix)
assert.is_true(platform().is.unix)
assert.is_true(platform().is_linux)
assert.is_true(platform().is.linux)
assert.is_false(platform().is_win)
assert.is_false(platform().is.win)
end)
it("should be able to detect windows", function()
stub_windows()
assert.is_false(platform().is_mac)
assert.is_false(platform().is.mac)
assert.is_false(platform().is_unix)
assert.is_false(platform().is.unix)
assert.is_false(platform().is_linux)
assert.is_false(platform().is.linux)
assert.is_true(platform().is_win)
assert.is_true(platform().is.win)
end)
it("should run correct case on linux", function()
local unix = spy.new()
local win = spy.new()
local mac = spy.new()
local linux = spy.new()
stub_linux()
platform().when {
unix = unix,
win = win,
linux = linux,
mac = mac,
}
assert.spy(unix).was_not_called()
assert.spy(mac).was_not_called()
assert.spy(win).was_not_called()
assert.spy(linux).was_called(1)
end)
it("should run correct case on mac", function()
local unix = spy.new()
local win = spy.new()
local mac = spy.new()
local linux = spy.new()
stub_mac()
platform().when {
unix = unix,
win = win,
linux = linux,
mac = mac,
}
assert.spy(unix).was_not_called()
assert.spy(mac).was_called(1)
assert.spy(win).was_not_called()
assert.spy(linux).was_not_called()
end)
it("should run correct case on windows", function()
local unix = spy.new()
local win = spy.new()
local mac = spy.new()
local linux = spy.new()
stub_windows()
platform().when {
unix = unix,
win = win,
linux = linux,
mac = mac,
}
assert.spy(unix).was_not_called()
assert.spy(mac).was_not_called()
assert.spy(win).was_called(1)
assert.spy(linux).was_not_called()
end)
it("should run correct case on mac (unix)", function()
local unix = spy.new()
local win = spy.new()
stub_mac()
platform().when {
unix = unix,
win = win,
}
assert.spy(unix).was_called(1)
assert.spy(win).was_not_called()
end)
it("should run correct case on linux (unix)", function()
local unix = spy.new()
local win = spy.new()
stub_linux()
platform().when {
unix = unix,
win = win,
}
assert.spy(unix).was_called(1)
assert.spy(win).was_not_called()
end)
end)
|