diff options
author | Phaedrus Leeds <mwleeds@protonmail.com> | 2022-05-10 17:34:21 +0000 |
---|---|---|
committer | Phaedrus Leeds <mwleeds@protonmail.com> | 2022-05-10 17:34:21 +0000 |
commit | 72e532d7edd0219b20f391f6dc63533e75a445cf (patch) | |
tree | f0b85783954d4c3ff1c6ce2a319c1d09aa389914 /tests | |
parent | c71f7aefa142c444210f1021d1af42f365ec3a7b (diff) | |
parent | 238f7bfc494e16a0864f88ae891da6e7b3d82e5b (diff) | |
download | libglnx-72e532d7edd0219b20f391f6dc63533e75a445cf.tar.gz |
Merge branch 'wip/smcv/subproject' into 'master'
Improve Meson subproject support
See merge request GNOME/libglnx!34
Diffstat (limited to 'tests')
-rw-r--r-- | tests/meson.build | 62 | ||||
-rw-r--r-- | tests/use-as-subproject/.gitignore | 5 | ||||
-rw-r--r-- | tests/use-as-subproject/README | 8 | ||||
-rw-r--r-- | tests/use-as-subproject/config.h | 6 | ||||
-rw-r--r-- | tests/use-as-subproject/dummy-config.h.in | 6 | ||||
-rw-r--r-- | tests/use-as-subproject/meson.build | 24 | ||||
-rw-r--r-- | tests/use-as-subproject/use-libglnx.c | 16 | ||||
-rw-r--r-- | tests/use-as-subproject/use-testlib.c | 17 |
8 files changed, 123 insertions, 21 deletions
diff --git a/tests/meson.build b/tests/meson.build index 2ad8c44..2c38ab0 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -2,25 +2,45 @@ # Copyright 2019 Collabora Ltd. # SPDX-License-Identifier: LGPL-2.1-or-later -test_names = [ - 'errors', - 'fdio', - 'macros', - 'shutil', - 'xattrs', -] +libglnx_testlib = static_library( + 'glnx-testlib', + 'libglnx-testlib.c', + 'libglnx-testlib.h', + dependencies : [ + libglnx_dep, + libglnx_deps, + ], + install : false, +) +libglnx_testlib_dep = declare_dependency( + dependencies : [ + libglnx_dep, + libglnx_deps, + ], + include_directories : include_directories('.'), + link_with : libglnx_testlib, +) -foreach test_name : test_names - exe = executable(test_name, - [ - 'libglnx-testlib.c', - 'libglnx-testlib.h', - 'test-libglnx-' + test_name + '.c', - ], - dependencies: [ - libglnx_dep, - libglnx_deps, - ], - ) - test(test_name, exe) -endforeach +if get_option('tests') + test_names = [ + 'errors', + 'fdio', + 'macros', + 'shutil', + 'xattrs', + ] + + foreach test_name : test_names + exe = executable(test_name, + [ + 'test-libglnx-' + test_name + '.c', + ], + dependencies: [ + libglnx_dep, + libglnx_deps, + libglnx_testlib_dep, + ], + ) + test(test_name, exe) + endforeach +endif diff --git a/tests/use-as-subproject/.gitignore b/tests/use-as-subproject/.gitignore new file mode 100644 index 0000000..ec6149f --- /dev/null +++ b/tests/use-as-subproject/.gitignore @@ -0,0 +1,5 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: LGPL-2.0-or-later + +/_build/ +/subprojects/ diff --git a/tests/use-as-subproject/README b/tests/use-as-subproject/README new file mode 100644 index 0000000..cc43a09 --- /dev/null +++ b/tests/use-as-subproject/README @@ -0,0 +1,8 @@ +This is a simple example of a project that uses libglnx as a subproject. +The intention is that if this project can successfully build and use libglnx +as a subproject, then so could Flatpak. + +<!-- +Copyright 2022 Collabora Ltd. +SPDX-License-Identifier: LGPL-2.0-or-later +--> diff --git a/tests/use-as-subproject/config.h b/tests/use-as-subproject/config.h new file mode 100644 index 0000000..dffc647 --- /dev/null +++ b/tests/use-as-subproject/config.h @@ -0,0 +1,6 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#error Should not use superproject config.h to compile libglnx diff --git a/tests/use-as-subproject/dummy-config.h.in b/tests/use-as-subproject/dummy-config.h.in new file mode 100644 index 0000000..bffb52a --- /dev/null +++ b/tests/use-as-subproject/dummy-config.h.in @@ -0,0 +1,6 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#error Should not use superproject generated config.h to compile libglnx diff --git a/tests/use-as-subproject/meson.build b/tests/use-as-subproject/meson.build new file mode 100644 index 0000000..2d08160 --- /dev/null +++ b/tests/use-as-subproject/meson.build @@ -0,0 +1,24 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: LGPL-2.0-or-later + +project( + 'use-libglnx-as-subproject', + 'c', + version : '0', + meson_version : '>=0.49.0', +) + +configure_file( + copy : true, + input : 'dummy-config.h.in', + output : 'config.h', +) + +glib_dep = dependency('glib-2.0') + +libglnx = subproject('libglnx') +libglnx_dep = libglnx.get_variable('libglnx_dep') +libglnx_testlib_dep = libglnx.get_variable('libglnx_testlib_dep') + +executable('use-libglnx', 'use-libglnx.c', dependencies : [libglnx_dep, glib_dep]) +executable('use-testlib', 'use-testlib.c', dependencies : [libglnx_testlib_dep, glib_dep]) diff --git a/tests/use-as-subproject/use-libglnx.c b/tests/use-as-subproject/use-libglnx.c new file mode 100644 index 0000000..0e14db0 --- /dev/null +++ b/tests/use-as-subproject/use-libglnx.c @@ -0,0 +1,16 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#include <libglnx.h> + +int +main (void) +{ + GError *error = NULL; + + glnx_throw (&error, "whatever"); + g_clear_error (&error); + return 0; +} diff --git a/tests/use-as-subproject/use-testlib.c b/tests/use-as-subproject/use-testlib.c new file mode 100644 index 0000000..9a955b4 --- /dev/null +++ b/tests/use-as-subproject/use-testlib.c @@ -0,0 +1,17 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#include <libglnx.h> +#include <libglnx-testlib.h> + +int +main (void) +{ + _GLNX_TEST_DECLARE_ERROR (local_error, error); + + glnx_throw (error, "Whatever"); + g_clear_error (&local_error); + return 0; +} |