[gnome-photos/wip/rishi/unit-tests: 4/5] tests: Add a harness for unit tests



commit e243c276b3aae5ff23dd9699759371fec16d7fc3
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Oct 23 20:43:27 2018 +0200

    tests: Add a harness for unit tests
    
    The actual tests will be added in subsequent commits.

 configure.ac           |  1 +
 meson.build            |  3 +++
 template-tap.test.in   |  4 ++++
 tests/Makefile.am      |  2 ++
 tests/meson.build      |  2 ++
 tests/unit/Makefile.am | 18 ++++++++++++++++
 tests/unit/meson.build | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 88 insertions(+)
---
diff --git a/configure.ac b/configure.ac
index e399bdf5..274a4cb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,7 @@ help/Makefile
 subprojects/libgd/Makefile
 src/Makefile
 tests/Makefile
+tests/unit/Makefile
 po/Makefile.in
 ])
 AC_OUTPUT
diff --git a/meson.build b/meson.build
index 2b492062..62882972 100644
--- a/meson.build
+++ b/meson.build
@@ -23,12 +23,15 @@ photos_namespace = 'org.gnome.Photos'
 photos_buildtype = get_option('buildtype')
 photos_installed_tests_enabled = get_option('installed_tests')
 
+photos_installed_tests_template_tap = files('template-tap.test.in')
+
 gnome = import('gnome')
 i18n = import('i18n')
 
 source_root = meson.current_source_dir()
 po_dir = join_paths(source_root, 'po')
 
+src_inc = include_directories('src')
 top_inc = include_directories('.')
 
 photos_commit_id = ''
diff --git a/template-tap.test.in b/template-tap.test.in
new file mode 100644
index 00000000..6adf73f0
--- /dev/null
+++ b/template-tap.test.in
@@ -0,0 +1,4 @@
+[Test]
+Type=session
+Exec=@installed_tests_dir@/@program@ --tap
+Output=TAP
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2a1a7745..9bf271e9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,7 @@
 include $(top_srcdir)/glib-tap.mk
 
+SUBDIRS = unit
+
 dogtail_tests = \
        basic.py \
        $(NULL)
diff --git a/tests/meson.build b/tests/meson.build
index e4396f05..eea33e20 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,3 +1,5 @@
+subdir('unit')
+
 test_name = 'basic.py'
 
 if photos_installed_tests_enabled
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
new file mode 100644
index 00000000..690c96f6
--- /dev/null
+++ b/tests/unit/Makefile.am
@@ -0,0 +1,18 @@
+include $(top_srcdir)/glib-tap.mk
+
+AM_TESTS_ENVIRONMENT += \
+       GSETTINGS_BACKEND=memory \
+       $(NULL)
+
+test_programs = \
+       $(NULL)
+
+AM_CFLAGS = \
+       $(WARN_CFLAGS) \
+       $(NULL)
+
+AM_LDFLAGS = \
+       $(WARN_LDFLAGS) \
+       $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
new file mode 100644
index 00000000..27aca94e
--- /dev/null
+++ b/tests/unit/meson.build
@@ -0,0 +1,58 @@
+# Not entirely random of course, but at least it changes over time
+meson_minor_version = meson.version().split('.').get(1).to_int()
+photos_minor_version = meson.project_version().split('.').get(1).to_int()
+random_number = meson_minor_version + photos_minor_version
+
+test_env = environment()
+test_env.set('G_DEBUG', 'gc-friendly')
+test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
+test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
+test_env.set('GSETTINGS_BACKEND', 'memory')
+test_env.set('MALLOC_CHECK_', '2')
+test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
+
+tests = {
+}
+
+foreach test_name, extra_args: tests
+  deps = extra_args.get('dependencies', [])
+  extra_sources = extra_args.get('extra_sources', [])
+  install = photos_installed_tests_enabled and extra_args.get('install', true)
+  is_parallel = extra_args.get('is_parallel', true)
+  source = extra_args.get('source', test_name + '.c')
+  suite = extra_args.get('suite', [])
+
+  if install
+    test_conf = configuration_data()
+    test_conf.set('installed_tests_dir', photos_installed_test_execdir)
+    test_conf.set('program', test_name)
+    configure_file(
+      input: photos_installed_tests_template_tap,
+      output: test_name + '.test',
+      configuration: test_conf,
+      install: true,
+      install_dir: photos_installed_test_metadir,
+    )
+  endif
+
+  exe = executable(
+    test_name,
+    [source, extra_sources],
+    include_directories: [src_inc, top_inc],
+    dependencies: deps,
+    install: install,
+    install_dir: photos_installed_test_execdir,
+    install_rpath: photos_libdir,
+  )
+
+  timeout = suite.contains('slow') ? 120 : 30
+  test(
+    test_name,
+    exe,
+    env: test_env,
+    timeout: timeout,
+    suite: suite,
+    args: ['--tap'],
+    is_parallel: is_parallel,
+  )
+endforeach


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