mirror of
https://gitlab.gnome.org/GNOME/libmks.git
synced 2024-12-22 05:35:21 +00:00
tests: add scaffolding for unit tests with coverage
This commit is contained in:
parent
0cd80513e0
commit
db33eece15
15
README.md
15
README.md
@ -7,6 +7,21 @@ D-Bus device support in QEMU and GTK 4.
|
|||||||
|
|
||||||
Nightly documentation can be found [here](https://gnome.pages.gitlab.gnome.org/libmks/libmks1).
|
Nightly documentation can be found [here](https://gnome.pages.gitlab.gnome.org/libmks/libmks1).
|
||||||
|
|
||||||
|
# Unit testing
|
||||||
|
|
||||||
|
Be sure you have `lcov` package installed on your system if you want coverage data.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
meson setup builddir
|
||||||
|
meson configure -Db_coverage=true builddir # if you want to collect coverage data
|
||||||
|
meson compile -C builddir
|
||||||
|
meson test -C builddir --suit "libmks"
|
||||||
|
rm -rf builddir/subprojects # if you don't want subprojects coverage in the report
|
||||||
|
ninja coverage-html -C builddir # if you want to generate coverage report
|
||||||
|
```
|
||||||
|
|
||||||
|
If generated, coverage report will be in `builddir/meson-logs/coveragereport/index.html`
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
|
|
||||||
By default, QEMU will connect to your user session D-Bus if you do not
|
By default, QEMU will connect to your user session D-Bus if you do not
|
||||||
|
@ -158,8 +158,15 @@ add_project_link_arguments(project_link_args, language: 'c')
|
|||||||
subdir('lib')
|
subdir('lib')
|
||||||
subdir('tools')
|
subdir('tools')
|
||||||
|
|
||||||
|
have_tests = get_option('tests')
|
||||||
|
if have_tests
|
||||||
|
subdir('tests')
|
||||||
|
endif
|
||||||
|
|
||||||
if get_option('docs') and get_option('introspection').allowed()
|
if get_option('docs') and get_option('introspection').allowed()
|
||||||
subdir('docs')
|
subdir('docs')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
configure_file(output: 'config.h', configuration: config_h)
|
configure_file(output: 'config.h', configuration: config_h)
|
||||||
|
|
||||||
|
summary('Enabled', have_tests, section: 'Tests')
|
||||||
|
@ -14,3 +14,9 @@ option('tracing',
|
|||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
value: false,
|
value: false,
|
||||||
description: 'Enable developer tracing information in logs')
|
description: 'Enable developer tracing information in logs')
|
||||||
|
|
||||||
|
option('tests',
|
||||||
|
type: 'boolean',
|
||||||
|
value: true,
|
||||||
|
description: 'Enable tests globally.'
|
||||||
|
)
|
5
tests/meson.build
Normal file
5
tests/meson.build
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
unit_tests = executable('unit-tests', 'unit-tests.c',
|
||||||
|
dependencies: libmks_dep,
|
||||||
|
)
|
||||||
|
|
||||||
|
test('Unit tests', unit_tests)
|
57
tests/unit-tests.c
Normal file
57
tests/unit-tests.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* unit-tests.c
|
||||||
|
*
|
||||||
|
* Copyright 2023 Sandro Bonazzola <sbonazzo@redhat.com>
|
||||||
|
*
|
||||||
|
* 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 General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <libmks.h>
|
||||||
|
|
||||||
|
|
||||||
|
static void test_mks_get_major_version (void) {
|
||||||
|
int version = mks_get_major_version();
|
||||||
|
g_assert_cmpint (version, ==, MKS_MAJOR_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_mks_get_minor_version (void) {
|
||||||
|
int version = mks_get_minor_version();
|
||||||
|
g_assert_cmpint (version, ==, MKS_MINOR_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_mks_get_micro_version (void) {
|
||||||
|
int version = mks_get_micro_version();
|
||||||
|
g_assert_cmpint (version, ==, MKS_MICRO_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_tests (void)
|
||||||
|
{
|
||||||
|
g_test_add_func ("/lib/init", mks_init);
|
||||||
|
g_test_add_func ("/lib/get_major_version", test_mks_get_major_version);
|
||||||
|
g_test_add_func ("/lib/get_minor_version", test_mks_get_minor_version);
|
||||||
|
g_test_add_func ("/lib/get_micro_version", test_mks_get_micro_version);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
init_tests ();
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user