Skip to content

Support for test output through socket writing via LuaSocket

François Perrad requested to merge ewmailing:master into master

Created by: ewmailing

We modified Lua Test More to allow writing to sockets (via LuaSocket) in addition to stdout and files. We needed this because when testing on mobile devices like iOS and Android, it isn't always convenient or possible to fetch test results on the device itself. So we've overloaded/modified many of the internal functions to take an optional socket parameter so if a socket is set as the output, it will write to the socket instead. This allows us to transmit results to a server which saves and later analyzes the results.

In our use case, we essentially do the following:
require 'socket'
require 'Test.More'
local tb = test_builder()
local server = socket.connect(host, port)
if server then
    tb:set_output(nil, server)
    tb:set_failure_output(nil, server)
    tb:set_todo_output(nil, server)
end
tb:plan(plan_args)

We believe the final changes don't actually require LuaSocket to be present. The require 'socket' only needs to be done by the end-user if they use it. The internal code just references the socket object returned by LuaSocket. So if the user doesn't use LuaSocket, that code will never be hit.

Perhaps the most controversial of the changes is we split up some of the internal functions to have explicit set_ and get_ versions. We had some hairiness problems dealing with a single overloaded function that did both because we now have both file and socket parameters to move around which may or may not be nil. Splitting this up into separate setters and getters simplified ambiguity problems greatly.

Our changes were originally made against a 2.2-ish version. I've attempted to merge the changes with the work done since then in master. The merge probably should undergo some additional scrutiny because of that.

Merge request reports