approvals / ApprovalTests.cpp

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

Use constexpr to define version numbers, not #define #107

Open claremacrae opened 4 years ago

claremacrae commented 4 years ago

This arose out of #91.

It would be better to use constexpr instead of #define to define the version number components of this project in code - for type-safety.

Not everyone who uses this project uses it with CMake, so I would stick with our current structure - but I see that constexpr is a nicer - type-safe - way of setting the various version numbers...

I'll set up a separate issue to convert the #define approach in to constexpr instead...

Originally posted by @claremacrae in https://github.com/approvals/ApprovalTests.cpp/issues/91#issuecomment-589946545

claremacrae commented 4 years ago

Current situation:

We use this:

https://github.com/approvals/ApprovalTests.cpp/blob/d997f56343ac70db621fd36593fa55b87b4eb975/build/prepare_release.py#L62-L81

To generate this:

https://github.com/approvals/ApprovalTests.cpp/blob/d997f56343ac70db621fd36593fa55b87b4eb975/ApprovalTests/ApprovalTestsVersion.h#L1-L13

claremacrae commented 4 years ago

See the following template for the intention of this ticket...

https://github.com/jwillikers/cmake_configure_version_header/blob/fa644a6db6d61b7ac6dffce738bcb038fa4e6bd7/src/version.hpp.in#L1-L14

Instead of the @...@ text, our Python script would insert actual values.

We need to think about the use of a namespace, though - It would be a breaking change to add this now...

And we would use char[] instead of std::string_view

claremacrae commented 3 years ago

We're marking this as on_hold, as no current plans to implement it...

claremacrae commented 3 years ago

It doesn't have to be a breaking change, if we add this as a new mechanism, and keep the old one...