Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Add CATCH_VERSION_* defines for external use

I wonder how much use they will actually see, but their cost is
fairly minor.

Closes #1131
Commit
44dbda9f0184818dc8a84085c3679740a185325d
Author
Martin Hořeňovský ·
Parents
ca2455e6e643

Files · Download .tar.gz

Changes

 docs/own-main.md         | 14 ++++++++++++++
 include/catch.hpp        |  3 +++
 scripts/releaseCommon.py | 18 ++++++++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/docs/own-main.md b/docs/own-main.md
index 7de4b963..18d1b7d3 100644
--- a/docs/own-main.md
+++ b/docs/own-main.md
@@ -106,6 +106,20 @@ int main( int argc, char* argv[] )
 
 See the [Clara documentation](https://github.com/philsquared/Clara/blob/master/README.md) for more details.
 
+
+## Version detection
+
+Catch provides a triplet of macros providing the header's version, 
+
+* `CATCH_VERSION_MAJOR`
+* `CATCH_VERSION_MINOR`
+* `CATCH_VERSION_PATCH`
+
+these macros expand into a single number, that corresponds to the appropriate
+part of the version. As an example, given single header version v2.3.4,
+the macros would expand into `2`, `3`, and `4` respectively.
+
+
 ---
 
 [Home](Readme.md#top)
diff --git a/include/catch.hpp b/include/catch.hpp
index 34c551be..0a4711be 100644
--- a/include/catch.hpp
+++ b/include/catch.hpp
@@ -9,6 +9,9 @@
 #ifndef TWOBLUECUBES_CATCH_HPP_INCLUDED
 #define TWOBLUECUBES_CATCH_HPP_INCLUDED
 
+#define CATCH_VERSION_MAJOR 2
+#define CATCH_VERSION_MINOR 1
+#define CATCH_VERSION_PATCH 1
 
 #ifdef __clang__
 #    pragma clang system_header
diff --git a/scripts/releaseCommon.py b/scripts/releaseCommon.py
index a3b63906..6e44da24 100644
--- a/scripts/releaseCommon.py
+++ b/scripts/releaseCommon.py
@@ -10,6 +10,7 @@ from scriptCommon import catchPath
 versionParser = re.compile( r'(\s*static\sVersion\sversion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' )
 rootPath = os.path.join( catchPath, 'include/' )
 versionPath = os.path.join( rootPath, "internal/catch_version.cpp" )
+definePath = os.path.join(rootPath, 'catch.hpp')
 readmePath = os.path.join( catchPath, "README.md" )
 conanPath = os.path.join(catchPath, 'conanfile.py')
 conanTestPath = os.path.join(catchPath, 'test_package', 'conanfile.py')
@@ -137,10 +138,27 @@ def updateCmakeFile(version):
             else:
                 file.write(line)
 
+
+def updateVersionDefine(version):
+    with open(definePath, 'r') as file:
+        lines = file.readlines()
+    with open(definePath, 'w') as file:
+        for line in lines:
+            if '#define CATCH_VERSION_MAJOR' in line:
+                file.write('#define CATCH_VERSION_MAJOR {}\n'.format(version.majorVersion))
+            elif '#define CATCH_VERSION_MINOR' in line:
+                file.write('#define CATCH_VERSION_MINOR {}\n'.format(version.minorVersion))
+            elif '#define CATCH_VERSION_PATCH' in line:
+                file.write('#define CATCH_VERSION_PATCH {}\n'.format(version.patchNumber))
+            else:
+                file.write(line)
+
+
 def performUpdates(version):
     # First update version file, so we can regenerate single header and
     # have it ready for upload to wandbox, when updating readme
     version.updateVersionFile()
+    updateVersionDefine(version)
 
     import generateSingleHeader
     generateSingleHeader.generate(version)