Skip to content

Commit

Permalink
self-test: Optionally install for as-installed testing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
smcv committed Sep 2, 2019
1 parent a57e5d6 commit 48e80ea
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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')
9 changes: 1 addition & 8 deletions tests/gcab-self-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 43 additions & 1 deletion tests/meson.build
Original file line number Diff line number Diff line change
@@ -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 : [
Expand All @@ -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)
4 changes: 4 additions & 0 deletions tests/template-tap.test.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Test]
Type=session
Exec=@env@@installed_tests_dir@/@program@ --tap
Output=TAP

0 comments on commit 48e80ea

Please sign in to comment.