Repository navigation
Expand file tree
/
Copy pathtest-spawn.lua
More file actions
83 lines (76 loc) · 2.37 KB
/
Copy pathtest-spawn.lua
File metadata and controls
83 lines (76 loc) · 2.37 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
--- Tests for spawn
local runner = require("_runner")
local spawn = require("awful.spawn")
local spawns_done = 0
local exit_yay, exit_snd = nil, nil
-- * Using spawn with array is already covered by the test client.
-- * spawn with startup notification is covered by test-spawn-snid.lua
local steps = {
function(count)
if count == 1 then
local steps_yay = 0
spawn.with_line_callback("echo yay", {
stdout = function(line)
assert(line == "yay", "line == '" .. tostring(line) .. "'")
assert(steps_yay == 0)
steps_yay = steps_yay + 1
end,
output_done = function()
assert(steps_yay == 1)
steps_yay = steps_yay + 1
spawns_done = spawns_done + 1
end,
exit = function(reason, code)
assert(reason == "exit")
assert(exit_yay == nil)
assert(code == 0)
exit_yay = code
end
})
local steps_count = 0
local err_count = 0
spawn.with_line_callback({ "sh", "-c", "printf line1\\\\nline2\\\\nline3 ; echo err >&2 ; exit 42" }, {
stdout = function(line)
assert(steps_count < 3)
steps_count = steps_count + 1
assert(line == "line" .. steps_count, "line == '" .. tostring(line) .. "'")
end,
stderr = function(line)
assert(err_count == 0)
err_count = err_count + 1
assert(line == "err", "line == '" .. tostring(line) .. "'")
end,
output_done = function()
assert(steps_count == 3)
assert(err_count == 1)
steps_count = steps_count + 1
spawns_done = spawns_done + 1
end,
exit = function(reason, code)
assert(reason == "exit")
assert(exit_snd == nil)
assert(code == 42)
exit_snd = code
end
})
end
if spawns_done == 2 then
assert(exit_yay == 0)
assert(exit_snd == 42)
return true
end
end,
function()
-- Test empty command table
spawn{}
return true
end,
function()
-- Test empty command string
spawn("")
assert(#client.get() == 0)
return true
end,
}
runner.run_steps(steps)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80