[gcab/wip/smcv/insttest: 2/2] self-test: Optionally install for as-installed testing
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcab/wip/smcv/insttest: 2/2] self-test: Optionally install for as-installed testing
- Date: Mon, 2 Sep 2019 09:53:58 +0000 (UTC)
commit 48e80eacb9eef0654ad9694603bf5ba58f567c68
Author: Simon McVittie <smcv debian org>
Date: Mon Sep 2 10:01:43 2019 +0100
self-test: Optionally install for as-installed testing
This follows the interface proposed in
https://wiki.gnome.org/Initiatives/GnomeGoals/InstalledTests and can
be used for "as-installed" testing, which is a useful way to check for
regressions (for example if a GLib upgrade might cause a regression in
the already-compiled version of gcab), especially in frameworks like
Debian's autopkgtest and Fedora's Standard Test Interface.
To locate the test data in a way that is compatible with as-installed
tests, use g_test_build_filename() instead of hard-coding the source
directory into the test executable. This incidentally also avoids relying
on PATH_MAX, which is not completely portable.
Signed-off-by: Simon McVittie <smcv debian org>
meson.build | 1 -
meson_options.txt | 1 +
tests/gcab-self-test.c | 9 +--------
tests/meson.build | 44 +++++++++++++++++++++++++++++++++++++++++++-
tests/template-tap.test.in | 4 ++++
5 files changed, 49 insertions(+), 10 deletions(-)
---
diff --git a/meson.build b/meson.build
index d48cf5f..8e90da7 100644
--- a/meson.build
+++ b/meson.build
@@ -111,7 +111,6 @@ conf.set_quoted('PACKAGE_NAME', meson.project_name())
conf.set_quoted('PACKAGE_STRING', package_string)
conf.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
conf.set_quoted('PACKAGE_BUGREPORT',
'https://bugzilla.gnome.org/enter_bug.cgi?product=msitools&component=gcab')
-conf.set_quoted('TESTDATADIR', join_paths(meson.source_root(), 'tests'))
configure_file(
output : 'config.h',
configuration : conf
diff --git a/meson_options.txt b/meson_options.txt
index 8aecd20..c1b1da1 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -3,3 +3,4 @@ option('introspection', type : 'boolean', value : true, description : 'generate
option('nls', type : 'boolean', value : true, description : 'enable native language support')
option('vapi', type : 'boolean', value : true, description: 'generate Vala bindings (requires
introspection)')
option('tests', type : 'boolean', value : true, description : 'enable tests')
+option('installed_tests', type : 'boolean', value : false, description : 'install tests for "as-installed"
testing')
diff --git a/tests/gcab-self-test.c b/tests/gcab-self-test.c
index 66a4778..746d069 100644
--- a/tests/gcab-self-test.c
+++ b/tests/gcab-self-test.c
@@ -29,14 +29,7 @@
static gchar *
gcab_test_get_filename (const gchar *filename)
{
- gchar *tmp;
- char full_tmp[PATH_MAX];
- g_autofree gchar *path = NULL;
- path = g_build_filename (TESTDATADIR, filename, NULL);
- tmp = realpath (path, full_tmp);
- if (tmp != NULL)
- return g_strdup (full_tmp);
- return NULL;
+ return g_test_build_filename (G_TEST_DIST, filename, NULL);
}
static void
diff --git a/tests/meson.build b/tests/meson.build
index d9be63c..1e46e2a 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,3 +1,40 @@
+installed_tests_metadir = join_paths(get_option('datadir'), 'installed-tests', 'libgcab-1.0')
+installed_tests_execdir = join_paths(get_option('libexecdir'), 'installed-tests', 'libgcab-1.0')
+installed_tests_enabled = get_option('installed_tests')
+installed_tests_template_tap = files('template-tap.test.in')
+abs_installed_tests_execdir = join_paths(get_option('prefix'), installed_tests_execdir)
+
+if installed_tests_enabled
+ install_data(
+ 'CVE-2014-9556.cab',
+ 'CVE-2014-9732.cab',
+ 'CVE-2015-4470.cab',
+ 'CVE-2015-4471.cab',
+ 'privkey.pem',
+ 'test-mszip.cab',
+ 'test-ncbytes-overflow.cab',
+ 'test-none.cab',
+ 'test-signed.cab',
+ install_dir : installed_tests_execdir,
+ )
+ install_data(
+ 'src/test.sh',
+ 'src/test.txt',
+ install_dir : join_paths(installed_tests_execdir, 'src'),
+ )
+
+ test_conf = configuration_data()
+ test_conf.set('installed_tests_dir', abs_installed_tests_execdir)
+ test_conf.set('program', 'gcab-self-test')
+ test_conf.set('env', '')
+ configure_file(
+ input : installed_tests_template_tap,
+ output : 'gcab-self-test.test',
+ install_dir : installed_tests_metadir,
+ configuration : test_conf,
+ )
+endif
+
e = executable(
'gcab-self-test',
sources : [
@@ -16,5 +53,10 @@ e = executable(
link_with : [
libgcab,
],
+ install : installed_tests_enabled,
+ install_dir : installed_tests_execdir,
)
-test('gcab-self-test', e)
+env = environment()
+env.set('G_TEST_SRCDIR', meson.current_source_dir())
+env.set('G_TEST_BUILDDIR', meson.current_build_dir())
+test('gcab-self-test', e, env : env)
diff --git a/tests/template-tap.test.in b/tests/template-tap.test.in
new file mode 100644
index 0000000..30cd166
--- /dev/null
+++ b/tests/template-tap.test.in
@@ -0,0 +1,4 @@
+[Test]
+Type=session
+Exec=@env@@installed_tests_dir@/@program@ --tap
+Output=TAP
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]