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

Improve handling of newlines in release scripts

Under WSL, Python in text mode will translate `\n` into `\r\n`, even
though other tools and utilities use `\n` (because WSL is basically
Linux). This leads to the update scripts leaving the files with
Windows newlines even though git and similar expect them to have
Linux newlines.

By instead handling files in binary mode, we can keep the original
newlines. This commits switches parts of the update process to
binary mode, but not all because some of the will require a lot of
work to fix.
Commit
06bc20cf37b8b7754989569be91e5f62a1c3d1b9
Author
Martin Hořeňovský ·
Parents
7a4beed6a666

Files · Download .tar.gz

Changes

 scripts/releaseCommon.py | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/scripts/releaseCommon.py b/scripts/releaseCommon.py
index 87c6e261..c8475460 100644
--- a/scripts/releaseCommon.py
+++ b/scripts/releaseCommon.py
@@ -100,29 +100,28 @@ def updateReadmeFile(version):
 
 
 def updateCmakeFile(version):
-    with open(cmakePath, 'r') as file:
+    with open(cmakePath, 'rb') as file:
         lines = file.readlines()
-    with open(cmakePath, 'w') as file:
+    replacementRegex = re.compile(b'project\\(Catch2 LANGUAGES CXX VERSION \\d+\\.\\d+\\.\\d+\\)')
+    replacement = 'project(Catch2 LANGUAGES CXX VERSION {0})'.format(version.getVersionString()).encode('ascii')
+    with open(cmakePath, 'wb') as file:
         for line in lines:
-            if 'project(Catch2 LANGUAGES CXX VERSION ' in line:
-                file.write('project(Catch2 LANGUAGES CXX VERSION {0})\n'.format(version.getVersionString()))
-            else:
-                file.write(line)
+            file.write(replacementRegex.sub(replacement, line))
 
 
 def updateVersionDefine(version):
-    with open(definePath, 'r') as file:
+    # First member of the tuple is the compiled regex object, the second is replacement if it matches
+    replacementRegexes = [(re.compile(b'#define CATCH_VERSION_MAJOR \\d+'),'#define CATCH_VERSION_MAJOR {}'.format(version.majorVersion).encode('ascii')),
+                          (re.compile(b'#define CATCH_VERSION_MINOR \\d+'),'#define CATCH_VERSION_MINOR {}'.format(version.minorVersion).encode('ascii')),
+                          (re.compile(b'#define CATCH_VERSION_PATCH \\d+'),'#define CATCH_VERSION_PATCH {}'.format(version.patchNumber).encode('ascii')),
+                         ]
+    with open(definePath, 'rb') as file:
         lines = file.readlines()
-    with open(definePath, 'w') as file:
+    with open(definePath, 'wb') 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)
+            for replacement in replacementRegexes:
+                line = replacement[0].sub(replacement[1], line)
+            file.write(line)
 
 
 def updateVersionPlaceholder(filename, version):