compat_spec.lua

 1-- SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2--
 3-- SPDX-License-Identifier: GPL-3.0-or-later
 4
 5describe("Lua version compatibility", function()
 6	describe("os.execute return value", function()
 7		it("returns true for successful commands", function()
 8			local success = os.execute("true")
 9			assert.is_true(success == true or success == 0)
10		end)
11
12		it("returns non-true for failed commands", function()
13			local success = os.execute("false")
14			assert.is_not_true(success == true)
15		end)
16	end)
17
18	describe("load() with 4 arguments", function()
19		it("works with mode and env parameters", function()
20			local chunk = load("return 42", "test", "t", {})
21			assert.is_function(chunk)
22			assert.are.equal(42, chunk())
23		end)
24
25		it("respects restricted environment", function()
26			local chunk = load("return { x = 1, y = 2 }", "test", "t", {})
27			assert.is_function(chunk)
28			local result = chunk()
29			assert.are.equal(1, result.x)
30			assert.are.equal(2, result.y)
31		end)
32	end)
33
34	describe("string patterns used in wt", function()
35		it("matches git URL project names", function()
36			local url = "git@github.com:user/project.git"
37			local name = url:match("([^/]+)%.git$") or url:match("([^/:]+)$")
38			assert.are.equal("project", name)
39		end)
40
41		it("matches https URL project names", function()
42			local url = "https://github.com/user/project.git"
43			local name = url:match("([^/]+)%.git$") or url:match("([^/:]+)$")
44			assert.are.equal("project", name)
45		end)
46
47		it("handles gitdir patterns", function()
48			local content = "gitdir: .bare"
49			assert.is_truthy(content:match("gitdir:%s*%.?/?%.bare"))
50		end)
51	end)
52
53	describe("io.popen", function()
54		it("captures command output", function()
55			local handle = io.popen("echo hello")
56			assert.is_not_nil(handle)
57			local output = handle:read("*a")
58			handle:close()
59			assert.are.equal("hello\n", output)
60		end)
61	end)
62end)