Skip to content

Commit

Permalink
Add CATCH_VERSION_* defines for external use
Browse files Browse the repository at this point in the history
I wonder how much use they will actually see, but their cost is
fairly minor.

Closes #1131
  • Loading branch information
horenmar committed Jan 26, 2018
1 parent ca2455e commit 44dbda9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/own-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions include/catch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions scripts/releaseCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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')
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 44dbda9

Please sign in to comment.