[json-glib] Install tests



commit d21d54f2f157b08bc91679dd0e027c450f8f9f4e
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Mar 13 13:29:33 2017 +0000

    Install tests
    
    We should install our tests in order to get them executed in
    environments like GNOME Continuous and other continuous delivery
    systems.

 Makefile.am                           |    1 +
 json-glib/tests/gen-installed-test.py |   19 +++++++++++++++++++
 json-glib/tests/meson.build           |   23 ++++++++++++++++++++++-
 meson.build                           |    1 +
 4 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 8a05190..d932b4f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,6 +8,7 @@ EXTRA_DIST = \
        doc/reference/xml/gtkdocentities.ent.in \
        json-glib/meson.build \
        json-glib/tests/meson.build \
+       json-glib/tests/gen-installed-test.py \
        po/meson.build \
        $()
 
diff --git a/json-glib/tests/gen-installed-test.py b/json-glib/tests/gen-installed-test.py
new file mode 100644
index 0000000..8fe4265
--- /dev/null
+++ b/json-glib/tests/gen-installed-test.py
@@ -0,0 +1,19 @@
+import sys
+import os
+import argparse
+
+def write_template(filename, data):
+    with open(filename, 'w') as f:
+        f.write(data)
+
+def build_template(testdir, testname):
+    return "[Test]\nType=session\nExec={}\n".format(os.path.join(testdir, testname))
+
+argparser = argparse.ArgumentParser(description='Generate installed-test data.')
+argparser.add_argument('--testdir', metavar='dir', required=True, help='Installed test directory')
+argparser.add_argument('--testname', metavar='name', required=True, help='Installed test name')
+argparser.add_argument('--outfile', metavar='file', required=True, help='Output file')
+argparser.add_argument('--outdir', metavar='dir', required=True, help='Output directory')
+args = argparser.parse_args()
+
+write_template(os.path.join(args.outdir, args.outfile), build_template(args.testdir, args.testname))
diff --git a/json-glib/tests/meson.build b/json-glib/tests/meson.build
index 9cab4bc..20c3fea 100644
--- a/json-glib/tests/meson.build
+++ b/json-glib/tests/meson.build
@@ -16,6 +16,7 @@ tests = [
 ]
 
 python3 = find_program('python3')
+gen_installed_test = join_paths(meson.current_source_dir(), 'gen-installed-test.py')
 
 test_data = [
   'stream-load.json',
@@ -29,9 +30,29 @@ foreach d: test_data
   endif
 endforeach
 
+installed_test_dir = join_paths(json_libexecdir, 'installed-tests', 'json-glib-1.0')
+
+install_data(test_data, install_dir: installed_test_dir)
+
 foreach t: tests
+  data = custom_target('@0@.test'.format(t),
+                       output: '@0@.test'.format(t),
+                       command: [
+                         python3,
+                         gen_installed_test,
+                         '--testdir=@0@'.format(installed_test_dir),
+                         '--testname=@0@.test'.format(t),
+                         '--outdir=@OUTDIR@',
+                         '--outfile=@0@.test'.format(t),
+                       ],
+                       install: true,
+                       install_dir: join_paths(json_datadir, 'installed-tests', 'json-glib-1.0'))
+
   exe = executable(t, '@0@.c'.format(t),
                    c_args: json_c_args,
+                   install: true,
+                   install_dir: installed_test_dir,
                    dependencies: [ json_glib_dep, ])
-  test(t, exe)
+
+  test(t, exe, args: [ '--tap', '-k' ])
 endforeach
diff --git a/meson.build b/meson.build
index 29d59da..57c8bef 100644
--- a/meson.build
+++ b/meson.build
@@ -36,6 +36,7 @@ json_includedir = join_paths(get_option('prefix'), get_option('includedir'))
 json_datadir = join_paths(get_option('prefix'), get_option('datadir'))
 json_mandir = join_paths(get_option('prefix'), get_option('mandir'))
 json_localedir = join_paths(get_option('prefix'), get_option('localedir'))
+json_libexecdir = join_paths(get_option('prefix'), get_option('libexecdir'))
 
 # Dependencies
 glib_req_version = '>= 2.37.6'


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]