[gjs/wip/3v1n0/toggle-queue-tests: 1/4] tests: Move internal API tests into a different test binary




commit ed6370b90613d4743d5c2a8e568fba0e2f731a8e
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Sun May 16 16:50:18 2021 +0200

    tests: Move internal API tests into a different test binary

 installed-tests/js/libgjstesttools/meson.build |  3 ++
 meson.build                                    | 43 +++++++++++++++++---------
 test/gjs-tests-internal.cpp                    | 25 +++++++++++++++
 test/gjs-tests.cpp                             |  3 --
 test/meson.build                               | 36 ++++++++++++++++-----
 5 files changed, 85 insertions(+), 25 deletions(-)
---
diff --git a/installed-tests/js/libgjstesttools/meson.build b/installed-tests/js/libgjstesttools/meson.build
index 036d7076..2e57483a 100644
--- a/installed-tests/js/libgjstesttools/meson.build
+++ b/installed-tests/js/libgjstesttools/meson.build
@@ -17,3 +17,6 @@ gjstest_tools_gir = gnome.generate_gir(libgjstesttools,
     install: get_option('installed_tests'), install_dir_gir: false,
     install_dir_typelib: installed_tests_execdir)
 gjstest_tools_typelib = gjstest_tools_gir[1]
+libgjstesttools_dep = declare_dependency(
+    link_with: libgjstesttools,
+    include_directories: include_directories('.'))
diff --git a/meson.build b/meson.build
index 3cf75661..15701d47 100644
--- a/meson.build
+++ b/meson.build
@@ -504,13 +504,28 @@ if get_option('b_pch') and not meson.version().version_compare('>= 0.58.1')
     endif
 endif
 
+# This dependency should provide everything that is needed to compile gjs except
+# the sources themselves, is used to copmile both the static libraries and the
+# tests
+base_build_dep = declare_dependency(
+    compile_args: libgjs_cpp_args,
+    dependencies: libgjs_dependencies)
+
 libgjs_jsapi = static_library(meson.project_name() + '-jsapi',
     libgjs_jsapi_sources, probes_header, probes_objfile,
     cpp_args: libgjs_cpp_args,
-    dependencies: libgjs_dependencies,
     cpp_pch: pch_headers,
+    dependencies: base_build_dep,
     install: false)
 
+# We need to create an internal static library to be able to link with the tests
+# that may use internal APIs. This is also used to generate the actual shared
+# library so that we compile its sources just once.
+libgjs_internal = static_library('gjs-internal',
+    libgjs_sources, probes_header, probes_objfile,
+    dependencies: base_build_dep,
+    link_with: libgjs_jsapi)
+
 link_args = []
 symbol_map = files('libgjs.map')
 symbol_list = files('libgjs.symbols')
@@ -522,13 +537,11 @@ link_args += cxx.get_supported_link_arguments([
 ])
 
 libgjs = shared_library(meson.project_name(),
-    libgjs_sources, libgjs_private_sources, module_resource_srcs,
-    probes_header, probes_objfile,
-    cpp_args: libgjs_cpp_args,
-    link_args: link_args, link_depends: [symbol_map, symbol_list],
-    link_with: libgjs_jsapi,
-    dependencies: libgjs_dependencies,
+    sources: [ libgjs_private_sources, module_resource_srcs ],
     cpp_pch: pch_headers,
+    link_args: link_args, link_depends: [symbol_map, symbol_list],
+    link_whole: libgjs_internal,
+    dependencies: base_build_dep,
     version: '0.0.0', soversion: '0',
     gnu_symbol_visibility: 'hidden',
     install: true)
@@ -537,7 +550,7 @@ install_headers(gjs_public_headers, subdir: api_name / 'gjs')
 
 # Allow using libgjs as a subproject
 libgjs_dep = declare_dependency(link_with: [libgjs, libgjs_jsapi],
-    dependencies: libgjs_dependencies, include_directories: top_include)
+    dependencies: base_build_dep, include_directories: top_include)
 
 ### Build GjsPrivate introspection library #####################################
 
@@ -553,7 +566,6 @@ gjs_private_typelib = gjs_private_gir[1]
 gjs_console_srcs = ['gjs/console.cpp']
 
 gjs_console = executable('gjs-console', gjs_console_srcs,
-    cpp_args: libgjs_cpp_args,
     dependencies: libgjs_dep, install: true)
 
 meson.add_install_script('build/symlink-gjs.py', get_option('bindir'))
@@ -595,6 +607,7 @@ libgjs_test_tools_builddir = js_tests_builddir / 'libgjstesttools'
 tests_environment.set('TOP_BUILDDIR', meson.build_root())
 tests_environment.set('GJS_USE_UNINSTALLED_FILES', '1')
 tests_environment.set('GJS_PATH', '')
