Thu, 23 Mar 2023 15:12:30 +0000
Serialize XML in a consistent order by default
This overrides all XML serialization to emit attributes in an ordered form, so
the XML will match across multiple runs. This can be useful for comparing
different runs, or even two stanzas printed in the same run (e.g. if there is
a mismatch).
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; |
124
168cc5aad639
main: Throw scansion error on timeout, to avoid unnecessary traceback
Matthew Wild <mwild1@gmail.com>
parents:
123
diff
changeset
|
8 | local new_error = require "scansion.error".new_error; |
168cc5aad639
main: Throw scansion error on timeout, to avoid unnecessary traceback
Matthew Wild <mwild1@gmail.com>
parents:
123
diff
changeset
|
9 | |
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
|
10 | 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
|
11 | 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
|
12 | local test_metadata = {}; |
67
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
13 | 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
|
14 | local skip_server_startup_log = false; |
137
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
15 | local action_timeout = 10; |
107
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
16 | 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
|
17 | local quiet = false; |
174
662bd8c5ae28
Serialize XML in a consistent order by default
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
18 | local ordered = true; |
131
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
19 | local force_summary = false; |
137
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
20 | local serve_mode = false; |
157
b35dc87ebff0
Make --serve and --serve-port take an origin argument, in order to disallow random websites from accessing the local port
Waqas Hussain <waqas20@gmail.com>
parents:
155
diff
changeset
|
21 | local serve_origin = nil; |
150
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
22 | local only_tags, skip_tags; |
67
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
23 | |
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
|
24 | 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
|
25 | |
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 | 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
|
27 | 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
|
28 | 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
|
29 | 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
|
30 | 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
|
31 | 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
|
32 | 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
|
33 | 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
|
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 | 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
|
36 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
37 | 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
|
38 | 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
|
39 | 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
|
40 | end |
127
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
41 | |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
42 | local files = {}; |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
43 | |
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
|
44 | 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
|
45 | 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
|
46 | 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
|
47 | 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
|
48 | 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
|
49 | 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
|
50 | 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
|
51 | 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
|
52 | 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
|
53 | 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
|
54 | 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
|
55 | 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
|
56 | 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
|
57 | 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
|
58 | 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
|
59 | 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
|
60 | 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
|
61 | 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
|
62 | local new_lines = {}; |
67
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
63 | local last_line_time = time(); |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
64 | 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
|
65 | sleep(0.05); |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
66 | for line in server_log:lines() do |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
67 | table.insert(new_lines, line); |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
68 | last_line_time = time(); |
a2a9dd606200
main: Add delay when reading server logs
Matthew Wild <mwild1@gmail.com>
parents:
65
diff
changeset
|
69 | 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
|
70 | 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
|
71 | 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
|
72 | 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
|
73 | 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
|
74 | 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
|
75 | 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
|
76 | action_timeout = assert(tonumber(get_value()), "number expected for --step-timeout"); |
150
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
77 | elseif opt == "--meta" then |
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
|
78 | 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
|
79 | 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
|
80 | 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
|
81 | 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
|
82 | else |
150
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
83 | error("Unable to parse metadata: "..tag); |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
84 | end |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
85 | elseif opt == "--with-tag" then |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
86 | if not only_tags then |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
87 | only_tags = {}; |
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
|
88 | end |
150
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
89 | local tag = get_value(); |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
90 | local key, value = tag:match("^([^=]+):(.+)$"); |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
91 | table.insert(only_tags, { key or tag, value }); |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
92 | elseif opt == "--skip-tag" then |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
93 | if not skip_tags then |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
94 | skip_tags = {}; |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
95 | end |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
96 | local tag = get_value(); |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
97 | local key, value = tag:match("^([^=]+):(.+)$"); |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
98 | table.insert(skip_tags, { key or tag, value }); |
107
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
99 | 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
|
100 | 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
|
101 | quiet = false; |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
102 | 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
|
103 | verse_log_levels = { "error" }; |
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
104 | quiet = true; |
132
e6df4368029d
main: Add long form of -d: --script-dir
Matthew Wild <mwild1@gmail.com>
parents:
131
diff
changeset
|
105 | elseif opt == "--script-dir" or opt == "-d" then |
127
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
106 | local have_lfs, lfs = pcall(require, "lfs"); |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
107 | if not have_lfs then |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
108 | error("The '-d' parameter requires LuaFileSystem (lfs), please make sure this library is available"); |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
109 | end |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
110 | local path = assert(get_value(), "path expected for '-d'"):gsub("/*$", ""); |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
111 | for f in lfs.dir(path) do |
144
f7e8b865873f
main: Only process .scs files in directories
Matthew Wild <mwild1@gmail.com>
parents:
137
diff
changeset
|
112 | if f:sub(1,1) ~= "." and f:sub(-4) == ".scs" then |
127
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
113 | table.insert(files, path.."/"..f); |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
114 | end |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
115 | end |
131
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
116 | elseif opt == "--summary" then |
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
117 | force_summary = true; |
137
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
118 | elseif opt == "--serve" then |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
119 | serve_mode = 8007; |
157
b35dc87ebff0
Make --serve and --serve-port take an origin argument, in order to disallow random websites from accessing the local port
Waqas Hussain <waqas20@gmail.com>
parents:
155
diff
changeset
|
120 | serve_origin = assert(get_value(), "origin expected for '--serve'"); |
137
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
121 | elseif opt == "--serve-port" then |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
122 | serve_mode = assert(tonumber(get_value()), "expected port number"); |
157
b35dc87ebff0
Make --serve and --serve-port take an origin argument, in order to disallow random websites from accessing the local port
Waqas Hussain <waqas20@gmail.com>
parents:
155
diff
changeset
|
123 | serve_origin = assert(get_value(), "origin expected for '--serve-port'"); |
174
662bd8c5ae28
Serialize XML in a consistent order by default
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
124 | elseif opt == "--unordered" then |
662bd8c5ae28
Serialize XML in a consistent order by default
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
125 | ordered = false; |
58
8fa0a464c727
main.lua: Error on unknown command-line options
Matthew Wild <mwild1@gmail.com>
parents:
57
diff
changeset
|
126 | else |
8fa0a464c727
main.lua: Error on unknown command-line options
Matthew Wild <mwild1@gmail.com>
parents:
57
diff
changeset
|
127 | 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
|
128 | 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
|
129 | end |
127
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
130 | for _, file in ipairs(arg) do |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
131 | table.insert(files, file); |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
132 | end |
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
133 | return files; |
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
|
134 | 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
|
135 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
136 | 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
|
137 | io.input(script_name); |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
138 | return io.read("*a"); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
139 | 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
|
140 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
141 | local function parse_script(data) |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
142 | local parser = require "scansion.parser"; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
143 | return assert(parser.parse(data)); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
144 | 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
|
145 | |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
146 | local function initialize_script(script, context) |
173
14ed4cb241f4
scansion: Support for per-script captures
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
147 | script.captures = {}; |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
148 | local c = 0; |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
149 | for name, object in pairs(script.objects) do --luacheck: ignore name |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
150 | context.line = object.defined_line |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
151 | local o = require("scansion.objects."..object.type); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
152 | object.handler = o; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
153 | 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
|
154 | 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
|
155 | 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
|
156 | 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
|
157 | end |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
158 | o._validate(object); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
159 | c = c + 1; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
160 | end |
123
96b81f84809a
main: Factor out script uninitialization into a function for consistency
Matthew Wild <mwild1@gmail.com>
parents:
117
diff
changeset
|
161 | end |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
162 | |
123
96b81f84809a
main: Factor out script uninitialization into a function for consistency
Matthew Wild <mwild1@gmail.com>
parents:
117
diff
changeset
|
163 | local function uninitialize_script(script) |
134
ce945ba7a754
main: Don't let action timeout fire after a script already finished
Matthew Wild <mwild1@gmail.com>
parents:
132
diff
changeset
|
164 | script.finished = true; |
149
b2e397594cbd
main: Add more luacheck annotations
Matthew Wild <mwild1@gmail.com>
parents:
146
diff
changeset
|
165 | for name, obj in pairs(script.objects) do --luacheck: ignore name |
123
96b81f84809a
main: Factor out script uninitialization into a function for consistency
Matthew Wild <mwild1@gmail.com>
parents:
117
diff
changeset
|
166 | if obj.handler._finish then |
96b81f84809a
main: Factor out script uninitialization into a function for consistency
Matthew Wild <mwild1@gmail.com>
parents:
117
diff
changeset
|
167 | obj.handler._finish(obj); |
96b81f84809a
main: Factor out script uninitialization into a function for consistency
Matthew Wild <mwild1@gmail.com>
parents:
117
diff
changeset
|
168 | end |
96b81f84809a
main: Factor out script uninitialization into a function for consistency
Matthew Wild <mwild1@gmail.com>
parents:
117
diff
changeset
|
169 | end |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
170 | end |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
171 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
172 | local function initialize_verse(errcb) |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
173 | local verse = require "verse"; |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
174 | |
107
65791ba388b9
scansion: Add -q and -v for controlling log output
Matthew Wild <mwild1@gmail.com>
parents:
89
diff
changeset
|
175 | 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
|
176 | |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
177 | 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
|
178 | -- 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
|
179 | 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
|
180 | 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
|
181 | 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
|
182 | end |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
183 | errcb(err); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
184 | end |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
185 | verse.set_error_handler(error_handler); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
186 | 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
|
187 | 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
|
188 | |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
189 | local function main(log_data, script, context) |
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
|
190 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
191 | 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
|
192 | |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
193 | initialize_script(script, context); |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
194 | |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
195 | context.line = nil; |
71
f7dbb46b5770
main.lua: Log script title and summary
Matthew Wild <mwild1@gmail.com>
parents:
69
diff
changeset
|
196 | |
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
|
197 | 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
|
198 | 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
|
199 | 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
|
200 | 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
|
201 | 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
|
202 | 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
|
203 | 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
|
204 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
205 | 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
|
206 | local async = require "scansion.async"; |
7
ecac723bb6e1
main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents:
3
diff
changeset
|
207 | |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
208 | local runner = async.runner(function () |
80
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
209 | for i, action in ipairs(script.actions) do |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
210 | context.line = action.line_start; |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
211 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
212 | local object = script.objects[action.object_name]; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
213 | local handler = object.handler; |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
214 | |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
215 | log_data("action", { |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
216 | action = action.action; |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
217 | object = object.name; |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
218 | object_type = object.type; |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
219 | extra = action.extra; |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
220 | annotation = action.annotation; |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
221 | line_start = action.line_start; |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
222 | line_end = action.line_end; |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
223 | }); |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
224 | |
161
fadae5511044
main: Make undefined actions throw a proper scansion error
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
225 | if not handler[action.action] then |
fadae5511044
main: Make undefined actions throw a proper scansion error
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
226 | local e = new_error("unsupported-action", { |
fadae5511044
main: Make undefined actions throw a proper scansion error
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
227 | text = "Objects of type '"..object.type.."' do not support action '"..action.action.."'"; |
fadae5511044
main: Make undefined actions throw a proper scansion error
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
228 | }); |
fadae5511044
main: Make undefined actions throw a proper scansion error
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
229 | error(e); |
fadae5511044
main: Make undefined actions throw a proper scansion error
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
230 | end |
68
cd63f764d1bf
main.lua: Restructure server log reading
Matthew Wild <mwild1@gmail.com>
parents:
67
diff
changeset
|
231 | if server_log_reader then |
cd63f764d1bf
main.lua: Restructure server log reading
Matthew Wild <mwild1@gmail.com>
parents:
67
diff
changeset
|
232 | log_data("server", { lines = server_log_reader() }); |
cd63f764d1bf
main.lua: Restructure server log reading
Matthew Wild <mwild1@gmail.com>
parents:
67
diff
changeset
|
233 | end |
131
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
234 | |
80
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
235 | if action_timeout and action_timeout > 0 then |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
236 | local action_number = i; |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
237 | verse.add_task(action_timeout, function () |
134
ce945ba7a754
main: Don't let action timeout fire after a script already finished
Matthew Wild <mwild1@gmail.com>
parents:
132
diff
changeset
|
238 | if i == action_number and not script.finished then |
124
168cc5aad639
main: Throw scansion error on timeout, to avoid unnecessary traceback
Matthew Wild <mwild1@gmail.com>
parents:
123
diff
changeset
|
239 | local e = new_error("action-timeout", { text = "Timeout waiting for response" }); |
168cc5aad639
main: Throw scansion error on timeout, to avoid unnecessary traceback
Matthew Wild <mwild1@gmail.com>
parents:
123
diff
changeset
|
240 | error(e); |
80
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
241 | end |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
242 | end); |
6676218cc481
main.lua: Add per-action timeout
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
243 | end |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
244 | do |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
245 | --luacheck: ignore ok err |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
246 | 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
|
247 | if server_log_reader then |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
248 | log_data("server", { lines = server_log_reader() }); |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
249 | end |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
250 | if not ok then |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
251 | log_data("error", { message = err, line = context.line }); |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
252 | error(err); |
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
253 | end |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
254 | end |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
255 | end |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
256 | context.line = nil; |
89
f353cd50c075
main.lua: Add flag for when script has finished
Matthew Wild <mwild1@gmail.com>
parents:
82
diff
changeset
|
257 | script.finished = true; |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
258 | 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
|
259 | verse.quit(); |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
260 | end, { |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
261 | error = function (runner, _err) --luacheck: ignore runner |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
262 | verse.log("error", "Runner caught error: %s", _err); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
263 | ok, err = false, _err; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
264 | verse.quit(); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
265 | end; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
266 | }); |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
267 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
268 | runner:run(true); |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
269 | verse.log("debug", "runner paused") |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
270 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
271 | 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
|
272 | |
0ee626030acb
main.lua: Read any remaining server logs after script completes (error or otherwise)
Matthew Wild <mwild1@gmail.com>
parents:
80
diff
changeset
|
273 | 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
|
274 | 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
|
275 | end |
0ee626030acb
main.lua: Read any remaining server logs after script completes (error or otherwise)
Matthew Wild <mwild1@gmail.com>
parents:
80
diff
changeset
|
276 | |
123
96b81f84809a
main: Factor out script uninitialization into a function for consistency
Matthew Wild <mwild1@gmail.com>
parents:
117
diff
changeset
|
277 | uninitialize_script(script); |
117
fd4025e54f4d
main: Add _finish handler so objects can clean up
Matthew Wild <mwild1@gmail.com>
parents:
115
diff
changeset
|
278 | |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
279 | return ok, err; |
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
280 | end |
7
ecac723bb6e1
main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents:
3
diff
changeset
|
281 | |
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
|
282 | -- Process command-line options |
127
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
283 | local files = process_options(); |
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
|
284 | |
131
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
285 | local console_handlers = require "scansion.console".new({ |
174
662bd8c5ae28
Serialize XML in a consistent order by default
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
286 | ordered = ordered; |
131
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
287 | summary = not(quiet) or force_summary; |
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
288 | quiet = quiet; |
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
289 | }); |
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
290 | |
174
662bd8c5ae28
Serialize XML in a consistent order by default
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
291 | if ordered then |
662bd8c5ae28
Serialize XML in a consistent order by default
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
292 | require "scansion.ordered_serializer".enable(); |
662bd8c5ae28
Serialize XML in a consistent order by default
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
293 | end |
662bd8c5ae28
Serialize XML in a consistent order by default
Matthew Wild <mwild1@gmail.com>
parents:
173
diff
changeset
|
294 | |
115
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
295 | local function console_logger(event, data) |
131
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
296 | local h = console_handlers[event]; |
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
297 | if h then |
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
298 | io.write(h(data), "\n"); |
115
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
299 | end |
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
300 | end |
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
301 | |
3 | 302 | |
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
|
303 | 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
|
304 | 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
|
305 | 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
|
306 | result_log:write("[\n"); |
115
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
307 | end |
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
308 | |
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
309 | local function log_data(type, data) |
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
310 | console_logger(type, data); |
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
311 | |
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
312 | if result_log then |
61
21871fb2db99
main: Switch to socket.gettime for higher accuracy timestamps in machine-readable logs
Matthew Wild <mwild1@gmail.com>
parents:
59
diff
changeset
|
313 | local entry = { type = type, data = data, time = time() }; |
125
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
314 | result_log:write(" ", json.encode(entry), type ~= "end" and ",\n" or "\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
|
315 | result_log:flush(); |
125
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
316 | if type == "end" then |
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
317 | result_log:write("]\n"); |
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
318 | result_log:close(); |
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
319 | result_log = nil; |
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
320 | 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
|
321 | end |
115
0f8d0906af6e
Revamp console output to be driven by log_data()
Matthew Wild <mwild1@gmail.com>
parents:
114
diff
changeset
|
322 | 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
|
323 | |
155
84aa28dda508
main: Pass logging function to run_test_script
Matthew Wild <mwild1@gmail.com>
parents:
154
diff
changeset
|
324 | local function run_test_script(script_name, script_text, log_data) |
136
2df38fd36b2b
main: Modify run_test_script() to take the actual script data
Matthew Wild <mwild1@gmail.com>
parents:
135
diff
changeset
|
325 | local script = parse_script(script_text) |
146
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
326 | local script_data = { title = script.title, summary = script.summary, tags = script.tags, filename = script_name }; |
150
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
327 | |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
328 | local tags = script.tags or {}; |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
329 | if skip_tags then |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
330 | for _, skip in ipairs(skip_tags) do |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
331 | local k, v = skip[1], skip[2]; |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
332 | if tags[k] and (not(v) or tags[k] == v) then |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
333 | return { name = script.title or script.name, status = "skipped", reason = "skipping tag "..k }; |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
334 | end |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
335 | end |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
336 | end |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
337 | if only_tags then |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
338 | for _, only in ipairs(only_tags) do |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
339 | local k, v = only[1], only[2]; |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
340 | if not tags[k] or (v and tags[k] ~= v) then |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
341 | return { name = script.title or script.name, status = "skipped", reason = "not tagged "..k }; |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
342 | end |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
343 | end |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
344 | end |
cf2b2fcd0bc1
main: Add support for including/excluding tests based on tag
Matthew Wild <mwild1@gmail.com>
parents:
149
diff
changeset
|
345 | |
146
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
346 | log_data("script", script_data); |
109
f7609d1a5bdf
main.lua: Some fixes for [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
108
diff
changeset
|
347 | |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
348 | local context = { line = nil }; |
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
349 | local ok, result, err = pcall(main, log_data, script, context); |
125
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
350 | |
146
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
351 | local event, status, reason; |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
352 | if not ok then |
146
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
353 | event, status, reason = "test-error", "error", result; |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
354 | elseif not result then |
146
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
355 | event, status, reason = "test-failed", "fail", err; |
131
2d19fdddb9ee
main, console: Allow force-printing --summary even if -q is passed
Matthew Wild <mwild1@gmail.com>
parents:
129
diff
changeset
|
356 | else |
146
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
357 | event, status, reason = "test-passed", "ok", nil; |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
358 | end |
146
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
359 | |
162
f888f236321f
Make current line number available in all error events
Waqas Hussain <waqas20@gmail.com>
parents:
161
diff
changeset
|
360 | local result_data = { name = script.title or script_name, status = status, reason = reason, line = context.line }; |
146
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
361 | |
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
362 | log_data(event, result_data); |
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
363 | |
885fa9f5929d
main, scansion.console: Refactor (changes event data format) so that test results include test name
Matthew Wild <mwild1@gmail.com>
parents:
144
diff
changeset
|
364 | return result_data; |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
365 | 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
|
366 | |
137
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
367 | |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
368 | if serve_mode then |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
369 | local have_serve, serve = pcall(require, "scansion.serve"); |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
370 | |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
371 | if not have_serve then |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
372 | error("This version of scansion was not built with --with-server"); |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
373 | end |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
374 | |
149
b2e397594cbd
main: Add more luacheck annotations
Matthew Wild <mwild1@gmail.com>
parents:
146
diff
changeset
|
375 | initialize_verse(function (e) --luacheck: ignore e |
137
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
376 | -- This function handles scansion errors, |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
377 | -- but they shouldn't reach here anyway |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
378 | end); |
157
b35dc87ebff0
Make --serve and --serve-port take an origin argument, in order to disallow random websites from accessing the local port
Waqas Hussain <waqas20@gmail.com>
parents:
155
diff
changeset
|
379 | serve.run({ port = serve_mode, origin = serve_origin }, run_test_script); |
137
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
380 | os.exit(0); |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
381 | end |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
382 | |
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
|
383 | 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
|
384 | |
125
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
385 | local result_tally = { all = {} }; |
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
386 | |
135
0c1887ee2059
main: Move check for whether any files have been provided
Matthew Wild <mwild1@gmail.com>
parents:
134
diff
changeset
|
387 | assert(#files > 0, "No test script provided"); |
127
df5aa6a12561
main: Add support for passing one or more script directories with '-d'
Matthew Wild <mwild1@gmail.com>
parents:
125
diff
changeset
|
388 | for i = 1, #files do |
136
2df38fd36b2b
main: Modify run_test_script() to take the actual script data
Matthew Wild <mwild1@gmail.com>
parents:
135
diff
changeset
|
389 | local script_text = read_script(files[i]); |
155
84aa28dda508
main: Pass logging function to run_test_script
Matthew Wild <mwild1@gmail.com>
parents:
154
diff
changeset
|
390 | local ret = run_test_script(files[i], script_text, log_data); |
125
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
391 | if not result_tally[ret.status] then |
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
392 | result_tally[ret.status] = {}; |
108
cd58c64c67c0
scansion: Add support for passing multiple scripts on the command-line
Matthew Wild <mwild1@gmail.com>
parents:
107
diff
changeset
|
393 | end |
125
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
394 | table.insert(result_tally[ret.status], ret); |
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
395 | table.insert(result_tally.all, ret); |
21
8ac80da35408
main: Refactor into functions
Matthew Wild <mwild1@gmail.com>
parents:
14
diff
changeset
|
396 | 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
|
397 | |
125
dfff8dfe8861
main: Refactor to support a more advanced summary at the end of a test run
Matthew Wild <mwild1@gmail.com>
parents:
124
diff
changeset
|
398 | log_data("end", { time = time(), summary = result_tally }); |
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
|
399 | |
137
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
400 | |
129
ff11f32d2499
main: Fix to restore correct exit code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
401 | local exit_code = 0; |
ff11f32d2499
main: Fix to restore correct exit code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
402 | if result_tally.error then |
ff11f32d2499
main: Fix to restore correct exit code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
403 | exit_code = 2; |
ff11f32d2499
main: Fix to restore correct exit code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
404 | elseif result_tally.fail then |
ff11f32d2499
main: Fix to restore correct exit code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
405 | exit_code = 1; |
ff11f32d2499
main: Fix to restore correct exit code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
406 | end |
ff11f32d2499
main: Fix to restore correct exit code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
407 | |
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
|
408 | os.exit(exit_code); |
137
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
409 | |
091212cef52a
main, scansion.serve: Add mode that serves /run API for executing scripts
Matthew Wild <mwild1@gmail.com>
parents:
136
diff
changeset
|
410 |