Module testing stdlib

testing
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
10
Imported by:
0
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imported by

This section is empty.

Aliases

This section is empty.

Constants

#constant github_job

pub const github_job = os.getenv('GITHUB_JOB')

#constant show_start

pub const show_start = os.getenv('VTEST_SHOW_START') == '1'

#constant hide_skips

pub const hide_skips = os.getenv('VTEST_HIDE_SKIP') == '1'

#constant hide_oks

pub const hide_oks = os.getenv('VTEST_HIDE_OK') == '1'

#constant fail_fast

pub const fail_fast = os.getenv('VTEST_FAIL_FAST') == '1'

#constant fail_flaky

pub const fail_flaky = os.getenv('VTEST_FAIL_FLAKY') == '1'

#constant test_only

pub const test_only = os.getenv('VTEST_ONLY').split_any(',')

#constant test_only_fn

pub const test_only_fn = os.getenv('VTEST_ONLY_FN').split_any(',')

#constant is_node_present

pub const is_node_present = os.execute('node --version').exit_code == 0

#constant all_processes

pub const all_processes = get_all_processes()

#constant empty

pub const empty = term.header(' ', ' ')

Sum types

This section is empty.

Functions

#fn build_v_cmd_failed

fn build_v_cmd_failed(cmd string) bool

#fn building_any_v_binaries_failed

fn building_any_v_binaries_failed() bool

#fn eheader

fn eheader(msg string)

#fn find_started_process

fn find_started_process(pname string) !string

#fn get_test_details

fn get_test_details(file string) TestDetails

#fn prepare_test_session

fn prepare_test_session(zargs string, folder string, oskipped []string, main_label string) TestSession

#fn setup_new_vtmp_folder

fn setup_new_vtmp_folder() string

setup_new_vtmp_folder creates a new nested folder inside VTMP, then resets VTMP to it, so that V programs/tests will write their temporary files to new location.

The new nested folder, and its contents, will get removed after all tests/programs succeed.

#fn v_build_failing_skipped

fn v_build_failing_skipped(zargs string, folder string, oskipped []string, cb fn (mut &TestSession)) bool

#fn vlib_should_be_present

fn vlib_should_be_present(parent_dir string)

Structs

#struct TestSession

pub struct TestSession {
pub mut:
	files         []string
	skip_files    []string
	vexe          string
	vroot         string
	vtmp_dir      string
	vargs         string
	fail_fast     bool
	benchmark     benchmark.Benchmark
	rm_binaries   bool = true
	silent_mode   bool
	show_stats    bool
	progress_mode bool
	root_relative bool // used by CI runs, so that the output is stable everywhere
	nmessages     chan LogMessage // many publishers, single consumer/printer
	nmessage_idx  int // currently printed message index
	failed_cmds   shared []string
	reporter      Reporter = Reporter(NormalReporter{})
}

#fn new_test_session

fn new_test_session(_vargs string, will_compile bool) TestSession

#fn (&TestSession) add_failed_cmd

fn (mut ts &TestSession) add_failed_cmd(cmd string)

#fn (&TestSession) show_list_of_failed_tests

fn (mut ts &TestSession) show_list_of_failed_tests()

#fn (&TestSession) append_message

fn (mut ts &TestSession) append_message(kind MessageKind, msg string, mtc MessageThreadContext)

#fn (&TestSession) append_message_with_duration

fn (mut ts &TestSession) append_message_with_duration(kind MessageKind, msg string, d time.Duration, mtc MessageThreadContext)

#fn (&TestSession) session_start

fn (mut ts &TestSession) session_start(message string)

#fn (&TestSession) session_stop

fn (mut ts &TestSession) session_stop(message string)

#fn (&TestSession) print_messages

fn (mut ts &TestSession) print_messages()

#fn (&TestSession) handle_test_runner_option

fn (mut ts &TestSession) handle_test_runner_option()

#fn (&TestSession) init

fn (mut ts &TestSession) init()

#fn (&TestSession) add

fn (mut ts &TestSession) add(file string)

#fn (&TestSession) test

fn (mut ts &TestSession) test()

#struct TestDetails

pub struct TestDetails {
pub mut:
	retry int
	flaky bool // when flaky tests fail, the whole run is still considered successfull, unless VTEST_FAIL_FLAKY is 1
}

#struct LogMessage

pub struct LogMessage {
pub:
	kind    MessageKind   // see the MessageKind declaration above
	file    string        // the _test.v file that the message is about
	when    time.Time     // when was the message sent (messages are sent by the execution threads at the *end* of each event)
	flow_id string        // the messages of each thread, producing LogMessage, will have all the same unique flowid. Messages by other threads will have other flowid. If you use VJOBS=1 to serialise the execution, then all messages will have the same flowid.
	took    time.Duration // the duration of the event, that this message describes
	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
}

#struct DumpReporter

pub struct DumpReporter {
mut:
	files []string
}

DumpReporter implements the interface testing.Reporter.

It is used by v -test-runner dump test .

#fn (&DumpReporter) worker_threads_start

fn (mut r &DumpReporter) worker_threads_start(files []string, mut ts &TestSession)

#fn (DumpReporter) worker_threads_finish

fn (r DumpReporter) worker_threads_finish(mut ts &TestSession)

#fn (DumpReporter) session_start

fn (r DumpReporter) session_start(message string, mut ts &TestSession)

#fn (DumpReporter) session_stop

fn (r DumpReporter) session_stop(message string, mut ts &TestSession)

#fn (DumpReporter) report

fn (r DumpReporter) report(index int, message LogMessage)

#fn (DumpReporter) report_stop