+tests_environment.set('GJS_DEBUG_OUTPUT', 'stderr')
 tests_environment.prepend('GI_TYPELIB_PATH', meson.current_build_dir(),
     js_tests_builddir, libgjs_test_tools_builddir)
 tests_environment.prepend('LD_LIBRARY_PATH', meson.current_build_dir(),
@@ -634,18 +647,18 @@ endif
 
 ### Tests and test setups ######################################################
 
-# Note: The test program in test/ needs to be ported
-#       to Windows before we can build it on Windows.
-if host_machine.system() != 'windows'
-    subdir('test')
-endif
-
 if not get_option('skip_gtk_tests')
     have_gtk4 = dependency('gtk4', required: false).found()
 endif
 
 subdir('installed-tests')
 
+# Note: The test program in test/ needs to be ported
+#       to Windows before we can build it on Windows.
+if host_machine.system() != 'windows'
+    subdir('test')
+endif
+
 valgrind_environment = environment()
 valgrind_environment.set('G_SLICE', 'always-malloc,debug-blocks')
 valgrind_environment.set('G_DEBUG',
diff --git a/test/gjs-tests-internal.cpp b/test/gjs-tests-internal.cpp
new file mode 100644
index 00000000..4f8f74ba
--- /dev/null
+++ b/test/gjs-tests-internal.cpp
@@ -0,0 +1,25 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+// SPDX-FileCopyrightText: 2021 Canonical, Ltd.
+// SPDX-FileContributor: Marco Trevisan <marco trevisan canonical com>
+
+#include <config.h>
+#include <glib.h>
+
+#include "test/gjs-test-utils.h"
+
+int main(int argc, char** argv) {
+    /* Avoid interference in the tests from stray environment variable */
+    g_unsetenv("GJS_ENABLE_PROFILER");
+    g_unsetenv("GJS_TRACE_FD");
+
+    g_test_init(&argc, &argv, nullptr);
+
+    gjs_test_add_tests_for_rooting();
+    gjs_test_add_tests_for_parse_call_args();
+    gjs_test_add_tests_for_jsapi_utils();
+
+    g_test_run();
+
+    return 0;
+}
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index 79098610..60928c22 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -955,9 +955,6 @@ main(int    argc,
 #undef ADD_JSAPI_UTIL_TEST
 
     gjs_test_add_tests_for_coverage ();
-    gjs_test_add_tests_for_parse_call_args();
-    gjs_test_add_tests_for_rooting();
-    gjs_test_add_tests_for_jsapi_utils();
 
     g_test_run();
 
diff --git a/test/meson.build b/test/meson.build
index 83c63067..bf6f10c2 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -7,21 +7,43 @@ mock_js_resources_files = gnome.compile_resources('mock-js-resources',
     'mock-js-resources.gresource.xml', c_name: 'mock_js_resources',
     source_dir: '..')
 
+libgjs_tests_common = static_library('gjs-tests-common',
+    sources: [
+        'gjs-test-utils.cpp', 'gjs-test-utils.h',
+        'gjs-test-common.cpp', 'gjs-test-common.h',
+    ],
+    cpp_args: libgjs_cpp_args,
+    include_directories: top_include, dependencies: libgjs_dependencies,
+)
+
 gjs_tests_sources = [
     'gjs-tests.cpp',
-    'gjs-test-common.cpp', 'gjs-test-common.h',
-    'gjs-test-utils.cpp', 'gjs-test-utils.h',
-    'gjs-test-call-args.cpp',
     'gjs-test-coverage.cpp',
-    'gjs-test-rooting.cpp',
-    'gjs-test-jsapi-utils.cpp',
     'gjs-test-no-introspection-object.cpp', 'gjs-test-no-introspection-object.h',
 ]
 
 gjs_tests = executable('gjs-tests', gjs_tests_sources, mock_js_resources_files,
-    cpp_args: ['-DGJS_COMPILATION'] + directory_defines,
-    include_directories: top_include, dependencies: libgjs_dep)
+    include_directories: top_include, dependencies: libgjs_dep,
+    link_with: libgjs_tests_common)
 
 test('API tests', gjs_tests, args: ['--tap', '--keep-going', '--verbose'],
     depends: gjs_private_typelib, env: tests_environment, protocol: 'tap',
     suite: 'C', timeout: 60)
+
+gjs_tests_internal = executable('gjs-tests-internal',
+    sources: [
+        'gjs-tests-internal.cpp',
+        'gjs-test-call-args.cpp',
+        'gjs-test-rooting.cpp',
+        'gjs-test-jsapi-utils.cpp',
+        module_resource_srcs,
+    ],
+    include_directories: top_include,
+    cpp_args: libgjs_cpp_args,
+    dependencies: [libgjs_dependencies, libgjstesttools_dep],
+    link_with: [libgjs_tests_common, libgjs_internal])
+
+test('Internal API tests', gjs_tests_internal,
+    args: ['--tap', '--keep-going', '--verbose'],
+    env: tests_environment, protocol: 'tap',
+    suite: ['C', 'thread-safe'])


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