aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-09-29 01:02:45 +0200
committerGitHub <noreply@github.com>2022-09-29 01:02:45 +0200
commit342c81c29b74a4254dd2636005549832a6b44631 (patch)
tree3a8c4f96d5bc0bf8dee2be67b6fc76ceb0e3c8c8 /tests
parentfeat(verible): add support for CentOS 7.9 (#471) (diff)
downloadmason-342c81c29b74a4254dd2636005549832a6b44631.tar
mason-342c81c29b74a4254dd2636005549832a6b44631.tar.gz
mason-342c81c29b74a4254dd2636005549832a6b44631.tar.bz2
mason-342c81c29b74a4254dd2636005549832a6b44631.tar.lz
mason-342c81c29b74a4254dd2636005549832a6b44631.tar.xz
mason-342c81c29b74a4254dd2636005549832a6b44631.tar.zst
mason-342c81c29b74a4254dd2636005549832a6b44631.zip
refactor(platform): more functional approach to parsing (#479)
Diffstat (limited to 'tests')
-rw-r--r--tests/mason-core/functional/table_spec.lua16
-rw-r--r--tests/mason-core/platform_spec.lua93
2 files changed, 109 insertions, 0 deletions
diff --git a/tests/mason-core/functional/table_spec.lua b/tests/mason-core/functional/table_spec.lua
index 012c981c..7516e33a 100644
--- a/tests/mason-core/functional/table_spec.lua
+++ b/tests/mason-core/functional/table_spec.lua
@@ -36,6 +36,22 @@ describe("functional: table", function()
)
end)
+ it("converts pairs to table", function()
+ assert.same(
+ { skies = "cloudy", temperature = "20°" },
+ _.from_pairs {
+ {
+ "skies",
+ "cloudy",
+ },
+ {
+ "temperature",
+ "20°",
+ },
+ }
+ )
+ end)
+
it("should invert tables", function()
assert.same(
{
diff --git a/tests/mason-core/platform_spec.lua b/tests/mason-core/platform_spec.lua
index 7559e1ce..d85354ca 100644
--- a/tests/mason-core/platform_spec.lua
+++ b/tests/mason-core/platform_spec.lua
@@ -1,6 +1,18 @@
local stub = require "luassert.stub"
local spy = require "luassert.spy"
local match = require "luassert.match"
+local _ = require "mason-core.functional"
+local Result = require "mason-core.result"
+
+local spawn = require "mason-core.spawn"
+
+---@param contents string
+local function stub_etc_os_release(contents)
+ stub(spawn, "bash")
+ spawn.bash.on_call_with({ "-c", "cat /etc/*-release" }).returns(Result.success {
+ stdout = contents,
+ })
+end
describe("platform", function()
local function platform()
@@ -179,4 +191,85 @@ describe("platform", function()
assert.spy(unix).was_called(1)
assert.spy(win).was_not_called()
end)
+
+ describe("macOS distribution detection", function()
+ before_each(function()
+ stub_mac()
+ end)
+
+ it("detects macOS", function()
+ assert.same({ id = "macOS", version = {} }, platform().os_distribution())
+ end)
+ end)
+
+ describe("Windows distribution detection", function()
+ before_each(function()
+ stub_windows()
+ end)
+
+ it("detects Windows", function()
+ assert.same({ id = "windows", version = {} }, platform().os_distribution())
+ end)
+ end)
+
+ describe("Linux distribution detection", function()
+ before_each(function()
+ stub_linux()
+ end)
+
+ it("detects Ubuntu", function()
+ stub_etc_os_release(_.dedent [[
+ NAME="Ubuntu"
+ VERSION="20.04.5 LTS (Focal Fossa)"
+ ID=ubuntu
+ ID_LIKE=debian
+ PRETTY_NAME="Ubuntu 20.04.5 LTS"
+ VERSION_ID="20.04"
+ HOME_URL="https://www.ubuntu.com/"
+ SUPPORT_URL="https://help.ubuntu.com/"
+ BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
+ PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
+ VERSION_CODENAME=focal
+ UBUNTU_CODENAME=focal
+ ]])
+ assert.same(
+ { id = "ubuntu", version = { major = 20, minor = 4 }, version_id = "20.04" },
+ platform().os_distribution()
+ )
+ end)
+
+ it("detects CentOS", function()
+ stub_etc_os_release(_.dedent [[
+ NAME="CentOS Linux"
+ VERSION="7 (Core)"
+ ID="centos"
+ ID_LIKE="rhel fedora"
+ VERSION_ID="7"
+ PRETTY_NAME="CentOS Linux 7 (Core)"
+ ANSI_COLOR="0;31"
+ CPE_NAME="cpe:/o:centos:centos:7"
+ HOME_URL="https://www.centos.org/"
+ BUG_REPORT_URL="https://bugs.centos.org/"
+
+ CENTOS_MANTISBT_PROJECT="CentOS-7"
+ CENTOS_MANTISBT_PROJECT_VERSION="7"
+ REDHAT_SUPPORT_PRODUCT="centos"
+ REDHAT_SUPPORT_PRODUCT_VERSION="7"
+ ]])
+ assert.same({ id = "centos", version = { major = 7 }, version_id = "7" }, platform().os_distribution())
+ end)
+
+ it("detects generic Linux", function()
+ stub(spawn, "bash")
+ spawn.bash.returns(Result.failure())
+ assert.same({ id = "linux-generic", version = {} }, platform().os_distribution())
+ end)
+
+ it("detects generic Linux", function()
+ stub_etc_os_release(_.dedent [[
+ UNKNOWN_ID=here
+ ]])
+ assert.same({ id = "linux-generic", version = {} }, platform().os_distribution())
+ end)
+ end)
end)