William A. Kennington III | 0a01b2a | 2021-05-13 18:38:57 -0700 | [diff] [blame] | 1 | gtest = dependency('gtest', main: true, disabler: true, required: false) |
| 2 | gmock = dependency('gmock', disabler: true, required: false) |
| 3 | if not gtest.found() or not gmock.found() |
| 4 | gtest_opts = import('cmake').subproject_options() |
| 5 | gtest_opts.add_cmake_defines({'CMAKE_CXX_FLAGS': '-Wno-pedantic'}) |
| 6 | gtest_proj = import('cmake').subproject( |
| 7 | 'googletest', |
| 8 | options: gtest_opts, |
| 9 | required: false) |
| 10 | if gtest_proj.found() |
| 11 | gtest = declare_dependency( |
| 12 | dependencies: [ |
| 13 | dependency('threads'), |
| 14 | gtest_proj.dependency('gtest'), |
| 15 | gtest_proj.dependency('gtest_main'), |
| 16 | ]) |
| 17 | gmock = gtest_proj.dependency('gmock') |
| 18 | else |
William A. Kennington III | fc3aff9 | 2021-05-29 15:09:58 -0700 | [diff] [blame] | 19 | assert(not get_option('tests').enabled(), 'Googletest is required') |
William A. Kennington III | 0a01b2a | 2021-05-13 18:38:57 -0700 | [diff] [blame] | 20 | endif |
| 21 | endif |
| 22 | |
| 23 | test_headers = include_directories('.') |
| 24 | |
| 25 | test_deps = [ |
| 26 | meson.get_compiler('cpp').find_library('dl'), |
| 27 | networkd_dep, |
| 28 | gtest, |
| 29 | gmock, |
| 30 | ] |
| 31 | |
| 32 | test_lib = static_library( |
| 33 | 'networkd-test', |
| 34 | 'mock_syscall.cpp', |
| 35 | 'global_network_objects.cpp', |
| 36 | implicit_include_directories: false, |
| 37 | include_directories: test_headers, |
| 38 | dependencies: test_deps) |
| 39 | |
| 40 | test_dep = declare_dependency( |
| 41 | dependencies: test_deps, |
| 42 | include_directories: test_headers, |
| 43 | link_with: test_lib) |
| 44 | |
| 45 | tests = [ |
| 46 | 'config_parser', |
| 47 | 'ethernet_interface', |
| 48 | 'neighbor', |
| 49 | 'netlink', |
| 50 | 'network_manager', |
| 51 | #'rtnetlink', |
| 52 | 'util', |
| 53 | 'vlan_interface', |
| 54 | ] |
| 55 | |
| 56 | foreach t : tests |
| 57 | test( |
| 58 | t, |
| 59 | executable( |
| 60 | t.underscorify(), |
| 61 | 'test_' + t + '.cpp', |
| 62 | implicit_include_directories: false, |
| 63 | dependencies: test_dep)) |
| 64 | endforeach |