aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2018-11-29 12:56:52 +0100
committerDaniel Mensinger <daniel@mensinger-ka.de>2019-01-06 12:19:28 +0100
commitc4eb5c79fe89ca49dd9d9f5bd72be99d919dd2a0 (patch)
treed32bb616886be379b602760ac8f42095a8f4ad0d
parent24d668bea06b3b953855fa12ef2f5b417d4dd163 (diff)
downloadmeson-c4eb5c79fe89ca49dd9d9f5bd72be99d919dd2a0.zip
meson-c4eb5c79fe89ca49dd9d9f5bd72be99d919dd2a0.tar.gz
meson-c4eb5c79fe89ca49dd9d9f5bd72be99d919dd2a0.tar.bz2
Added unit test
-rw-r--r--mesonbuild/build.py2
-rw-r--r--mesonbuild/compilers/cs.py2
-rw-r--r--mesonbuild/compilers/java.py2
-rw-r--r--mesonbuild/compilers/swift.py2
-rw-r--r--mesonbuild/msetup.py3
-rwxr-xr-xrun_unittests.py145
-rw-r--r--test cases/unit/49 introspection/meson.build14
-rw-r--r--test cases/unit/49 introspection/sharedlib/meson.build2
-rw-r--r--test cases/unit/49 introspection/sharedlib/shared.cpp9
-rw-r--r--test cases/unit/49 introspection/sharedlib/shared.hpp10
-rw-r--r--test cases/unit/49 introspection/staticlib/meson.build2
-rw-r--r--test cases/unit/49 introspection/staticlib/static.c5
-rw-r--r--test cases/unit/49 introspection/staticlib/static.h3
-rw-r--r--test cases/unit/49 introspection/t1.cpp13
-rw-r--r--test cases/unit/49 introspection/t2.cpp8
-rw-r--r--test cases/unit/49 introspection/t3.cpp16
16 files changed, 216 insertions, 22 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 1054451..4fa6bde 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1515,7 +1515,6 @@ class SharedLibrary(BuildTarget):
known_kwargs = known_shlib_kwargs
def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs):
- self.typename = 'shared library'
self.soversion = None
self.ltversion = None
# Max length 2, first element is compatibility_version, second is current_version
@@ -1528,6 +1527,7 @@ class SharedLibrary(BuildTarget):
# The import library that GCC would generate (and prefer)
self.gcc_import_filename = None
super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs)
+ self.typename = 'shared library'
if 'rust' in self.compilers:
# If no crate type is specified, or it's the generic lib type, use dylib
if not hasattr(self, 'rust_crate_type') or self.rust_crate_type == 'lib':
diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py
index 95b1603..a6c74d2 100644
--- a/mesonbuild/compilers/cs.py
+++ b/mesonbuild/compilers/cs.py
@@ -82,7 +82,7 @@ class CsCompiler(Compiler):
def get_std_exe_link_args(self):
return []
- def get_include_args(self, path, is_system):
+ def get_include_args(self, path):
return []
def get_pic_args(self):
diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py
index 686d2e0..978562c 100644
--- a/mesonbuild/compilers/java.py
+++ b/mesonbuild/compilers/java.py
@@ -63,7 +63,7 @@ class JavaCompiler(Compiler):
def get_std_exe_link_args(self):
return []
- def get_include_args(self, path, is_system):
+ def get_include_args(self, path):
return []
def get_pic_args(self):
diff --git a/mesonbuild/compilers/swift.py b/mesonbuild/compilers/swift.py
index c156541..4d5dd0c 100644
--- a/mesonbuild/compilers/swift.py
+++ b/mesonbuild/compilers/swift.py
@@ -85,7 +85,7 @@ class SwiftCompiler(Compiler):
def build_rpath_args(self, *args):
return [] # FIXME
- def get_include_args(self, dirname, is_system):
+ def get_include_args(self, dirname):
return ['-I' + dirname]
def get_compile_only_args(self):
diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py
index 491ea2f..402f756 100644
--- a/mesonbuild/msetup.py
+++ b/mesonbuild/msetup.py
@@ -218,9 +218,6 @@ class MesonApp:
coredata.update_cmd_line_file(self.build_dir, self.options)
# Generate an IDE introspection file with the same syntax as the already existing API
- intro_tests = intr.backend.create_test_serialisation(b.get_tests())
- intro_benchmarks = intr.backend.create_test_serialisation(b.get_benchmarks())
- intro_install = intr.backend.create_install_data()
if self.options.profile:
fname = os.path.join(self.build_dir, 'meson-private', 'profile-introspector.log')
profile.runctx('mintro.generate_introspection_file(b, intr.backend)', globals(), locals(), filename=fname)
diff --git a/run_unittests.py b/run_unittests.py
index 9120a43..811df6b 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -3110,26 +3110,141 @@ recommended as it is not supported on some platforms''')
self.maxDiff = None
self.assertListEqual(res_nb, res_wb)
- def test_introspect_all_command(self):
- testdir = os.path.join(self.common_test_dir, '6 linkshared')
+ def test_introspect_json_dump(self):
+ testdir = os.path.join(self.unit_test_dir, '49 introspection')
self.init(testdir)
- res = self.introspect('--all')
- keylist = [
- 'benchmarks',
- 'buildoptions',
- 'buildsystem_files',
- 'dependencies',
- 'installed',
- 'projectinfo',
- 'targets',
- 'tests'
+ introfile = os.path.join(self.builddir, 'meson-introspection.json')
+ self.assertPathExists(introfile)
+ with open(introfile, 'r') as fp:
+ res = json.load(fp)
+
+ def assertKeyTypes(key_type_list, obj):
+ for i in key_type_list:
+ self.assertIn(i[0], obj)
+ self.assertIsInstance(obj[i[0]], i[1])
+
+ root_keylist = [
+ ('benchmarks', list),
+ ('buildoptions', list),
+ ('buildsystem_files', list),
+ ('dependencies', list),
+ ('installed', dict),
+ ('projectinfo', dict),
+ ('targets', list),
+ ('tests', list),
+ ]
+
+ test_keylist = [
+ ('cmd', list),
+ ('env', dict),
+ ('name', str),
+ ('timeout', int),
+ ('suite', list),
+ ('is_parallel', bool),
+ ]
+
+ buildoptions_keylist = [
+ ('name', str),
+ ('section', str),
+ ('type', str),
+ ('description', str),
+ ]
+
+ buildoptions_typelist = [
+ ('combo', str, [('choices', list)]),
+ ('string', str, []),
+ ('boolean', bool, []),
+ ('integer', int, []),
+ ('array', list, []),
+ ]
+
+ dependencies_typelist = [
+ ('name', str),
+ ('compile_args', list),
+ ('link_args', list),
+ ]
+
+ targets_typelist = [
+ ('name', str),
+ ('id', str),
+ ('type', str),
+ ('filename', str),
+ ('build_by_default', bool),
+ ('sources', list),
+ ('installed', bool),
+ ]
+
+ targets_sources_typelist = [
+ ('language', str),
+ ('compiler', list),
+ ('parameters', list),
+ ('source_files', list),
]
- for i in keylist:
- self.assertIn(i, res)
+ assertKeyTypes(root_keylist, res)
+
+ # Check Tests and benchmarks
+ tests_to_find = ['test case 1', 'test case 2', 'benchmark 1']
+ for i in res['benchmarks'] + res['tests']:
+ assertKeyTypes(test_keylist, i)
+ if i['name'] in tests_to_find:
+ tests_to_find.remove(i['name'])
+ self.assertListEqual(tests_to_find, [])
+
+ # Check buildoptions
+ buildopts_to_find = {'cpp_std': 'c++11'}
+ for i in res['buildoptions']:
+ assertKeyTypes(buildoptions_keylist, i)
+ valid_type = False
+ for j in buildoptions_typelist:
+ if i['type'] == j[0]:
+ self.assertIsInstance(i['value'], j[1])
+ assertKeyTypes(j[2], i)
+ valid_type = True
+ break
+
+ self.assertTrue(valid_type)
+ if i['name'] in buildopts_to_find:
+ self.assertEqual(i['value'], buildopts_to_find[i['name']])
+ buildopts_to_find.pop(i['name'], None)
+ self.assertDictEqual(buildopts_to_find, {})
+
+ # Check buildsystem_files
+ self.assertListEqual(res['buildsystem_files'], ['meson.build', 'sharedlib/meson.build', 'staticlib/meson.build'])
+
+ # Check dependencies
+ dependencies_to_find = ['zlib']
+ for i in res['dependencies']:
+ assertKeyTypes(dependencies_typelist, i)
+ if i['name'] in dependencies_to_find:
+ dependencies_to_find.remove(i['name'])
+ self.assertListEqual(dependencies_to_find, [])
+
+ # Check projectinfo
+ self.assertDictEqual(res['projectinfo'], {'version': '1.2.3', 'descriptive_name': 'introspection', 'subprojects': []})
+
+ # Check targets
+ targets_to_find = {
+ 'sharedTestLib': ('shared library', True, False),
+ 'staticTestLib': ('static library', True, False),
+ 'test1': ('executable', True, True),
+ 'test2': ('executable', True, False),
+ 'test3': ('executable', True, False),
+ }
+ for i in res['targets']:
+ assertKeyTypes(targets_typelist, i)
+ if i['name'] in targets_to_find:
+ tgt = targets_to_find[i['name']]
+ self.assertEqual(i['type'], tgt[0])
+ self.assertEqual(i['build_by_default'], tgt[1])
+ self.assertEqual(i['installed'], tgt[2])
+ targets_to_find.pop(i['name'], None)
+ for j in i['sources']:
+ assertKeyTypes(targets_sources_typelist, j)
+ self.assertDictEqual(targets_to_find, {})
def test_introspect_file_dump_eauals_all(self):
- testdir = os.path.join(self.common_test_dir, '6 linkshared')
+ testdir = os.path.join(self.unit_test_dir, '49 introspection')
self.init(testdir)
res_all = self.introspect('--all')
res_file = {}
diff --git a/test cases/unit/49 introspection/meson.build b/test cases/unit/49 introspection/meson.build
new file mode 100644
index 0000000..bd5d51a
--- /dev/null
+++ b/test cases/unit/49 introspection/meson.build
@@ -0,0 +1,14 @@
+project('introspection', ['c', 'cpp'], version: '1.2.3', default_options: ['cpp_std=c++11'])
+
+dep1 = dependency('zlib')
+
+subdir('sharedlib')
+subdir('staticlib')
+
+t1 = executable('test1', 't1.cpp', link_with: [sharedlib], install: true)
+t2 = executable('test2', 't2.cpp', link_with: [staticlib])
+t3 = executable('test3', 't3.cpp', link_with: [sharedlib, staticlib], dependencies: [dep1])
+
+test('test case 1', t1)
+test('test case 2', t2)
+benchmark('benchmark 1', t3)
diff --git a/test cases/unit/49 introspection/sharedlib/meson.build b/test cases/unit/49 introspection/sharedlib/meson.build
new file mode 100644
index 0000000..3de3493
--- /dev/null
+++ b/test cases/unit/49 introspection/sharedlib/meson.build
@@ -0,0 +1,2 @@
+SRC_shared = ['shared.cpp']
+sharedlib = shared_library('sharedTestLib', SRC_shared)
diff --git a/test cases/unit/49 introspection/sharedlib/shared.cpp b/test cases/unit/49 introspection/sharedlib/shared.cpp
new file mode 100644
index 0000000..5030ab7
--- /dev/null
+++ b/test cases/unit/49 introspection/sharedlib/shared.cpp
@@ -0,0 +1,9 @@
+#include "shared.hpp"
+
+void SharedClass::doStuff() {
+ number++;
+}
+
+int SharedClass::getNumber() const {
+ return number;
+}
diff --git a/test cases/unit/49 introspection/sharedlib/shared.hpp b/test cases/unit/49 introspection/sharedlib/shared.hpp
new file mode 100644
index 0000000..dc9b2da
--- /dev/null
+++ b/test cases/unit/49 introspection/sharedlib/shared.hpp
@@ -0,0 +1,10 @@
+#pragma once
+
+class SharedClass {
+ private:
+ int number = 42;
+ public:
+ SharedClass() = default;
+ void doStuff();
+ int getNumber() const;
+}; \ No newline at end of file
diff --git a/test cases/unit/49 introspection/staticlib/meson.build b/test cases/unit/49 introspection/staticlib/meson.build
new file mode 100644
index 0000000..b1b9afe
--- /dev/null
+++ b/test cases/unit/49 introspection/staticlib/meson.build
@@ -0,0 +1,2 @@
+SRC_static = ['static.c']
+staticlib = static_library('staticTestLib', SRC_static)
diff --git a/test cases/unit/49 introspection/staticlib/static.c b/test cases/unit/49 introspection/staticlib/static.c
new file mode 100644
index 0000000..37ebc0d
--- /dev/null
+++ b/test cases/unit/49 introspection/staticlib/static.c
@@ -0,0 +1,5 @@
+#include "static.h"
+
+int add_numbers(int a, int b) {
+ return a + b;
+} \ No newline at end of file
diff --git a/test cases/unit/49 introspection/staticlib/static.h b/test cases/unit/49 introspection/staticlib/static.h
new file mode 100644
index 0000000..506784e
--- /dev/null
+++ b/test cases/unit/49 introspection/staticlib/static.h
@@ -0,0 +1,3 @@
+#pragma once
+
+int add_numbers(int a, int b); \ No newline at end of file
diff --git a/test cases/unit/49 introspection/t1.cpp b/test cases/unit/49 introspection/t1.cpp
new file mode 100644
index 0000000..2bcaab8
--- /dev/null
+++ b/test cases/unit/49 introspection/t1.cpp
@@ -0,0 +1,13 @@
+#include "sharedlib/shared.hpp"
+
+int main() {
+ SharedClass cl1;
+ if(cl1.getNumber() != 42) {
+ return 1;
+ }
+ cl1.doStuff();
+ if(cl1.getNumber() != 43) {
+ return 2;
+ }
+ return 0;
+}
diff --git a/test cases/unit/49 introspection/t2.cpp b/test cases/unit/49 introspection/t2.cpp
new file mode 100644
index 0000000..fee5097
--- /dev/null
+++ b/test cases/unit/49 introspection/t2.cpp
@@ -0,0 +1,8 @@
+#include "staticlib/static.h"
+
+int main() {
+ if(add_numbers(1, 2) != 3) {
+ return 1;
+ }
+ return 0;
+}
diff --git a/test cases/unit/49 introspection/t3.cpp b/test cases/unit/49 introspection/t3.cpp
new file mode 100644
index 0000000..8a906e0
--- /dev/null
+++ b/test cases/unit/49 introspection/t3.cpp
@@ -0,0 +1,16 @@
+#include "sharedlib/shared.hpp"
+#include "staticlib/static.h"
+
+int main() {
+ for(int i = 0; i < 1000; add_numbers(i, 1)) {
+ SharedClass cl1;
+ if(cl1.getNumber() != 42) {
+ return 1;
+ }
+ cl1.doStuff();
+ if(cl1.getNumber() != 43) {
+ return 2;
+ }
+ }
+ return 0;
+}