William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [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_proj = import('cmake').subproject( |
| 5 | 'googletest', |
| 6 | cmake_options: [ |
| 7 | '-DCMAKE_CXX_FLAGS=-Wno-pedantic', |
| 8 | ], |
| 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 |
| 19 | assert(not build_tests.enabled(), 'Googletest is required') |
| 20 | endif |
| 21 | endif |
| 22 | |
| 23 | tests = [ |
| 24 | 'iface_test', |
| 25 | 'sock_test', |
| 26 | #'ncsi_test', # TODO: Re-enable when fixed |
| 27 | ] |
| 28 | |
| 29 | ncsid_test_headers = include_directories('.') |
| 30 | |
| 31 | ncsid_test_lib = static_library( |
| 32 | 'ncsid_test', |
| 33 | [ |
| 34 | 'net_iface_mock.cpp', |
| 35 | 'nic_mock.cpp', |
| 36 | ], |
| 37 | include_directories: ncsid_test_headers, |
| 38 | implicit_include_directories: false, |
| 39 | dependencies: ncsid) |
| 40 | |
| 41 | ncsid_test = declare_dependency( |
| 42 | dependencies: ncsid, |
| 43 | include_directories: ncsid_test_headers, |
| 44 | link_with: ncsid_test_lib) |
| 45 | |
| 46 | foreach t : tests |
| 47 | test(t, executable(t.underscorify(), t + '.cpp', |
| 48 | implicit_include_directories: false, |
| 49 | dependencies: [gtest, gmock, ncsid_test])) |
| 50 | endforeach |
| 51 | |
| 52 | script_tests = [ |
| 53 | 'normalize_ip_test', |
| 54 | 'normalize_mac_test', |
| 55 | ] |
| 56 | |
| 57 | script_env = environment() |
| 58 | script_deps = [] |
| 59 | script_env.set('NORMALIZE_IP', normalize_ip.full_path()) |
| 60 | script_deps += normalize_ip |
| 61 | script_env.set('NORMALIZE_MAC', normalize_mac.full_path()) |
| 62 | script_deps += normalize_mac |
| 63 | |
| 64 | foreach st : script_tests |
| 65 | test(st, find_program('bash'), args: files(st + '.sh'), |
| 66 | protocol: 'tap', env: script_env, depends: script_deps) |
| 67 | endforeach |