scansion/console.lua

Sun, 30 Dec 2018 09:43:36 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 30 Dec 2018 09:43:36 +0000
changeset 164
14500a149b31
parent 148
e2c85e095a4c
child 174
662bd8c5ae28
permissions
-rw-r--r--

client: Ignore timeout timer if we received a stanza

115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local pretty = require "scansion.pretty".new({});
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
145
df4faaa2d36f scansion.console: Support for indentation in lines() helper
Matthew Wild <mwild1@gmail.com>
parents: 133
diff changeset
3 local function lines(l, indent)
df4faaa2d36f scansion.console: Support for indentation in lines() helper
Matthew Wild <mwild1@gmail.com>
parents: 133
diff changeset
4 return table.concat(l, "\n"..string.rep(" ", indent or 0));
115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 end
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local handlers = {
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 ["script"] = function (data)
133
e087dd875160 scansion.console: Handle missing filename
Matthew Wild <mwild1@gmail.com>
parents: 131
diff changeset
9 return "TEST: "..(data.title or data.filename or "untitled");
115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 end;
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 ["test-passed"] = function ()
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 return "PASS";
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 end;
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 ["test-failed"] = function (data)
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local error_text;
146
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
16 if data.reason and data.reason.type == "unexpected-stanza" then
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
17 error_text = "Received unexpected stanza:\n\n"..pretty(data.reason.data.stanza, 4);
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
18 if data.reason.data.expected then
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
19 error_text = error_text.."\n\nExpected:\n\n"..pretty(data.reason.data.expected, 4);
115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 else
146
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
22 error_text = tostring(data.reason);
115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 end
146
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
24 return lines({
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
25 "FAILED: "..data.name;
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
26 "";
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
27 (error_text:gsub("\n", "\n "));
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
28 "";
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
29 }, 4);
115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end;
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 ["test-error"] = function (data)
146
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
32 return lines({
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
33 "ERROR: "..data.name;
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
34 "";
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
35 (tostring(data.reason):gsub("\n", "\n "));
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
36 "";
885fa9f5929d main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents: 145
diff changeset
37 }, 4);
115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end;
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 ["action"] = function (data)
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 local action = data.action;
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 local obj_type = data.object_type;
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 local l = {};
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 if data.annotation then
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 table.insert(l, action.annotation);
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 table.insert(l, data.object.." "..action);
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 if data.extra and obj_type == "client" and (action == "sends" or action == "receives") then
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 table.insert(l, "\n"..pretty(lines(data.extra), 4).."\n");
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 end
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 return lines(l);
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end;
126
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
53
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
54 ["end"] = function (data)
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
55 local r = {};
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
56
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
57 local all_results = {};
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
58 for k, v in pairs(data.summary.all) do
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
59 table.insert(all_results, v);
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
60 end
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
61 table.sort(all_results, function (a, b) return a.name < b.name end);
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
62
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
63 print("");
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
64 print("Summary");
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
65 print("-------");
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
66
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
67 for _, test_result in ipairs(all_results) do
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
68 print("", test_result.status, test_result.name);
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
69 end
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
70
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
71 print("");
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
72
148
e2c85e095a4c scansion.console: Add count of skipped tests
Matthew Wild <mwild1@gmail.com>
parents: 146
diff changeset
73 for _, test_result in ipairs{ "ok", "fail", "error", "skipped", "total" } do
126
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
74 local count = data.summary[test_result] and #data.summary[test_result] or 0;
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
75 table.insert(r, tostring(count).." "..test_result);
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
76 end
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
77 return table.concat(r, " / ");
87ea077acc21 scansion.console: Print summary at end of test run
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
78 end;
115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 };
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80
131
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
81 local quiet_handlers = { "test-failed", "test-error" };
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
82
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
83 local function new(config)
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
84 local h = {};
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
85 if config.quiet then
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
86 for _, handler_name in ipairs(quiet_handlers) do
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
87 h[handler_name] = handlers[handler_name];
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
88 end
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
89 if config.summary then
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
90 h["end"] = handlers["end"];
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
91 end
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
92 else
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
93 h = handlers;
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
94 end
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
95 return h;
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
96 end
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
97
115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 return {
131
2d19fdddb9ee main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents: 126
diff changeset
99 new = new;
115
0f8d0906af6e Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 }

mercurial