1 local errors
= require
"util.error"
3 describe("util.error", function ()
4 describe("new()", function ()
5 it("works", function ()
6 local err
= errors
.new("bork", "bork bork");
8 assert.equal("cancel", err
.type);
9 assert.equal("undefined-condition", err
.condition
);
10 assert.same("bork bork", err
.context
);
13 describe("templates", function ()
14 it("works", function ()
18 condition
= "internal-server-error",
21 local err
= errors
.new("fail", { traceback
= "in some file, somewhere" }, templates
);
22 assert.equal("wait", err
.type);
23 assert.equal("internal-server-error", err
.condition
);
24 assert.same({ traceback
= "in some file, somewhere" }, err
.context
);
30 describe("is_err()", function ()
31 it("works", function ()
32 assert.truthy(errors
.is_err(errors
.new()));
33 assert.falsy(errors
.is_err("not an error"));
37 describe("coerce", function ()
38 it("works", function ()
39 local ok
, err
= errors
.coerce(nil, "it dun goofed");
41 assert.truthy(errors
.is_err(err
))
45 describe("from_stanza", function ()
46 it("works", function ()
47 local st
= require
"util.stanza";
48 local m
= st
.message({ type = "chat" });
49 local e
= st
.error_reply(m
, "modify", "bad-request");
50 local err
= errors
.from_stanza(e
);
51 assert.truthy(errors
.is_err(err
));
52 assert.equal("modify", err
.type);
53 assert.equal("bad-request", err
.condition
);
54 assert.equal(e
, err
.context
.stanza
);
58 describe("__tostring", function ()
59 it("doesn't throw", function ()
60 assert.has_no
.errors(function ()
62 tostring(errors
.new());