From 2a15b2cc61d5870790f2272c6268c1377aaa1f61 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 7 Nov 2024 12:03:38 -0500 Subject: [PATCH] Add a test for nonfatal assertions Testing this in a normal testcaes is a bit tricky, since triggering a non-fatal assertion has the side-effect of marking the test as failed. So just don't run any testcases here, but check the side-effect manually. Since we don't produce TAP output when not using g_test_run(), tell meson that we're using the exitcode protocol. --- glib/tests/meson.build | 3 +++ glib/tests/testing-nonfatal.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 glib/tests/testing-nonfatal.c diff --git a/glib/tests/meson.build b/glib/tests/meson.build index ffa931453..10886f698 100644 --- a/glib/tests/meson.build +++ b/glib/tests/meson.build @@ -159,6 +159,9 @@ glib_tests = { 'extra_programs' : ['testing-helper'], 'c_args' : cc.get_id() == 'gcc' ? ['-Werror=sign-conversion'] : [], }, + 'testing-nonfatal' : { + 'protocol' : 'exitcode' + }, 'test-printf' : {}, 'thread' : {}, 'thread-deprecated' : {}, diff --git a/glib/tests/testing-nonfatal.c b/glib/tests/testing-nonfatal.c new file mode 100644 index 000000000..f3bbd83f5 --- /dev/null +++ b/glib/tests/testing-nonfatal.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2024 Red Hat, Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, G_TEST_OPTION_NONFATAL_ASSERTIONS, NULL); + + g_assert_cmpstr ("We can survive this!", ==, "Or maybe not?"); + + if (!g_test_failed ()) + return 1; + + return 0; +}