Module: MessageHandler
- Included in:
- TestScriptEngine, TestScriptRunnable
- Defined in:
- lib/testscript_engine/message_handler.rb
Instance Attribute Summary collapse
-
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
-
#modify_report ⇒ Object
Returns the value of attribute modify_report.
Instance Method Summary collapse
- #begin_symbol ⇒ Object
- #cascade_skips(message_type, actions, *options) ⇒ Object
-
#client(*args) ⇒ Object
< —- TO REVIEW —- >.
- #decrease_space ⇒ Object
- #error(message_type, *options) ⇒ Object
- #fail(message_type, *options) ⇒ Object
- #finish_symbol ⇒ Object
- #increase_space ⇒ Object
- #info(message_type, *options) ⇒ Object
- #load_fixtures ⇒ Object
- #load_scripts ⇒ Object
- #logger_formatter_with_spacing ⇒ Object
- #logger_formatters_with_spacing ⇒ Object
- #make_runnables ⇒ Object
- #messages(message, *options) ⇒ Object
- #newline ⇒ Object
- #outcome_symbol(outcome) ⇒ Object
- #pass(message_type, *options) ⇒ Object
- #postprocessing ⇒ Object
- #preprocess ⇒ Object
- #print_action_header(action_type) ⇒ Object
- #print_out(message) ⇒ Object
- #run(*args) ⇒ Object
- #setup ⇒ Object
- #skip(message_type, *options) ⇒ Object
- #space ⇒ Object
- #teardown ⇒ Object
- #test ⇒ Object
- #unit_of_space ⇒ Object
- #warning(message_type, *options) ⇒ Object
Instance Attribute Details
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
2 3 4 |
# File 'lib/testscript_engine/message_handler.rb', line 2 def debug_mode @debug_mode end |
#modify_report ⇒ Object
Returns the value of attribute modify_report.
2 3 4 |
# File 'lib/testscript_engine/message_handler.rb', line 2 def modify_report @modify_report end |
Instance Method Details
#begin_symbol ⇒ Object
200 201 202 |
# File 'lib/testscript_engine/message_handler.rb', line 200 def begin_symbol [10551].pack("U*") end |
#cascade_skips(message_type, actions, *options) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/testscript_engine/message_handler.rb', line 45 def cascade_skips(, actions, *) print_out "#{outcome_symbol("SKIP")} #{(, *)}" increase_space counter = 0 while counter < actions.length action = actions[counter] if action.operation id = "Operation: [#{(action.operation.id || action.operation.label || 'unlabeled')}]" else id = "Assert: [#{(action.assert.id || action.assert.label || 'unlabeled')}]" if action.assert end skip(:eval_assert_result, "#{id} skipped.") counter += 1 end decrease_space end |
#client(*args) ⇒ Object
< —- TO REVIEW —- >
155 156 157 158 159 |
# File 'lib/testscript_engine/message_handler.rb', line 155 def client(*args) client = super FHIR.logger.formatter = logger_formatter_with_spacing client end |
#decrease_space ⇒ Object
16 17 18 |
# File 'lib/testscript_engine/message_handler.rb', line 16 def decrease_space @space.chomp!(unit_of_space) end |
#error(message_type, *options) ⇒ Object
141 142 143 144 145 |
# File 'lib/testscript_engine/message_handler.rb', line 141 def error(, *) = (, *) super() if modify_report print_out "#{outcome_symbol("ERROR")} #{}" end |
#fail(message_type, *options) ⇒ Object
123 124 125 126 127 |
# File 'lib/testscript_engine/message_handler.rb', line 123 def fail(, *) = (, *) super() if modify_report print_out "#{outcome_symbol("FAIL")} #{}" end |
#finish_symbol ⇒ Object
204 205 206 |
# File 'lib/testscript_engine/message_handler.rb', line 204 def finish_symbol [024465].pack("U*") end |
#increase_space ⇒ Object
12 13 14 |
# File 'lib/testscript_engine/message_handler.rb', line 12 def increase_space space << unit_of_space end |
#info(message_type, *options) ⇒ Object
41 42 43 |
# File 'lib/testscript_engine/message_handler.rb', line 41 def info(, *) print_out (, *) end |
#load_fixtures ⇒ Object
111 112 113 114 115 |
# File 'lib/testscript_engine/message_handler.rb', line 111 def load_fixtures increase_space super decrease_space end |
#load_scripts ⇒ Object
62 63 64 65 66 |
# File 'lib/testscript_engine/message_handler.rb', line 62 def load_scripts print_out (:begin_loading_scripts, testscript_path) super print_out (:finish_loading_scripts) end |
#logger_formatter_with_spacing ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/testscript_engine/message_handler.rb', line 165 def logger_formatter_with_spacing logger_formatters_with_spacing[space.length] || begin new_logger_formatter = proc do |severity, datetime, progname, msg| "#{space}#{unit_of_space}#{msg}\n" end logger_formatters_with_spacing[space.length] = new_logger_formatter new_logger_formatter end end |
#logger_formatters_with_spacing ⇒ Object
161 162 163 |
# File 'lib/testscript_engine/message_handler.rb', line 161 def logger_formatters_with_spacing @logger_formatters_with_spacing ||= {} end |
#make_runnables ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/testscript_engine/message_handler.rb', line 68 def make_runnables print_out (:begin_creating_runnables) increase_space super decrease_space print_out (:finish_creating_runnables) end |
#messages(message, *options) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/testscript_engine/message_handler.rb', line 208 def (, *) = case when :abort_test "Due to an unsuccessful action in the [#{[0]}] phase, remaining actions in this test will be skipped. Skipping the next #{[1]} action(s)." when :bad_script "Given non-TestScript resource. Can not create runnable." when :bad_serialized_script "Can not deserialize resource into TestScript: [#{[0]}]." when :begin_initialize_client ("INITIALIZE CLIENT") when :begin_creating_runnables ("MAKE RUNNABLE(S)") when :created_runnable "Created runnable from TestScript: [#{[0]}]." when :finish_creating_runnables ("MAKING RUNNABLE(S)") when :finish_initialize_client ("INITIALIZING CLIENT") when :invalid_script "Can not load TestScript. Invalid resource: [#{[0]}]." when :invalid_script "Given invalid TestScript resource. Can not create runnable." when :loaded_script "Loaded TestScript: [#{[0]}]." when :loaded_static_fixture "Loaded static fixture [#{[0]}]." when :no_postprocess "Nothing to postprocess." when :no_preprocess "Nothing to preprocess." when :no_setup "Nothing to setup." when :no_teardown "Nothing to teardown." when :overwrite_existing_script "Overwriting previously loaded TestScript: [#{[0]}]." when :skip_on_fail "Due to the preceeding unsuccessful action, skipping the next #{[0]} action(s)." when :unable_to_create_runnable "Can not create runnable from TestScript: [#{[0]}]." when :unable_to_locate_runnable "Can not locate runnable with id: [#{[0]}]. Can not execute." when :assertion_error "ERROR: Unable to process assertion: #{[0]}" when :assertion_exception "#{[0]}" when :bad_reference "Unable to read contents of reference: [#{[0]}]. No reference extracted." when :bad_request "Unable to create a request from operation." when :bad_static_fixture_reference "Static fixture included unresolvable reference. Can not load fixture. Moving on." when :begin_loading_scripts ("LOAD TESTSCRIPTS", [0]) when :begin_preprocess ("PREPROCESS", [0]) when :begin_runnable_execution ("EXECUTE RUNNABLE", [0]) when :begin_setup ("SETUP") when :begin_teardown ("TEARDOWN") when :begin_test ("TEST") when :eval_assert_result "#{[0]}" when :evaluate_assert "EVALUATING ASSERTION" when :execute_operation "OPERATION EXECUTION" when :execute_operation_error "Unable to execute operation. ERROR: [#{[0]}]. [#{[1]}]" when :finish_loading_scripts ("LOADING SCRIPTS") when :finish_preprocess ("PREPROCESS") when :finish_runnable_execution ("EXECUTING RUNNABLE. FINAL EXECUTION SCORE: [#{testreport.score}]") when :finish_setup ("SETUP") when :finish_teardown ("TEARDOWN") when :finish_test ("TEST") when :invalid_assert "Invalid assert. Can not evaluate." when :invalid_dump "Validation error: [#{[0]}]" when :invalid_operation "Invalid operation. Can not execute." when :invalid_request "Unable to create a request using operation: [#{[0]}]. Can not execute." when :no_contained_resource "Reference [#{[0]}] refers to a contained resource that does not exist. Moving on." when :no_path "Unable to extract path from operation." when :no_reference "Reference element of reference object is nil. Can not get resource from reference." when :no_static_fixture_id "No ID for static fixture. Can not load." when :no_static_fixture_reference "No reference for static fixture. Can not load." when :no_static_fixture_resource "No resource for static fixture. Can not load." when :pass_execute_operation "Executed Operation: [#{[0]}]" when :resource_extraction "Unable to extract resource referenced by [#{[0]}]. Encountered: [#{[1]}]." when :uncaught_error "Uncaught error: [#{[0]}]." when :unsupported_ref "Remote reference: [#{[0]}] not supported. No reference extracted." else "! unknown message type !" end end |
#newline ⇒ Object
20 21 22 |
# File 'lib/testscript_engine/message_handler.rb', line 20 def newline puts end |
#outcome_symbol(outcome) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/testscript_engine/message_handler.rb', line 175 def outcome_symbol(outcome) symbol = begin case outcome when "UNKNOWN" "?¿?" when "FATAL" [023042].pack("U*") when "ERROR" [10071].pack("U*") when "WARN" [023220].pack("U*") when "INFO" [10003].pack("U*") when "DEBUG" [0372415].pack("U*") when "FAIL" [10007].pack("U*") when "SKIP" "\u21BB".encode('utf-8') end end "(#{symbol})" end |
#pass(message_type, *options) ⇒ Object
117 118 119 120 121 |
# File 'lib/testscript_engine/message_handler.rb', line 117 def pass(, *) = (, *) super() print_out "#{outcome_symbol("INFO")} #{}" end |
#postprocessing ⇒ Object
108 109 |
# File 'lib/testscript_engine/message_handler.rb', line 108 def postprocessing end |
#preprocess ⇒ Object
84 85 86 87 88 |
# File 'lib/testscript_engine/message_handler.rb', line 84 def preprocess print_out (:begin_preprocess) super print_out (:finish_preprocess) end |
#print_action_header(action_type) ⇒ Object
147 148 149 150 151 152 |
# File 'lib/testscript_engine/message_handler.rb', line 147 def print_action_header(action_type) return false if @previous_action_type == action_type @previous_action_type = action_type true end |
#print_out(message) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/testscript_engine/message_handler.rb', line 24 def print_out() if .start_with?("START") newline increase_space elsif .start_with?("FINISH") else print unit_of_space end print space puts if .start_with?("FINISH") decrease_space end nil end |
#run(*args) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/testscript_engine/message_handler.rb', line 76 def run(*args) print_out (:begin_runnable_execution, script.id) result = super puts print_out (:finish_runnable_execution) result end |
#setup ⇒ Object
90 91 92 93 94 |
# File 'lib/testscript_engine/message_handler.rb', line 90 def setup print_out (:begin_setup) super print_out (:finish_setup) end |
#skip(message_type, *options) ⇒ Object
129 130 131 132 133 |
# File 'lib/testscript_engine/message_handler.rb', line 129 def skip(, *) = (, *) super() if modify_report print_out "#{outcome_symbol("SKIP")} #{}" end |
#space ⇒ Object
4 5 6 |
# File 'lib/testscript_engine/message_handler.rb', line 4 def space @space ||= '' end |
#teardown ⇒ Object
102 103 104 105 106 |
# File 'lib/testscript_engine/message_handler.rb', line 102 def teardown print_out (:begin_teardown) super print_out (:finish_teardown) end |
#test ⇒ Object
96 97 98 99 100 |
# File 'lib/testscript_engine/message_handler.rb', line 96 def test print_out (:begin_test) super print_out (:finish_test) end |
#unit_of_space ⇒ Object
8 9 10 |
# File 'lib/testscript_engine/message_handler.rb', line 8 def unit_of_space " " end |
#warning(message_type, *options) ⇒ Object
135 136 137 138 139 |
# File 'lib/testscript_engine/message_handler.rb', line 135 def warning(, *) = (, *) super() if modify_report print_out "#{outcome_symbol("WARN")} #{}" end |