aboutsummaryrefslogtreecommitdiff
path: root/test.lua
blob: 2edeca82076992b9d2d178b1d93f2644aeb41d69 (plain)
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
#!/usr/bin/env wdye
-- Very basic end-to-end testing for CI
function exec (...)
	local p = wdye.spawn(...)
	local out = wdye.expect(p:eof {function (p) return p[0] end})
	if not out then
		error "exec() timeout"
	end

	local status = p:wait()
	if status ~= 0 then
		io.write(out, "\n")
		error("exit status " .. status)
	end
	return out:gsub("%s+$", "")
end

local temp = exec {"mktemp", "-d"}
local atexit = {}
setmetatable(atexit, {__gc = function () exec {"rm", "-rf", "--", temp} end})

local env = {XDG_CONFIG_HOME=temp, TERM="xterm"}
exec {"./xD", "--write-default-cfg", environ=env}

-- Run the daemon to test against (assuming the default port 6667)
local xD = wdye.spawn {"./xD", "-d", environ=env}
local xC = wdye.spawn {"./xC", environ=env}

function send (...) xC:send(...) end
function expect (string)
	wdye.expect(xC:exact {string},
		wdye.timeout {5, function (p) error "xC timeout" end},
		xC:eof {function (p) error "xC exited prematurely" end})
end

-- Connect to the daemon
send "/server add localhost\n"
expect "]"
send "/set servers.localhost.addresses = \"localhost\"\n"
expect "Option changed"
send "/disconnect\n"
expect "]"
send "/connect\n"
expect "Welcome to"

-- Try some chatting
send "/join #test\n"
expect "has joined"
send "Hello\n"
expect "Hello"

-- Attributes
send "\x1bmbBold text! \x1bmc0,5And colors.\n"
expect "]"

-- Try basic commands
send "/set\n"
expect "]"
send "/help\n"
expect "]"

-- Quit
send "/quit\n"
expect "Shutting down"

local s1 = xC:wait()
assert(s1 == 0, "xC exited abnormally: " .. s1)

-- Send SIGINT (^C)
xD:send "\003"
local s2 = xD:wait()
assert(s2 == 0, "xD exited abnormally: " .. s2)