Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test setup: dependency for test target #2418

Closed
gauteh opened this issue Oct 3, 2017 · 3 comments
Closed

test setup: dependency for test target #2418

gauteh opened this issue Oct 3, 2017 · 3 comments

Comments

@gauteh
Copy link

gauteh commented Oct 3, 2017

Hi, I need to run a test setup script (or some code) before the tests can be run. This has to move a bunch of test data files into the build directory and set up a test environment. How can I do this in a good way? run_target was the obvious first try (with a shell script), but I was unable to add this as a dependency for the tests. Then I tried a custom_target, and add this as a link_depends for the test(exectuable()) - but this causes the test setup to be run just when tests are compiling - and I don't want to run this unless I am actually running the tests.

Also, is it possible to avoid having the tests build by default. Passing build_by_default : false to the test(executable()) did not work.

## Tests
test_setup = custom_target ('test_setup',
    command : [ find_program('tests/test_setup.sh').path(), '@INPUT@', '@OUTPUT@' ],
    input : 'tests',
    output : 'tests',
    install : false)

test_env = environment ()
test_env.set ('NOTMUCH_CONFIG', join_paths(meson.build_root (), 'tests', 'mail', 'test_config'))

src_o = astroid_exe.extract_objects (src)

boost_test = dependency ('boost', modules : [ 'unit_test_framework' ])
test_deps = deps
test_deps += boost_test

tests = [ [ 'generic test',   'test_generic', [ 'tests/test_generic.cc' ]],
          [ 'compose testing', 'test_composed_message',  [ 'tests/test_composed_message.cc' ]]
        ]

foreach t : tests
  test (t[0],
      executable (t[1], t[2], objects : src_o, include_directories : include_directories ('src'), dependencies : test_deps, link_depends : test_setup, build_by_default : false),
      env : test_env, workdir : meson.build_root())
endforeach

Full meson.build.

@db-src
Copy link

db-src commented Oct 27, 2017

Also, is it possible to avoid having the tests build by default. Passing build_by_default : false to the test(executable()) did not work.

This also does not seem to work for me (with the result of executable() stored in a variable); the test executables are always built. This is a real pain if I'm testing new code in src/, or a new feature that doesn't have a formal test yet, or I simply decide I don't care about the test results and just want to build the core.

@nirbheek
Copy link
Member

Duplicate of #1704

@nirbheek nirbheek marked this as a duplicate of #1704 Dec 12, 2017
@stalkerg
Copy link

@nirbheek I suppose it's a separate issue. Here we need something to prepare tests (run script, with some DB for example) and some action to stop tests (stop and clean DB for example).
In #1704 you mostly talking about a separate run for tests.

Of course, we can run some bash/bat script to do it but in that case semantic will not so clear for developers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants