aboutsummaryrefslogtreecommitdiff
path: root/test.lua
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2025-01-06 17:13:30 +0100
committerPřemysl Eric Janouch <p@janouch.name>2025-01-08 06:40:52 +0100
commit278a7f95a9f50489f371b7137eff8a342b494fdf (patch)
treef23a43d502e4b7575801bdf4963e153419a2b0af /test.lua
parenta8575ab8757c3c22c534bcebd2558c712bc6df90 (diff)
downloadxK-278a7f95a9f50489f371b7137eff8a342b494fdf.tar.gz
xK-278a7f95a9f50489f371b7137eff8a342b494fdf.tar.xz
xK-278a7f95a9f50489f371b7137eff8a342b494fdf.zip
Port the integration test from expect to wdye
Diffstat (limited to 'test.lua')
-rw-r--r--test.lua72
1 files changed, 72 insertions, 0 deletions
diff --git a/test.lua b/test.lua
new file mode 100644
index 0000000..2edeca8
--- /dev/null
+++ b/test.lua
@@ -0,0 +1,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)