-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.lua
More file actions
executable file
·94 lines (73 loc) · 2.3 KB
/
tests.lua
File metadata and controls
executable file
·94 lines (73 loc) · 2.3 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
#! /usr/libexec/flua
-- SPDX-FileCopyrightText: 2025 D. Bohdan
-- SPDX-License-Identifier: BSD-2-Clause
--
-- Tests for lsblk.lua.
local lester = require("vendor/lester/lester")
local describe, it, expect = lester.describe, lester.it, lester.expect
lester.parse_args()
local function run(cmd)
local f = io.popen(cmd .. " 2>&1", "r")
local output = f:read("*a")
local _, _, code = f:close()
return code, output
end
describe("lsblk.lua", function()
describe("CLI options", function()
it("should show help", function()
local code, output = run("./lsblk.lua -h")
expect.equal(code, 0)
expect.truthy(output:find("List information about block devices"))
expect.truthy(output:find("--help"))
expect.truthy(output:find("--version"))
end)
it("should show version", function()
local code, output = run("./lsblk.lua -V")
expect.equal(code, 0)
expect.truthy(output:match("^%d+%.%d+%.%d+\n$"))
end)
it("should reject invalid options", function()
local code, output = run("./lsblk.lua -Q")
expect.equal(code, 2)
expect.truthy(output:find("invalid option"))
end)
it("should reject positional arguments", function()
local code, output = run("./lsblk.lua /dev/ada0")
expect.equal(code, 2)
expect.truthy(output:find("arguments"))
end)
end)
describe("output formats", function()
it("should show default output", function()
local code, output = run("./lsblk.lua")
expect.equal(code, 0)
expect.truthy(
output:find("NAME +MAJ:MIN +SIZE +TYPE +FSTYPE +MOUNTPOINTS\n")
)
expect.truthy(output:find("disk"))
expect.truthy(output:find("part"))
end)
it("should show byte output", function()
local code, output = run("./lsblk.lua -b")
expect.equal(code, 0)
expect.truthy(output:find(" %d+ disk"))
end)
it("should show geom output", function()
local code, output = run("./lsblk.lua -g")
expect.equal(code, 0)
expect.truthy(output:find("NAME"))
expect.truthy(output:find("disk"))
-- Should filter out ZFS.
expect.falsy(output:find("zfs"))
end)
it("should show ZFS output", function()
local code, output = run("./lsblk.lua -z")
-- Only compare the code and the header
-- because the test machine may not have ZFS pools.
expect.equal(code, 0)
expect.truthy(output:find("NAME"))
end)
end)
end)
lester.report()
lester.exit()