Search code examples
testingmeson-build

How do I exclude/skip running certain tests with Meson?


In similar vein to Running Specific Test for Meson Build, I want to specify the tests run by Meson. However, instead of only running a specific subset of the tests, I want to run all tests except a specific subset of the tests, so that if new ones are added I don't have to manually add them to my test invocation. As such, hard-coding the list of included tests in the invocation is not the solution I'm looking for.

Is this possible with Meson, and if so, how?


Solution

  • I ended up doing it like this:

    $ test_list=$(meson test --list) 2> /dev/null
    

    This gets the list of all available tests. Redirecting stderr to /dev/null with 2> /dev/null avoids Ninja printing some error about there being nothing to do.

    $ test_list=${test_list//name-of-test-to-remove}
    

    This uses the built-in string replacement logic in Bash and various other shells to remove the test which you do not want to run. Notably, this does not work in pure POSIX shells as this feature is not part of the POSIX specification. However, many shells implement this extension.

    $ meson test $test_list
    

    And this works because Meson allows you to give it a list of tests to run, and $test_list will now contain all tests apart from the one that was removed in the previous step.

    This is of course not ideal since it either requires multiple steps or one very complicated invocation, but I couldn't find any other way to make Meson skip tests.