Brandon Kim | dab96f1 | 2021-02-18 11:21:37 -0800 | [diff] [blame] | 1 | # Copyright 2021 Google LLC |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 15 | gtest = dependency('gtest', main: true, disabler: true, required: false) |
| 16 | gmock = dependency('gmock', disabler: true, required: false) |
| 17 | if not gtest.found() or not gmock.found() |
| 18 | gtest_proj = import('cmake').subproject( |
| 19 | 'googletest', |
| 20 | cmake_options: [ |
| 21 | '-DCMAKE_CXX_FLAGS=-Wno-pedantic', |
| 22 | ], |
| 23 | required: false) |
| 24 | if gtest_proj.found() |
| 25 | gtest = declare_dependency( |
| 26 | dependencies: [ |
| 27 | dependency('threads'), |
| 28 | gtest_proj.dependency('gtest'), |
| 29 | gtest_proj.dependency('gtest_main'), |
| 30 | ]) |
| 31 | gmock = gtest_proj.dependency('gmock') |
| 32 | else |
| 33 | assert(not build_tests.enabled(), 'Googletest is required') |
| 34 | endif |
| 35 | endif |
| 36 | |
| 37 | tests = [ |
| 38 | 'iface_test', |
| 39 | 'sock_test', |
| 40 | #'ncsi_test', # TODO: Re-enable when fixed |
| 41 | ] |
| 42 | |
| 43 | ncsid_test_headers = include_directories('.') |
| 44 | |
| 45 | ncsid_test_lib = static_library( |
| 46 | 'ncsid_test', |
| 47 | [ |
| 48 | 'net_iface_mock.cpp', |
| 49 | 'nic_mock.cpp', |
| 50 | ], |
| 51 | include_directories: ncsid_test_headers, |
| 52 | implicit_include_directories: false, |
| 53 | dependencies: ncsid) |
| 54 | |
| 55 | ncsid_test = declare_dependency( |
| 56 | dependencies: ncsid, |
| 57 | include_directories: ncsid_test_headers, |
| 58 | link_with: ncsid_test_lib) |
| 59 | |
| 60 | foreach t : tests |
| 61 | test(t, executable(t.underscorify(), t + '.cpp', |
| 62 | implicit_include_directories: false, |
| 63 | dependencies: [gtest, gmock, ncsid_test])) |
| 64 | endforeach |
| 65 | |
| 66 | script_tests = [ |
| 67 | 'normalize_ip_test', |
| 68 | 'normalize_mac_test', |
| 69 | ] |
| 70 | |
| 71 | script_env = environment() |
| 72 | script_deps = [] |
| 73 | script_env.set('NORMALIZE_IP', normalize_ip.full_path()) |
| 74 | script_deps += normalize_ip |
| 75 | script_env.set('NORMALIZE_MAC', normalize_mac.full_path()) |
| 76 | script_deps += normalize_mac |
| 77 | |
| 78 | foreach st : script_tests |
| 79 | test(st, find_program('bash'), args: files(st + '.sh'), |
| 80 | protocol: 'tap', env: script_env, depends: script_deps) |
| 81 | endforeach |