init


Description:

[ Version ( since = "2.16" ) ]
public void init (ref unowned string[] args, ...)

Initialize the GLib testing framework, e.

g. by seeding the test random number generator, the name for get_prgname and parsing test related command line args.

This should be called before calling any other `g_test_*()` functions.

So far, the following arguments are understood:

  • `-l`: List test cases available in a test executable.
  • `--seed=SEED`: Provide a random seed to reproduce test runs using random numbers.
  • `--verbose`: Run tests verbosely.
  • `-q`, `--quiet`: Run tests quietly.
  • `-p PATH`: Execute all tests matching the given path.
  • `-s PATH`: Skip all tests matching the given path. This can also be used to force a test to run that would otherwise be skipped (ie, a test whose name contains "/subprocess").
  • `-m {perf|slow|thorough|quick|undefined|no-undefined}`: Execute tests according to these test modes:

    `perf`: Performance tests, may take long and report results (off by default).

    `slow`, `thorough`: Slow and thorough tests, may take quite long and maximize coverage (off by default).

    `quick`: Quick tests, should run really quickly and give good coverage (the default).

    `undefined`: Tests for undefined behaviour, may provoke programming errors under trap_subprocess or expect_message to check that appropriate assertions or warnings are given (the default).

    `no-undefined`: Avoid tests for undefined behaviour

  • `--debug-log`: Debug test logging output.

Options which can be passed to ... are:

  • `"no_g_set_prgname"`: Causes init to not call set_prgname.
  • g_test_option_isolate_dirs: Creates a unique temporary directory for each unit test and uses g_set_user_dirs to set XDG directories to point into that temporary directory for the duration of the unit test. See the documentation for g_test_option_isolate_dirs.

Since 2.58, if tests are compiled with `G_DISABLE_ASSERT` defined, init will print an error and exit. This is to prevent no-op tests from being executed, as assert is commonly (erroneously) used in unit tests, and is a no-op when compiled with `G_DISABLE_ASSERT`. Ensure your tests are compiled without `G_DISABLE_ASSERT` defined.

Example: Test, initialization:

public static int main (string[] args) {
// Use ./test --help to review our options
Test.init (ref args);

// Register test cases via Test.add_func & friends

Test.run ();
return 0;
}

valac --pkg glib-2.0 GLib.Test.init.vala

Parameters:

...

null-terminated list of special options, documented below.

argc

Address of the argc parameter of the main function. Changed if any arguments were handled.

argv

Address of the argv parameter of main. Any parameters understood by init stripped before return.


Namespace: GLib.Test
Package: glib-2.0