2 |
2 |
3 local json = require "cjson"; |
3 local json = require "cjson"; |
4 local time = require "socket".gettime; |
4 local time = require "socket".gettime; |
5 |
5 |
6 local result_log_filename = nil; |
6 local result_log_filename = nil; |
|
7 local server_log_reader = nil; |
7 local property_rules = {}; |
8 local property_rules = {}; |
8 |
9 |
9 local function apply_object_properties(class, name, object) |
10 local function apply_object_properties(class, name, object) |
10 for _, rule in ipairs(property_rules) do |
11 for _, rule in ipairs(property_rules) do |
11 if (not(rule.class) or tostring(rule.class):lower() == tostring(class):lower()) |
12 if (not(rule.class) or tostring(rule.class):lower() == tostring(class):lower()) |
34 elseif opt == "--host" or opt == "-h" then |
35 elseif opt == "--host" or opt == "-h" then |
35 local host = get_value(); |
36 local host = get_value(); |
36 table.insert(property_rules, { class = "client", properties = { connect_host = host } }); |
37 table.insert(property_rules, { class = "client", properties = { connect_host = host } }); |
37 elseif opt == "--out" or opt == "-o" then |
38 elseif opt == "--out" or opt == "-o" then |
38 result_log_filename = get_value(); |
39 result_log_filename = get_value(); |
|
40 elseif opt == "--server-log" or opt == "-s" then |
|
41 local server_log = assert(io.open(get_value(), "r")); |
|
42 function server_log_reader() |
|
43 local new_lines = {}; |
|
44 for line in server_log:lines() do |
|
45 table.insert(new_lines, line); |
|
46 end |
|
47 return new_lines; |
|
48 end |
39 else |
49 else |
40 error("Unhandled command-line option: "..opt); |
50 error("Unhandled command-line option: "..opt); |
41 end |
51 end |
42 end |
52 end |
43 assert(#arg > 0, "No test script provided"); |
53 assert(#arg > 0, "No test script provided"); |
88 |
98 |
89 local ok, err = true; |
99 local ok, err = true; |
90 |
100 |
91 local script = initialize_script(parse_script(read_script())); |
101 local script = initialize_script(parse_script(read_script())); |
92 |
102 |
|
103 if server_log_reader then |
|
104 log_data("server", { lines = server_log_reader() }); |
|
105 end |
|
106 |
93 local verse = initialize_verse(function (_err) ok, err = false, _err end); |
107 local verse = initialize_verse(function (_err) ok, err = false, _err end); |
94 local async = require "scansion.async"; |
108 local async = require "scansion.async"; |
95 |
109 |
96 local runner = async.runner(function (d) |
110 local runner = async.runner(function (d) |
97 for _, action in pairs(script.actions) do |
111 for _, action in pairs(script.actions) do |
106 extra = action.extra; |
120 extra = action.extra; |
107 annotation = action.annotation; |
121 annotation = action.annotation; |
108 }); |
122 }); |
109 if action.annotation then |
123 if action.annotation then |
110 print(action.annotation); |
124 print(action.annotation); |
|
125 end |
|
126 if server_log_reader then |
|
127 log_data("server", { lines = server_log_reader() }); |
111 end |
128 end |
112 print(object.name, action.action.."..."); |
129 print(object.name, action.action.."..."); |
113 local ok, err = pcall(handler[action.action], object, action.extra); |
130 local ok, err = pcall(handler[action.action], object, action.extra); |
114 if not ok then |
131 if not ok then |
115 log_data("error", { message = err }); |
132 log_data("error", { message = err }); |