[tracker/wip/carlosg/optional-tap: 1/2] build: Add meson option to enable TAP protocol in tests




commit 15c0d7845740050346f050250d2b74d1f8b4a1bd
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Mar 22 01:30:32 2021 +0100

    build: Add meson option to enable TAP protocol in tests
    
    Together with our C tests we have our python functional test framework,
    which requires the use of TAPTestRunner from tap.py.
    
    Add a config switch, so that we don't need the python library (or behave
    strangely in functional tests without it) in developer setups, and can
    enable specifically in CI.

 meson_options.txt                            |  2 ++
 tests/functional-tests/configuration.json.in |  1 +
 tests/functional-tests/configuration.py      |  4 ++++
 tests/functional-tests/fixtures.py           | 14 ++++++++------
 tests/functional-tests/meson.build           |  9 ++++++++-
 tests/meson.build                            |  8 +++++++-
 6 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/meson_options.txt b/meson_options.txt
index fc0810664..99c569502 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -24,3 +24,5 @@ option('test_utils', type: 'boolean', value: true,
        description: 'Whether to install the trackertestutils Python package')
 option('test_utils_dir', type: 'string', value: '',
        description: 'Directory to install trackertestutils Python package (or empty to use the default)')
+option('tests_tap_protocol', type: 'boolean', value: false,
+       description: 'Whether to enable TAP protocol on tests')
diff --git a/tests/functional-tests/configuration.json.in b/tests/functional-tests/configuration.json.in
index ecbea53ca..65f2c0bbe 100644
--- a/tests/functional-tests/configuration.json.in
+++ b/tests/functional-tests/configuration.json.in
@@ -3,5 +3,6 @@
     "TEST_ONTOLOGIES_DIR": "@TEST_ONTOLOGIES_DIR@",
     "TEST_DBUS_DAEMON_CONFIG_FILE": "@TEST_DBUS_DAEMON_CONFIG_FILE@",
     "TEST_PORTAL_FLATPAK_INFO": "@TEST_PORTAL_FLATPAK_INFO@",
+    "TEST_TAP_ENABLED": "@TEST_TAP_ENABLED@",
     "TRACKER_VERSION": "@TRACKER_VERSION@"
 }
diff --git a/tests/functional-tests/configuration.py b/tests/functional-tests/configuration.py
index cb1bc9a2b..649959888 100644
--- a/tests/functional-tests/configuration.py
+++ b/tests/functional-tests/configuration.py
@@ -53,6 +53,10 @@ def tracker_version():
     return config['TRACKER_VERSION']
 
 
+def tap_protocol_enabled():
+    return config['TEST_TAP_ENABLED']
+
+
 TRACKER_DEBUG_TESTS = 1
 
 def tests_verbose():
diff --git a/tests/functional-tests/fixtures.py b/tests/functional-tests/fixtures.py
index 2e338ed81..1f3fa6baf 100644
--- a/tests/functional-tests/fixtures.py
+++ b/tests/functional-tests/fixtures.py
@@ -65,12 +65,14 @@ def tracker_test_main():
 
     runner = None
 
-    try:
-        from tap import TAPTestRunner
-        runner = TAPTestRunner()
-        runner.set_stream(True)
-    except ImportError as e:
-        log.info('No TAP test runner found: %s', e)
+    if cfg.tap_protocol_enabled():
+        try:
+            from tap import TAPTestRunner
+            runner = TAPTestRunner()
+            runner.set_stream(True)
+        except ImportError as e:
+            log.error('No TAP test runner found: %s', e)
+            raise
 
     ut.main(testRunner=runner, verbosity=2)
 
diff --git a/tests/functional-tests/meson.build b/tests/functional-tests/meson.build
index 50d47e2ac..70130f65e 100644
--- a/tests/functional-tests/meson.build
+++ b/tests/functional-tests/meson.build
@@ -9,6 +9,7 @@ testconf.set('TEST_ONTOLOGIES_DIR', tracker_uninstalled_nepomuk_ontologies_dir)
 testconf.set('TEST_DBUS_DAEMON_CONFIG_FILE', build_root / 'tests' / 'test-bus.conf')
 testconf.set('TEST_PORTAL_FLATPAK_INFO', source_root / 'tests' / 'flatpak-info')
 testconf.set('TRACKER_VERSION', meson.project_version())
+testconf.set('TEST_TAP_ENABLED', get_option('tests_tap_protocol'))
 
 config_json = configure_file(
   input: 'configuration.json.in',
@@ -39,12 +40,18 @@ test_env.prepend('LD_LIBRARY_PATH', tracker_sparql_uninstalled_dir)
 test_env.prepend('PYTHONPATH', tracker_uninstalled_testutils_dir)
 test_env.set('TRACKER_FUNCTIONAL_TEST_CONFIG', config_json_full_path)
 
+if get_option('tests_tap_protocol')
+  protocol = 'tap'
+else
+  protocol = 'exitcode'
+endif
+
 foreach test_name: functional_tests
   file = meson.current_source_dir() / '@0@.py'.format(test_name)
   test(test_name, python,
     args: [file],
     env: test_env,
-    protocol: 'tap',
+    protocol: protocol,
     suite: ['functional'],
     timeout: 60)
 endforeach
diff --git a/tests/meson.build b/tests/meson.build
index 5f5855d70..3a543051b 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -15,6 +15,12 @@ subdir('libtracker-sparql')
 subdir('functional-tests')
 subdir('services')
 
+if get_option('tests_tap_protocol')
+  protocol = 'tap'
+else
+  protocol = 'exitcode'
+endif
+
 foreach t: tests
   test_name = t.get('name')
   test_exe = t.get('exe')
@@ -32,7 +38,7 @@ foreach t: tests
   test(test_name, test_exe,
     env: test_env,
     timeout: test_timeout,
-    protocol: 'tap',
+    protocol: protocol,
     suite: test_suite,
     is_parallel: test_is_parallel)
 endforeach


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