fn (r DumpReporter) report_stop()

#fn (DumpReporter) progress

fn (r DumpReporter) progress(index int, message string)

#fn (DumpReporter) update_last_line

fn (r DumpReporter) update_last_line(index int, message string)

#fn (DumpReporter) update_last_line_and_move_to_next

fn (r DumpReporter) update_last_line_and_move_to_next(index int, message string)

#fn (DumpReporter) message

fn (r DumpReporter) message(index int, message string)

#fn (DumpReporter) divider

fn (r DumpReporter) divider()

#fn (DumpReporter) list_of_failed_commands

fn (r DumpReporter) list_of_failed_commands(failed_cmds []string)

#struct NormalReporter

pub struct NormalReporter {
}

NormalReporter implements the interface testing.Reporter.

It is used by default by v test . It was extracted by the original non customiseable output implementation directly in cmd/tools/modules/testing/common.v

#fn (NormalReporter) session_start

fn (r NormalReporter) session_start(message string, mut ts &TestSession)

#fn (NormalReporter) session_stop

fn (r NormalReporter) session_stop(message string, mut ts &TestSession)

#fn (NormalReporter) report

fn (r NormalReporter) report(index int, message LogMessage)

the most general form; it may be useful for other reporters in the normal one, it currently does nothing

#fn (NormalReporter) report_stop

fn (r NormalReporter) report_stop()

#fn (NormalReporter) progress

fn (r NormalReporter) progress(index int, message string)

#fn (NormalReporter) update_last_line

fn (r NormalReporter) update_last_line(index int, message string)

in progress mode, the last line will be rewritten many times, and does not end with \n the \n will be printed just once when some progress has been made.

#fn (NormalReporter) update_last_line_and_move_to_next

fn (r NormalReporter) update_last_line_and_move_to_next(index int, message string)

#fn (NormalReporter) message

fn (r NormalReporter) message(index int, message string)

#fn (NormalReporter) divider

fn (r NormalReporter) divider()

#fn (NormalReporter) worker_threads_start

fn (r NormalReporter) worker_threads_start(files []string, mut ts &TestSession)

#fn (NormalReporter) worker_threads_finish

fn (r NormalReporter) worker_threads_finish(mut ts &TestSession)

#fn (NormalReporter) list_of_failed_commands

fn (r NormalReporter) list_of_failed_commands(failed_cmds []string)

#struct TeamcityReporter

pub struct TeamcityReporter {
}

TeamcityReporter implements the interface Reporter.

It is used by v -test-runner teamcity test .

#fn (TeamcityReporter) session_start

fn (r TeamcityReporter) session_start(message string, mut ts &TestSession)

#fn (TeamcityReporter) session_stop

fn (r TeamcityReporter) session_stop(message string, mut ts &TestSession)

fn (r TeamcityReporter) report(index int, message LogMessage)

#fn (TeamcityReporter) get_test_suite_name_by_file

fn (r TeamcityReporter) get_test_suite_name_by_file(path string) string

#fn (TeamcityReporter) report_stop

fn (r TeamcityReporter) report_stop()

#fn (TeamcityReporter) progress

fn (r TeamcityReporter) progress(index int, message string)

#fn (TeamcityReporter) update_last_line

fn (r TeamcityReporter) update_last_line(index int, message string)

#fn (TeamcityReporter) update_last_line_and_move_to_next

fn (r TeamcityReporter) update_last_line_and_move_to_next(index int, message string)

#fn (TeamcityReporter) message

fn (r TeamcityReporter) message(index int, message string)

#fn (TeamcityReporter) divider

fn (r TeamcityReporter) divider()

#fn (TeamcityReporter) worker_threads_start

fn (r TeamcityReporter) worker_threads_start(files []string, mut ts &TestSession)

#fn (TeamcityReporter) worker_threads_finish

fn (r TeamcityReporter) worker_threads_finish(mut ts &TestSession)

#fn (TeamcityReporter) list_of_failed_commands

fn (r TeamcityReporter) list_of_failed_commands(failed_cmds []string)

Interfaces

#interface Reporter

pub interface Reporter {
mut:
	session_start(message string, mut ts TestSession) // called once per test session, in the main thread, suitable for setting up supporting infrastructure.
	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.
	worker_threads_start(files []string, mut ts TestSession) // called once per test session, in the main thread, right before all the worker threads start
	worker_threads_finish(mut ts TestSession) // called once per test session, in the main thread, right after all the worker threads finish
	//
	report(index int, log_msg LogMessage) // called once per each message, that will be shown (ok/fail/skip etc), only in the reporting thread.
	report_stop() // called just once after all messages are processed, only in the reporting thread, but before stop_session.
	//
	// TODO: reconsider, whether the next methods, should be kept for all reporters, or just moved inside the normal reporter, to simplify the interface
	progress(index int, message string)
	update_last_line(index int, message string)
	update_last_line_and_move_to_next(index int, message string)
	message(index int, message string)
	divider() // called to show a long ---------- horizontal line; can be safely ignored in most reporters; used in the main thread.
	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.
}

Enums

#enum MessageKind

pub enum MessageKind {
	cmd_begin // sent right before *each* _test.v file execution, the resulting status is not known yet, but the _test.v file itself is
	cmd_end // sent right after *each* _test.v file execution, the message contains the output of that execution
	//
	ok // success of a _test.v file
	fail // failed _test.v file, one or more assertions failed
	skip // the _test.v file was skipped for some reason
	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)
	//
	cannot_compile // when the _test.v file compiled with errors
	//
	sentinel // send just once after all executions are done; it signals that the reporting/printing thread should stop the loop and exit
}