Annotate

spec/util_error_spec.lua @ 10299:fd94721186b8

Merge 0.11->trunk
author Matthew Wild <mwild1@gmail.com>
date Thu, 03 Oct 2019 16:38:46 +0100
parent 10101:ba7636860bbc
child 10365:744ca71a49f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10101
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local errors = require "util.error"
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 describe("util.error", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 describe("new()", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 it("works", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local err = errors.new("bork", "bork bork");
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 assert.not_nil(err);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 assert.equal("cancel", err.type);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 assert.equal("undefined-condition", err.condition);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 assert.same("bork bork", err.context);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 describe("templates", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 it("works", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local templates = {
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 ["fail"] = {
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 type = "wait",
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 condition = "internal-server-error",
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 };
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 };
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 local err = errors.new("fail", { traceback = "in some file, somewhere" }, templates);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 assert.equal("wait", err.type);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 assert.equal("internal-server-error", err.condition);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 assert.same({ traceback = "in some file, somewhere" }, err.context);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 describe("is_err()", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 it("works", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 assert.truthy(errors.is_err(errors.new()));
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 assert.falsy(errors.is_err("not an error"));
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 describe("coerce", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 it("works", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 local ok, err = errors.coerce(nil, "it dun goofed");
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 assert.is_nil(ok);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 assert.truthy(errors.is_err(err))
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 describe("from_stanza", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 it("works", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 local st = require "util.stanza";
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 local m = st.message({ type = "chat" });
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 local e = st.error_reply(m, "modify", "bad-request");
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 local err = errors.from_stanza(e);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 assert.truthy(errors.is_err(err));
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 assert.equal("modify", err.type);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 assert.equal("bad-request", err.condition);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 assert.equal(e, err.context.stanza);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 describe("__tostring", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 it("doesn't throw", function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 assert.has_no.errors(function ()
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 -- See 6f317e51544d
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 tostring(errors.new());
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 end);
ba7636860bbc util.error: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68