mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.3k stars 1.52k forks source link

New `add_test_suite` function #13181

Closed bruchar1 closed 2 weeks ago

bruchar1 commented 2 weeks ago

This function allows to attach new suite labels to already defined tests or benchmarks. It is used in the context you want to label a series of test with a specific label.

bruchar1 commented 2 weeks ago

The problem I want to solve is that I have hundreds of test targets. I need to group them to be able to execute all tests related to a part of my project (e.g. tests for an executable and tests for all its dependent libraries). Adding the required suites to every test would be tedious and error prone, because if a dependency change, I have to modify every tests related to that dependency. Having the list of test of a given test suite in one place would be easier to manage.

My other idea was to add a test_alias function, similar to alias_target, but since the notion of test suite already does that, it feels more natural to use it.

tristan957 commented 2 weeks ago

Could you not solve your problem like:

tests = {
  'test1': {
    # test kwargs
    'suite': ['original-suite']
  }
  # other tests...
}

foreach t, params : tests
  additional_suites = []
  if the_dep.found()
    additional_suites += 'other-suite'
  endif

  test(t, xxx, suites: params.get('suite', []) + additional_suites)
endforeach
eli-schwartz commented 2 weeks ago

It's not obvious to me how choosing and regularly updating which tests are appended to which array for later passing into add_test_suite(some_tests_array), is more or less easy to maintain than an array of suites_for_foobar and updating the list of suites in place, then reusing that array for each logical group of tests. Either one requires a bit of juggling.

bruchar1 commented 2 weeks ago

Thank you for your suggestions. I think I may be able to construct a datastucture while going through the build files. I was reluctant to the idea of putting all the test functions in a for loop as @tristan957 suggested, but finally, it may be not so bad. I will give it a try.

tristan957 commented 2 weeks ago

Hopefully it works out for you!

jpakkane commented 2 weeks ago

A main design point of Meson has always been that defined things are immutable. That is, all information pertaining to a thing must be present when it is defined. Altering things after the fact is not acceptable because that leads to unmaintainability. Whatever the solution to this problem ends up being, it must not be this.