Reduce duplication in request handler tables
[tinc] / test / unit / meson.build
1 dep_cmocka = dependency('cmocka', required: opt_tests)
2 if not dep_cmocka.found()
3   subdir_done()
4 endif
5
6 can_wrap = cc.has_link_argument('-Wl,--wrap=func')
7 if not can_wrap
8   message('linker has no support for function wrapping, mocked tests will not run')
9 endif
10
11 link_tinc = { 'lib': lib_tinc, 'dep': deps_tinc }
12 link_tincd = { 'lib': lib_tincd, 'dep': deps_tincd }
13
14 # Test definition format:
15 #
16 # 'free-form test name': {
17 #   'code': 'test1.c',      // or ['test1.c', 'test1_util.c']
18 #   'mock': ['foo', 'bar'], // list of functions to mock (default: empty)
19 #   'link': link_tinc,      // which binary to link with (default: tincd)
20 # }
21
22 tests = {
23   'net': {
24     'code': 'test_net.c',
25     'mock': ['execute_script', 'environment_init', 'environment_exit'],
26   },
27   'subnet': {
28     'code': 'test_subnet.c',
29   },
30   'protocol': {
31     'code': 'test_protocol.c',
32   },
33   'splay_tree': {
34     'code': 'test_splay_tree.c',
35     'link': link_tinc,
36   },
37 }
38
39 env = ['CMOCKA_MESSAGE_OUTPUT=TAP']
40
41 foreach test, data : tests
42   args = ld_flags
43
44   if can_wrap
45     mocks = data.get('mock', [])
46     if mocks.length() > 0
47       args += ',--wrap='.join(['-Wl'] + mocks)
48     endif
49   endif
50
51   libs = data.get('link', link_tincd)
52
53   exe = executable(test,
54                    sources: data['code'],
55                    link_args: args,
56                    dependencies: [libs['dep'], dep_cmocka],
57                    link_with: libs['lib'],
58                    implicit_include_directories: false,
59                    include_directories: inc_conf,
60                    build_by_default: false)
61
62   test(test,
63        exe,
64        suite: 'unit',
65        timeout: 60,
66        protocol: 'tap',
67        env: env)
68 endforeach
69