1gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
2gmock_dep = dependency('gmock', disabler: true, required: false)
3if not gtest_dep.found() or not gmock_dep.found()
4    gtest_proj = import('cmake').subproject('googletest', required: false)
5    if gtest_proj.found()
6        gtest_dep = declare_dependency(
7            dependencies: [
8                dependency('threads'),
9                gtest_proj.dependency('gtest'),
10                gtest_proj.dependency('gtest_main'),
11            ]
12        )
13        gmock_dep = gtest_proj.dependency('gmock')
14  else
15        assert(
16            not get_option('tests').allowed(),
17            'Googletest is required if tests are enabled'
18        )
19  endif
20endif
21
22test_yamls = [
23  'test-group-priority',
24  'test-led-priority'
25]
26
27test_sources = [
28  '../manager/manager.cpp',
29  '../manager/config-validator.cpp',
30  '../utils.cpp',
31]
32
33foreach yaml : test_yamls
34  gen_hpp = custom_target(
35    yaml + '.hpp',
36    command : [
37        prog_python,
38        meson.project_source_root() + '/scripts/parse_led.py',
39        '--filename', meson.project_source_root() + '/test/config/' + yaml + '.yaml',
40        '-o', meson.current_build_dir(),
41        '--output-filename', yaml + '.hpp'
42    ],
43    output : yaml + '.hpp')
44
45  test_sources += [ gen_hpp ]
46endforeach
47
48tests = [
49  'utest.cpp',
50  'utest-led-json.cpp',
51  'utest-group-priority.cpp',
52  'utest-led-yaml-group-priority.cpp',
53  'utest-led-yaml-led-priority.cpp',
54  'utest-config-validator.cpp'
55]
56if get_option('persistent-led-asserted').allowed()
57  test_sources += [
58    '../manager/serialize.cpp',
59  ]
60  tests += [
61    'utest-serialize.cpp',
62  ]
63endif
64
65foreach t : tests
66  test(t, executable(t.underscorify(), t,
67                     test_sources,
68                     include_directories: ['..', '../manager'],
69                     dependencies: [
70                         gtest_dep,
71                         gmock_dep,
72                         deps
73                         ]),
74       workdir: meson.current_source_dir())
75endforeach
76