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
Add support for unit tests, and a few unit tests #10636
Conversation
TEST_CASE("GreatestCommonDivisorTest - Negative") | ||
{ | ||
CHECK(4 == GreatestCommonDivisor(4, -52)); | ||
// CHECK(3 == GreatestCommonDivisor(-27, 6)); // error - returns -3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code, and an error elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a look to see if hierarchical tests could be done, it looks like it's supported by catch2 by way of SECTIONs, but ctest itself doesn't do anything with those and only shows the top-level TEST_CASE. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me.
Nice work! |
Motivation / Problem
Tests for new and existing code will make development & refactoring easier.
And will make it easier to detect regressions and unintended changes.
See #9038 and #7796. Triggered by #10570 which adds some tests as constexpr code.
Description
Split building of OpenTTD into a "library" and the executable, by extracting the
main()
functions into separate files. And then building the library without themain()
function and the openttd executable is themain()
function with the library linked. The library is not an actual library, but some construct in CMake that prevents building the same objects twice, since the library is going to be linked with the unit tests and then run.Add catch2 as third-parties library. It does not exist as library in ubuntu 20.04, so otherwise it would require updating those. Furthermore there were issues in getting it to work with Windows and Mac OS X. By third-partying it, it will just be available and do its thing.
Add unit test from #9038/#7796 and convert constexpr tests of #10570 to a proper unit test, and integrate catch2 into the build. Add an extra executable (openttd_test) that links the new "library" and the unit tests. With the integration it automatically gets picked up with ctest, and be run in parallel with the regression tests.
Limitations
I'm not sure whether OS/2 still builds.
I'm not sure whether the release workflows still function.
It has been a long time whack-a-moling to get this functioning, so I'm not sure whether I did the right things.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.