Mon, 10 Sep 2018 13:48:25 +0100
main: Move 'start' event to correct place (signals start of test run, not individual tests)
54 | 1 | #!/usr/bin/env luajit |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
2 | |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
3 | local json = require "cjson"; |
61
21871fb2db99
main: Switch to socket.gettime for higher accuracy timestamps in machine-readable logs
Matthew Wild <mwild1@gmail.com>
parents:
59
diff
changeset
|
4 | local time = require "socket".gettime; |
67
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
5 | local sleep = require "socket".sleep; |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
6 | |
110
d58403c8615e
main.lua: Don't log traceback for normal scansion internal errors
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
7 | local is_scansion_error = require "scansion.error".is; |
d58403c8615e
main.lua: Don't log traceback for normal scansion internal errors
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
8 | |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
9 | local result_log_filename = nil; |
62
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
10 | local server_log_reader = nil; |
69
1de0ebd8832f
main.lua: Support tagging metadata for test runs, and include it in JSON output
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
11 | local test_metadata = {}; |
67
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
12 | local server_log_wait_time = 0.2; |
76
fecc1af937be
main.lua: Add --skip-server-startup-log to discard server log output at startup
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
13 | local skip_server_startup_log = false; |
82
f90056b8e278
main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents:
81
diff
changeset
|
14 | local action_timeout = 5; |
107
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
15 | local verse_log_levels = { "warn", "error" }; |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
16 | local quiet = false; |
67
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
17 | |
56
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
18 | local property_rules = {}; |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
19 | |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
20 | local function apply_object_properties(class, name, object) |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
21 | for _, rule in ipairs(property_rules) do |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
22 | if (not(rule.class) or tostring(rule.class):lower() == tostring(class):lower()) |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
23 | and (not(rule.name) or tostring(rule.name):lower() == tostring(name):lower()) then |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
24 | for prop_key, prop_value in pairs(rule.properties) do |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
25 | object[prop_key] = prop_value; |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
26 | end |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
27 | end |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
28 | end |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
29 | end |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
30 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
31 | local function process_options() |
56
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
32 | local function get_value() |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
33 | return (assert(table.remove(arg, 1), "unexpected end of command-line options")); |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
34 | end |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
35 | while arg[1] and arg[1]:sub(1,1) == "-" do |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
36 | local opt = arg[1]; |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
37 | if opt == "--" then |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
38 | table.remove(arg, 1); |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
39 | break; |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
40 | end |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
41 | table.remove(arg, 1); |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
42 | if opt == "--port" or opt == "-p" then |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
43 | local port = assert(tonumber(get_value()), "port number must be a number"); |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
44 | table.insert(property_rules, { class = "client", properties = { connect_port = port } }); |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
45 | elseif opt == "--host" or opt == "-h" then |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
46 | local host = get_value(); |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
47 | table.insert(property_rules, { class = "client", properties = { connect_host = host } }); |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
48 | elseif opt == "--out" or opt == "-o" then |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
49 | result_log_filename = get_value(); |
62
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
50 | elseif opt == "--server-log" or opt == "-s" then |
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
51 | local server_log = assert(io.open(get_value(), "r")); |
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
52 | function server_log_reader() |
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
53 | local new_lines = {}; |
67
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
54 | local last_line_time = time(); |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
55 | while time() - last_line_time < server_log_wait_time do |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
56 | sleep(0.05); |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
57 | for line in server_log:lines() do |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
58 | table.insert(new_lines, line); |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
59 | last_line_time = time(); |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
60 | end |
62
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
61 | end |
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
62 | return new_lines; |
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
63 | end |
76
fecc1af937be
main.lua: Add --skip-server-startup-log to discard server log output at startup
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
64 | elseif opt == "--skip-server-startup-log" then |
fecc1af937be
main.lua: Add --skip-server-startup-log to discard server log output at startup
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
65 | skip_server_startup_log = true; |
82
f90056b8e278
main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents:
81
diff
changeset
|
66 | elseif opt == "--step-timeout" then |
f90056b8e278
main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents:
81
diff
changeset
|
67 | action_timeout = assert(tonumber(get_value()), "number expected for --step-timeout"); |
69
1de0ebd8832f
main.lua: Support tagging metadata for test runs, and include it in JSON output
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
68 | elseif opt == "--tag" then |
1de0ebd8832f
main.lua: Support tagging metadata for test runs, and include it in JSON output
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
69 | local tag = get_value(); |
1de0ebd8832f
main.lua: Support tagging metadata for test runs, and include it in JSON output
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
70 | local key, value = tag:match("^([^=]+):(.+)$"); |
1de0ebd8832f
main.lua: Support tagging metadata for test runs, and include it in JSON output
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
71 | if key and value then |
1de0ebd8832f
main.lua: Support tagging metadata for test runs, and include it in JSON output
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
72 | test_metadata[key] = value; |
1de0ebd8832f
main.lua: Support tagging metadata for test runs, and include it in JSON output
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
73 | else |
1de0ebd8832f
main.lua: Support tagging metadata for test runs, and include it in JSON output
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
74 | error("Unable to parse tag: "..tag); |
1de0ebd8832f
main.lua: Support tagging metadata for test runs, and include it in JSON output
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
75 | end |
107
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
76 | elseif opt == "--verbose" or opt == "-v" then |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
77 | verse_log_levels = { "debug", "info", "warn", "error" }; |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
78 | quiet = false; |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
79 | elseif opt == "--quiet" or opt == "-q" then |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
80 | verse_log_levels = { "error" }; |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
81 | quiet = true; |
58
8fa0a464c727
main.lua: Error on unknown command-line options
Matthew Wild <mwild1@gmail.com>
parents:
57
diff
changeset
|
82 | else |
8fa0a464c727
main.lua: Error on unknown command-line options
Matthew Wild <mwild1@gmail.com>
parents:
57
diff
changeset
|
83 | error("Unhandled command-line option: "..opt); |
56
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
84 | end |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
85 | end |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
86 | assert(#arg > 0, "No test script provided"); |
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
87 | end |
0
2e31b584f8d9
It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
89 | local function read_script(script_name) |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
90 | io.input(script_name); |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
91 | return io.read("*a"); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
92 | end |
0
2e31b584f8d9
It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
94 | local function parse_script(data) |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
95 | local parser = require "scansion.parser"; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
96 | return assert(parser.parse(data)); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
97 | end |
0
2e31b584f8d9
It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
99 | local function initialize_script(script) |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
100 | local c = 0; |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
101 | for name, object in pairs(script.objects) do --luacheck: ignore name |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
102 | local o = require("scansion.objects."..object.type); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
103 | object.handler = o; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
104 | object.script = script; |
56
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
105 | apply_object_properties(object.type, object.name, object); |
82
f90056b8e278
main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents:
81
diff
changeset
|
106 | if object.type == "client" and not object.stanza_timeout then |
f90056b8e278
main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents:
81
diff
changeset
|
107 | object.stanza_timeout = action_timeout - 1; |
f90056b8e278
main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents:
81
diff
changeset
|
108 | end |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
109 | o._validate(object); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
110 | c = c + 1; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
111 | end |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
112 | |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
113 | --print("Script defines "..c.." objects, and "..#script.actions.." actions"); |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
114 | return script; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
115 | end |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
116 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
117 | local function initialize_verse(errcb) |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
118 | local verse = require "verse"; |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
119 | |
107
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
120 | verse.set_log_handler(verse._default_log_handler, verse_log_levels); |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
121 | |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
122 | local function error_handler(err) |
110
d58403c8615e
main.lua: Don't log traceback for normal scansion internal errors
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
123 | -- Only log actual errors. Those reported by Scansion will be handled gracefully higher up. |
d58403c8615e
main.lua: Don't log traceback for normal scansion internal errors
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
124 | if not is_scansion_error(err) then |
d58403c8615e
main.lua: Don't log traceback for normal scansion internal errors
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
125 | verse.log("error", "Error: %s", err); |
d58403c8615e
main.lua: Don't log traceback for normal scansion internal errors
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
126 | verse.log("error", "Traceback: %s", debug.traceback()); |
d58403c8615e
main.lua: Don't log traceback for normal scansion internal errors
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
127 | end |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
128 | errcb(err); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
129 | end |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
130 | verse.set_error_handler(error_handler); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
131 | return verse; |
0
2e31b584f8d9
It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 | end |
2e31b584f8d9
It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
134 | local function main(log_data, script_name) |
56
5eda634ea15b
main.lua: Command-line processing, and a way to set connect_host/connect_port from the command-line
Matthew Wild <mwild1@gmail.com>
parents:
55
diff
changeset
|
135 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
136 | local ok, err = true; |
0
2e31b584f8d9
It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 | |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
138 | local script = initialize_script(parse_script(read_script(script_name))); |
71
f7dbb46b5770
main.lua: Log script title and summary
Matthew Wild <mwild1@gmail.com>
parents:
69
diff
changeset
|
139 | |
113
f5c1ccc58b48
main: Include script filename in "script" log event
Matthew Wild <mwild1@gmail.com>
parents:
110
diff
changeset
|
140 | log_data("script", { title = script.title, summary = script.summary, tags = script.tags, filename = script_name }); |
71
f7dbb46b5770
main.lua: Log script title and summary
Matthew Wild <mwild1@gmail.com>
parents:
69
diff
changeset
|
141 | |
62
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
142 | if server_log_reader then |
76
fecc1af937be
main.lua: Add --skip-server-startup-log to discard server log output at startup
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
143 | if skip_server_startup_log then |
fecc1af937be
main.lua: Add --skip-server-startup-log to discard server log output at startup
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
144 | server_log_reader(); |
fecc1af937be
main.lua: Add --skip-server-startup-log to discard server log output at startup
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
145 | else |
fecc1af937be
main.lua: Add --skip-server-startup-log to discard server log output at startup
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
146 | log_data("server", { lines = server_log_reader() }); |
fecc1af937be
main.lua: Add --skip-server-startup-log to discard server log output at startup
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
147 | end |
62
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
148 | end |
52a24deb0cc3
main: Support for --server-log/-s option, which reads the server's log file during a test and includes it in the JSON log
Matthew Wild <mwild1@gmail.com>
parents:
61
diff
changeset
|
149 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
150 | local verse = initialize_verse(function (_err) ok, err = false, _err end); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
151 | local async = require "scansion.async"; |
7
ecac723bb6e1
main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents:
3
diff
changeset
|
152 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
153 | local runner = async.runner(function () |
80
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
154 | for i, action in ipairs(script.actions) do |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
155 | local object = script.objects[action.object_name]; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
156 | local handler = object.handler; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
157 | assert(handler[action.action], "Objects of type '"..object.type.."' do not support action '"..action.action.."'"); |
107
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
158 | if not quiet then |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
159 | print(""); |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
160 | end |
68
cd63f764d1bf
main.lua: Restructure server log reading
Matthew Wild <mwild1@gmail.com>
parents:
67
diff
changeset
|
161 | if server_log_reader then |
cd63f764d1bf
main.lua: Restructure server log reading
Matthew Wild <mwild1@gmail.com>
parents:
67
diff
changeset
|
162 | log_data("server", { lines = server_log_reader() }); |
cd63f764d1bf
main.lua: Restructure server log reading
Matthew Wild <mwild1@gmail.com>
parents:
67
diff
changeset
|
163 | end |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
164 | log_data("action", { |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
165 | action = action.action; |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
166 | object = object.name; |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
167 | object_type = object.type; |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
168 | extra = action.extra; |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
169 | annotation = action.annotation; |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
170 | }); |
107
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
171 | if not quiet then |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
172 | if action.annotation then |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
173 | print(action.annotation); |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
174 | end |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
175 | print(object.name.." "..action.action); |
43
b37504fa3031
Add annotations to actions (by grabbing the preceding comment)
Matthew Wild <mwild1@gmail.com>
parents:
30
diff
changeset
|
176 | end |
80
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
177 | if action_timeout and action_timeout > 0 then |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
178 | local action_number = i; |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
179 | verse.add_task(action_timeout, function () |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
180 | if i == action_number then |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
181 | error("Timeout waiting for response from server"); |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
182 | end |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
183 | end); |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
184 | end |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
185 | do |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
186 | --luacheck: ignore ok err |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
187 | local ok, err = pcall(handler[action.action], object, action.extra); |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
188 | if server_log_reader then |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
189 | log_data("server", { lines = server_log_reader() }); |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
190 | end |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
191 | if not ok then |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
192 | log_data("error", { message = err }); |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
193 | error(err); |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
194 | end |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
195 | end |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
196 | end |
89
f353cd50c075
main.lua: Add flag for when script has finished
Matthew Wild <mwild1@gmail.com>
parents:
82
diff
changeset
|
197 | script.finished = true; |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
198 | verse.log("info", "Completed script!"); |
30
3c2489e79074
main: Remove 5s delay on quitting (was a hack for debug purposes)
Matthew Wild <mwild1@gmail.com>
parents:
21
diff
changeset
|
199 | verse.quit(); |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
200 | end, { |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
201 | error = function (runner, _err) --luacheck: ignore runner |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
202 | verse.log("error", "Runner caught error: %s", _err); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
203 | ok, err = false, _err; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
204 | verse.quit(); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
205 | end; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
206 | }); |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
207 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
208 | runner:run(true); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
209 | verse.log("debug", "runner paused") |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
210 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
211 | verse.loop(); |
81
0ee626030acb
main.lua: Read any remaining server logs after script completes (error or otherwise)
Matthew Wild <mwild1@gmail.com>
parents:
80
diff
changeset
|
212 | |
0ee626030acb
main.lua: Read any remaining server logs after script completes (error or otherwise)
Matthew Wild <mwild1@gmail.com>
parents:
80
diff
changeset
|
213 | if server_log_reader then |
0ee626030acb
main.lua: Read any remaining server logs after script completes (error or otherwise)
Matthew Wild <mwild1@gmail.com>
parents:
80
diff
changeset
|
214 | log_data("server", { lines = server_log_reader() }); |
0ee626030acb
main.lua: Read any remaining server logs after script completes (error or otherwise)
Matthew Wild <mwild1@gmail.com>
parents:
80
diff
changeset
|
215 | end |
0ee626030acb
main.lua: Read any remaining server logs after script completes (error or otherwise)
Matthew Wild <mwild1@gmail.com>
parents:
80
diff
changeset
|
216 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
217 | return ok, err; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
218 | end |
7
ecac723bb6e1
main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents:
3
diff
changeset
|
219 | |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
220 | -- Process command-line options |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
221 | process_options(); |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
222 | |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
223 | -- Dummy logging function, used if no log file set |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
224 | local log_data = function () end; |
3 | 225 | |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
226 | local result_log; |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
227 | if result_log_filename then |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
228 | result_log = assert(io.open(result_log_filename, "w+")); |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
229 | result_log:write("[\n"); |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
230 | function log_data(type, data) |
61
21871fb2db99
main: Switch to socket.gettime for higher accuracy timestamps in machine-readable logs
Matthew Wild <mwild1@gmail.com>
parents:
59
diff
changeset
|
231 | local entry = { type = type, data = data, time = time() }; |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
232 | result_log:write(" ", json.encode(entry), ",\n"); |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
233 | result_log:flush(); |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
234 | end |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
235 | end |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
236 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
237 | local function run_test_script(script_name) |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
238 | |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
239 | local ok, result, err = pcall(main, log_data, script_name); |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
240 | |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
241 | local exit_code = 0; |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
242 | if not ok then |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
243 | print("TEST ERROR:", result); |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
244 | exit_code = 2; |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
245 | log_data("test-error", { error = result }); |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
246 | elseif not result then |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
247 | print("TEST FAILED", err); |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
248 | exit_code = 1; |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
249 | log_data("test-failed", { error = err }); |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
250 | elseif not quiet then |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
251 | print("TEST PASSED"); |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
252 | log_data("test-passed"); |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
253 | end |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
254 | return exit_code; |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
255 | end |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
256 | |
114
48aab6c9e9d3
main: Move 'start' event to correct place (signals start of test run, not individual tests)
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
257 | log_data("start", { metadata = test_metadata }); |
48aab6c9e9d3
main: Move 'start' event to correct place (signals start of test run, not individual tests)
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
258 | |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
259 | local exit_code = 0; |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
260 | for i = 1, #arg do |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
261 | local ret = run_test_script(arg[i]); |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
262 | if ret > exit_code then |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
263 | exit_code = ret; |
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
264 | end |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
265 | end |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
266 | |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
267 | if result_log then |
63
0f19ffbe1519
main: Separate logging for the last event to ensure proper JSON syntax
Matthew Wild <mwild1@gmail.com>
parents:
62
diff
changeset
|
268 | result_log:write([[ {"type": "end", "time": ]]..time().."}\n]\n"); |
57
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
269 | result_log:close(); |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
270 | end |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
271 | |
6407a0157518
main.lua: Add support for JSON log output to a file, for a machine-readable transcript of the test results
Matthew Wild <mwild1@gmail.com>
parents:
56
diff
changeset
|
272 | os.exit(exit_code); |