approvals / ApprovalTests.cpp

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

Allow users to detect Approval Test version in code #40

Closed claremacrae closed 4 years ago

claremacrae commented 5 years ago

In #37 it was really helpful to be able to write code that was able to detect the doctest version number, to be able to support more than one doctest version.

The relevant doctest code is:

// =================================================================================================
// == VERSION ======================================================================================
// =================================================================================================

#define DOCTEST_VERSION_MAJOR 2
#define DOCTEST_VERSION_MINOR 3
#define DOCTEST_VERSION_PATCH 5
#define DOCTEST_VERSION_STR "2.3.5"

#define DOCTEST_VERSION                                                                            \
    (DOCTEST_VERSION_MAJOR * 10000 + DOCTEST_VERSION_MINOR * 100 + DOCTEST_VERSION_PATCH)

Can we do the corresponding thing in Approval Tests too?

This would involve changing the release script, to set the values automatically.

claremacrae commented 5 years ago

Before doing this, it would be worth looking at Catch2's release scripts, which are in Python and really nice and clean, for example:

https://github.com/catchorg/Catch2/blob/master/scripts/minorRelease.py

You don't have to even work out what the next version number will be. You just say "I'm doing a minor release" (or major, or patch) and it takes care of all the appropriate incrementation.

dheater commented 4 years ago

How about using CMake to generate the version number? https://cmake.org/cmake/help/latest/guide/tutorial/index.html#adding-a-version-number-and-configured-header-file

claremacrae commented 4 years ago

How about using CMake to generate the version number? https://cmake.org/cmake/help/latest/guide/tutorial/index.html#adding-a-version-number-and-configured-header-file

That's one possibility...

We'd still need to get the version number in to CMake in the first place, and this script updates the version number in various places: https://github.com/approvals/ApprovalTests.cpp/blob/master/build/build_hpp.sh

So also a possibility is to make build_hpp.sh to edit in the version number directly...

dheater commented 4 years ago

Yeah. Probably makes more sense to go direct with build_hpp.sh since there are several other things being modified.

claremacrae commented 4 years ago

This is now implemented, using these steps:

The generated code looks like this:

#ifndef APPROVALTESTS_CPP_APPROVALTESTSVERSION_H
#define APPROVALTESTS_CPP_APPROVALTESTSVERSION_H

#define APPROVALTESTS_VERSION_MAJOR 8
#define APPROVALTESTS_VERSION_MINOR 0
#define APPROVALTESTS_VERSION_PATCH 0
#define APPROVALTESTS_VERSION_STR "8.0.0"

#define APPROVALTESTS_VERSION                                                  \
    (APPROVALTESTS_VERSION_MAJOR * 10000 + APPROVALTESTS_VERSION_MINOR * 100 + \
     APPROVALTESTS_VERSION_PATCH)

#endif //APPROVALTESTS_CPP_APPROVALTESTSVERSION_H