approvals / ApprovalTests.cpp

Native ApprovalTests for C++ on Linux, Mac and Windows
https://approvaltestscpp.readthedocs.io/en/latest/
Apache License 2.0
312 stars 51 forks source link

Remove the need for out-of-source build trees with non-Unity Ninja builds #171

Closed claremacrae closed 3 years ago

claremacrae commented 3 years ago

In a project where I'm using ApprovalTests, and I'm out-of-source builds so that Ninja CI builds should work, I'm finding that the compile-time error check is being triggered...

https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/TroubleshootingMisconfiguredBuild.md#compilation-error

... I expected this Ninja build to work, because I'm doing out-of-source builds...

It's happened in one project where I'm loading the ApprovalTests.cpp project via CMake's FetchContent - so even though the build tree is outside the source directory, FetchContent is putting ApprovalTests inside the build-tree - which I think is resulting in relative paths...

This is another situation:

https://github.com/claremacrae/ApprovalTests.cpp.CMakeSamples/issues/5

claremacrae commented 3 years ago

Because of this issue, I've experiment with adding some code to ApprovalTests::TestName::setFileName() so that, if it finds that the supplied source file does not exist, it tries looking in the parent dir, the grandparent dir, and a few more....

And if it finds the source file there, it remembers the amount of "../" that it needed to add, and uses that in the remaining tests in that test suite run.

The code is a bit ugly at the moment - but it's a big improvement in behaviour, as we would be able to get rid of most or all of this Troubleshooting page, for newer releases: https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/TroubleshootingMisconfiguredBuild.md

.... and we would also get rid of the compile-time check as to whether the build was configured correctly...

claremacrae commented 3 years ago

The code so far is here - it runs on all CI platforms...

https://github.com/approvals/ApprovalTests.cpp/compare/a11ccaa...a2b0081

Things that definitely need to be done:

claremacrae commented 3 years ago

This is fixed in the soon-to-be-released v.10.8.0