GNOME Bugzilla – Bug 720236
gtestutils: Allow clean simple use of g_test_trap_subprocess()
Last modified: 2014-01-15 14:49:05 UTC
My biggest gripe about g_test_trap_subprocess() is how it requires changes all over the test case C file to get working. A test case needs to know it's own path, and additional tests need to be added with appropriate names. The above makes sense for pretty advanced cases, but for bog simple this-should-produce-a-critical-warning test, it's completely overkill. Luckily we can use g_test_subprocess() to rerun a test case itself in a subprocess. Like so: static void test_build_null_string (void) { GHashTable *attributes; if (g_test_subprocess ()) { attributes = secret_attributes_build (&MOCK_SCHEMA, "number", 4, "string", NULL, "even", TRUE, NULL); g_assert (attributes == NULL); return; } g_test_trap_subprocess ("/attributes/build-null-string", 0, G_TEST_SUBPROCESS_INHERIT_STDOUT); g_test_trap_assert_failed (); g_test_trap_assert_stderr ("*attribute*NULL*"); } As you can see one complication remains ... a test case must know its own path. This not only adds complexity, but prevents a single such testcase function being used with multiple different fixtures, at different paths. So attached patch changes g_test_trap_subprocess to accept NULL as it's test name, and it'll just run the same test in a subprocess. Allows elegant use of subprocesses. Updated documentation to remove complex example and replace with simple one.
Created attachment 263966 [details] [review] gtestutils: Allow clean simple use of g_test_trap_subprocess() Allow g_test_trap_subprocess() to be used in a simple cases by rerunning the same test case itself. This is accomplished by passing %NULL as the test case name.
That is pretty elegant, indeed. I like it. Does rerunning tests recursively work just fine with our reporting ?
Attachment 263966 [details] pushed as cd2204b - gtestutils: Allow clean simple use of g_test_trap_subprocess()
Thanks Matthias.