| 1 | module testing |
| 2 | |
| 3 | import time |
| 4 | |
| 5 | pub enum MessageKind { |
| 6 | compile_begin // sent right before *each* _test.v file compilation, the resulting status is not known yet, but the _test.v file itself is |
| 7 | compile_end // sent right after *each* _test.v file compilation, the message contains the output of that compilation |
| 8 | cmd_begin // sent right before *each* _test.v file execution, the resulting status is not known yet, but the _test.v file itself is |
| 9 | cmd_end // sent right after *each* _test.v file execution, the message contains the output of that execution |
| 10 | stats_output // captured `v -stats test` output that should be shown verbatim on stdout |
| 11 | stats_error // captured `v -stats test` output for failed commands, shown verbatim on stderr |
| 12 | |
| 13 | ok // success of a _test.v file |
| 14 | fail // failed _test.v file, one or more assertions failed |
| 15 | skip // the _test.v file was skipped for some reason |
| 16 | info // a generic information message, detailing the actions of the `v test` program (some tests could be repeated for example, and the details are sent with an .info status) |
| 17 | |
| 18 | cannot_compile // when the _test.v file compiled with errors |
| 19 | |
| 20 | sentinel // send just once after all executions are done; it signals that the reporting/printing thread should stop the loop and exit |
| 21 | } |
| 22 | |
| 23 | pub struct LogMessage { |
| 24 | pub: |
| 25 | kind MessageKind // see the MessageKind declaration above |
| 26 | file string // the _test.v file that the message is about |
| 27 | when time.Time // when was the message sent (messages are sent by the execution threads at the *end* of each event) |
| 28 | flow_id string // the messages of each thread, producing LogMessage, will have all the same unique flow_id. Messages by other threads will have other flow_id. If you use VJOBS=1 to serialise the execution, then all messages will have the same flow_id. |
| 29 | took time.Duration // the duration of the event, that this message describes |
| 30 | message string // the actual message text; the result of the event, that the message describes; most reporters could ignore this, since it could be reconstructed by the other fields |
| 31 | } |
| 32 | |
| 33 | pub interface Reporter { |
| 34 | mut: |
| 35 | session_start(message string, mut ts TestSession) // called once per test session, in the main thread, suitable for setting up supporting infrastructure. |
| 36 | session_stop(message string, mut ts TestSession) // called once per test session, in the main thread, after everything else, suitable for summaries, creating .xml reports, uploads etc. |
| 37 | worker_threads_start(files []string, mut ts TestSession) // called once per test session, in the main thread, right before all the worker threads start |
| 38 | worker_threads_finish(mut ts TestSession) // called once per test session, in the main thread, right after all the worker threads finish |
| 39 | |
| 40 | report(index int, log_msg LogMessage) // called once per each message, that will be shown (ok/fail/skip etc), only in the reporting thread. |
| 41 | report_stop() // called just once after all messages are processed, only in the reporting thread, but before stop_session. |
| 42 | |
| 43 | // TODO: reconsider, whether the next methods, should be kept for all reporters, or just moved inside the normal reporter, to simplify the interface |
| 44 | progress(index int, message string) |
| 45 | update_last_line(index int, message string) |
| 46 | update_last_line_and_move_to_next(index int, message string) |
| 47 | message(index int, message string) |
| 48 | divider() // called to show a long ---------- horizontal line; can be safely ignored in most reporters; used in the main thread. |
| 49 | list_of_failed_commands(cmds []string) // called after all testing is done, to produce a small summary that only lists the failed commands, so that they can be retried manually if needed, without forcing the user to scroll and find them. |
| 50 | } |
| 51 | |