trap_subprocess
Description:
[ Version ( since = "2.38" ) ]
public void trap_subprocess (string? test_path, uint64 usec_timeout, TestSubprocessFlags test_flags)
public void trap_subprocess (string? test_path, uint64 usec_timeout, TestSubprocessFlags test_flags)
Respawns the test program to run only test_path
in a subprocess.
This is equivalent to calling g_test_trap_subprocess_with_envp
with `envp` set to null. See the
documentation for that function for full details.
Example: Run a case in a subprocess:
public static int main (string[] args) {
Test.init (ref args);
Test.bug_base ("http://bugzilla.gnome.org/");
Test.add_func ("/valadoc/driver-0.14.x", () => {
Test.trap_subprocess ("/valadoc/driver-0.14.x/subprocess", 0, 0);
//
// Optional checks & asserts:
//
// Check whether the last fork passed/succeeded:
if (Test.trap_has_passed ()) {
// Whatever
}
// Check whether GTest killed the fork due to a timeout
if (Test.trap_reached_timeout ()) {
Test.message ("timeout reached!!");
}
// Make sure the last forked test passed/succeeded:
Test.trap_assert_passed ();
// Make sure the forked output does match the following patterns:
// See GLib.PatternSpec for details
Test.trap_assert_stdout ("*warning:*");
Test.trap_assert_stderr ("*error:*");
// Make sure the forked output does not match the following patterns:
Test.trap_assert_stdout_unmatched ("*debug:*");
Test.trap_assert_stderr_unmatched ("*critical-error:*");
});
// Because of the '/subprocess' in the name, this test will
// not be run by the Test.run () call below.
Test.add_func ("/valadoc/driver-0.14.x/subprocess", () => {
// Our testcase:
// ...
print ("warning: unexpected token: ==\n");
stderr.printf ("error: unexpected token: ==\n");
// ..
// use assert () and friends to verify your code
// assert (false) marks a test as "not-passed"
});
Test.run ();
return 0;
}
valac --pkg glib-2.0 GLib.Test.trap_subprocess.vala
./GLib.Test.trap_subprocess --verbose
Parameters:
test_path |
Test to run in a subprocess |
usec_timeout |
Timeout for the subprocess test in micro seconds. |
test_flags |
Flags to modify subprocess behaviour. |
Namespace: GLib.Test
Package: glib-2.0