Added unit test

pull/4547/head
Daniel Mensinger 6 years ago
parent 24d668bea0
commit c4eb5c79fe
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 2
      mesonbuild/build.py
  2. 2
      mesonbuild/compilers/cs.py
  3. 2
      mesonbuild/compilers/java.py
  4. 2
      mesonbuild/compilers/swift.py
  5. 3
      mesonbuild/msetup.py
  6. 145
      run_unittests.py
  7. 14
      test cases/unit/49 introspection/meson.build
  8. 2
      test cases/unit/49 introspection/sharedlib/meson.build
  9. 9
      test cases/unit/49 introspection/sharedlib/shared.cpp
  10. 10
      test cases/unit/49 introspection/sharedlib/shared.hpp
  11. 2
      test cases/unit/49 introspection/staticlib/meson.build
  12. 5
      test cases/unit/49 introspection/staticlib/static.c
  13. 3
      test cases/unit/49 introspection/staticlib/static.h
  14. 13
      test cases/unit/49 introspection/t1.cpp
  15. 8
      test cases/unit/49 introspection/t2.cpp
  16. 16
      test cases/unit/49 introspection/t3.cpp

@ -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':

@ -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):

@ -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):

@ -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):

@ -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)

@ -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 = {}

@ -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)

@ -0,0 +1,2 @@
SRC_shared = ['shared.cpp']
sharedlib = shared_library('sharedTestLib', SRC_shared)

@ -0,0 +1,9 @@
#include "shared.hpp"
void SharedClass::doStuff() {
number++;
}
int SharedClass::getNumber() const {
return number;
}

@ -0,0 +1,10 @@
#pragma once
class SharedClass {
private:
int number = 42;
public:
SharedClass() = default;
void doStuff();
int getNumber() const;
};

@ -0,0 +1,2 @@
SRC_static = ['static.c']
staticlib = static_library('staticTestLib', SRC_static)

@ -0,0 +1,5 @@
#include "static.h"
int add_numbers(int a, int b) {
return a + b;
}

@ -0,0 +1,3 @@
#pragma once
int add_numbers(int a, int b);

@ -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;
}

@ -0,0 +1,8 @@
#include "staticlib/static.h"
int main() {
if(add_numbers(1, 2) != 3) {
return 1;
}
return 0;
}

@ -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;
}
Loading…
Cancel
Save