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-empty-group',
24  'test-group-priority',
25  'test-led-priority'
26]
27
28test_sources = [
29  '../manager/manager.cpp',
30  '../manager/config-validator.cpp',
31  '../utils.cpp',
32]
33
34foreach yaml : test_yamls
35  gen_hpp = custom_target(
36    yaml + '.hpp',
37    command : [
38        prog_python,
39        meson.project_source_root() + '/scripts/parse_led.py',
40        '--filename', meson.project_source_root() + '/test/config/' + yaml + '.yaml',
41        '-o', meson.current_build_dir(),
42        '--output-filename', yaml + '.hpp'
43    ],
44    output : yaml + '.hpp')
45
46  test_sources += [ gen_hpp ]
47endforeach
48
49tests = [
50  'utest.cpp',
51  'utest-led-json.cpp',
52  'utest-group-priority.cpp',
53  'utest-led-yaml-group-priority.cpp',
54  'utest-led-yaml-led-priority.cpp',
55  'utest-led-yaml-empty-group.cpp',
56  'utest-config-validator.cpp'
57]
58if get_option('persistent-led-asserted').allowed()
59  test_sources += [
60    '../manager/serialize.cpp',
61  ]
62  tests += [
63    'utest-serialize.cpp',
64  ]
65endif
66
67foreach t : tests
68  test(t, executable(t.underscorify(), t,
69                     test_sources,
70                     include_directories: ['..', '../manager'],
71                     dependencies: [
72                         gtest_dep,
73                         gmock_dep,
74                         deps
75                         ]),
76       workdir: meson.current_source_dir())
77endforeach
78