5

In a meson build, is it possible to set the working directory before executing unit tests? It uses ninja by default to run the tests, so perhaps there's an option you can pass to ninja to set the directory?

Why I'm asking is sometimes unit tests need access to config/data files (I usually try to avoid this, but sometimes it's just not possible) and they need to know the relative path in order to load them.

oz10
  • 153,307
  • 27
  • 93
  • 128

1 Answers1

4

It appears the appropriate syntax for this is to append workdir to arguments passed to the test() method.

exe = executable('unit_test', 'test.c')
test('basic', exe, workdir : meson.source_root())
oz10
  • 153,307
  • 27
  • 93
  • 128
  • 1
    `.current_source_dir()` is more "future-proof" than `.source_root()` : more subprojects friendly. – MarcH Oct 30 '19 at 23:16