# HG changeset patch # User Matthew Wild # Date 1455882511 0 # Node ID c9061cd9951b5ee1c0e73912b31091723898c059 # Parent 52f8fa7f999e38645319d18d2e9ea80e4153b55e client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example diff -r 52f8fa7f999e -r c9061cd9951b scansion/objects/client.lua --- a/scansion/objects/client.lua Fri Feb 19 11:48:04 2016 +0000 +++ b/scansion/objects/client.lua Fri Feb 19 11:48:31 2016 +0000 @@ -85,12 +85,21 @@ receives = function (client, data) local wait, done = async.waiter(); - local expected_stanza = fill_vars(client.script, assert(parse_xml((table.concat(data):gsub("\t", " "))))); + local expected_stanza = false; + data = table.concat(data):gsub("\t", " "):gsub("^%s+", ""):gsub("%s+$", ""); + if data ~= "nothing" then + expected_stanza = fill_vars(client.script, assert(parse_xml(data))); + end local function stanza_handler(received_stanza) - if not stanzacmp.stanzas_match(expected_stanza, received_stanza) then - client.log("NOT IT!") - client.log("Expected: %s", expected_stanza); - client.log("Received: %s", received_stanza); + if not expected_stanza then + error(new_error("Received unexpected stanza", { stanza = tostring(received_stanza) })); + elseif not expected_stanza or not stanzacmp.stanzas_match(expected_stanza, received_stanza) then + if not expected_stanza then + client.log("Received a stanza when none were expected: %s", received_stanza); + else + client.log("Expected: %s", expected_stanza); + client.log("Received: %s", received_stanza); + end error(new_error("Received unexpected stanza", { stanza = tostring(received_stanza) })); else client.last_received_id = received_stanza.attr.id;