Allow junit tests to have empty sources

Review Request #2923 - Created Oct. 2, 2015 and submitted

Information
Eric Ayers
pants
zundel/allow-empty-sources
2305
57e4ff1...
Reviewers
pants-reviews
gmalmquist, jsirois

Adds an advanced option --test-junit-allow-empty-sources to allow a BUILD file to contain a test target that defines empty sources.

This is a convenience for us with out BUILD file in a maven style layout. Our test targets are defined with a regular pattern,

junit_tests(name='test',
  sources = rglobs('*Test.java'),
  ...
)

junit_tests(name='integration-tests',
  sources = rglobs('*IT.java'),
  ...
)

java_library(name='lib',
  sources = rglobs('*.java') - rglobs('*IT.java') - rglobs('*Test.java'),
  ...
)

And our scripts expect to be able to run ./pants test <project>:test on any project

but some directories are missing some classes of tests. Without this change, our BUILD file generation has to search the filesystem to find if tests with particular glob patterns exist and re-write these 'junit_tests()' targets with target(), which slows things down.


  
Garrett Malmquist
Eric Ayers
Eric Ayers
Review request changed

Status: Closed (submitted)

Change Summary:

Thanks Garrett. Went ahead and merged it, but if there are objections I'm happy to reconsider. Commit 8f137c6

Stu Hood

And our scripts expect to be able to run ./pants test <project>:test on any project

We strongly recommend ./pants test <project>:: internally. It ensures that all code (not just code which happens to have tests) is built. And generally, it would be good to move further in the direction of requiring non-empty targets.

  1. This is how devs run tests. It is possible for us to do this now because Garrett added isolation to testing, but that does not allow us to easily judge which test target is failing in our regression tests. Also, some of our subdirectories will be in flux, using maven as the source of truth for some subdirs and pants for others.

  2. It is possible for us to do this now because Garrett added isolation to testing, but that does not allow us to easily judge which test target is failing in our regression tests.

    We do this by running ./pants filter --type=junit_tests ::, and then running each test target in isolation (rather than using a manually specified list). You can then explicitly filter out test targets that shouldn't run via a list or exclude.

    Also, some of our subdirectories will be in flux, using maven as the source of truth for some subdirs and pants for others.

    That should be fine... ./pants test <project>:: will only build things that have BUILD files. Would just need to be sure that the BUILD files that exist are valid.

Loading...