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

Added script to strip trailing whitespace from source files

Commit
8c32b49d5fd2329b20c684f21fe7098cd6da95b8
Author
Phil Nash ·
Parents
ece529ae7cd5

Files · Download .tar.gz

Changes

 scripts/fixTrailingWhitespace.py | 46 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/scripts/fixTrailingWhitespace.py b/scripts/fixTrailingWhitespace.py
new file mode 100644
index 00000000..0ffe8e91
--- /dev/null
+++ b/scripts/fixTrailingWhitespace.py
@@ -0,0 +1,46 @@
+from  __future__ import  print_function
+import os
+from scriptCommon import catchPath
+
+changedFiles = 0
+
+def isSourceFile( path ):
+    return path.endswith( ".cpp" ) or path.endswith( ".h" ) or path.endswith( ".hpp" )
+
+def fixAllFilesInDir( dir ):
+    for f in os.listdir( dir ):
+        path = os.path.join( dir,f )
+        if os.path.isfile( path ):
+            if( isSourceFile( path ) ):
+                fixFile( path )
+        else:
+            fixAllFilesInDir( path )
+
+def fixFile( path ):
+    f = open( path, 'r' )
+    lines = []
+    changed = 0
+    for line in f:
+        trimmed = line.rstrip() + "\n"
+        if trimmed != line:
+            changed = changed +1
+        lines.append( trimmed )
+    f.close()
+    if changed > 0:
+        global changedFiles
+        changedFiles = changedFiles + 1
+        print( path + ":" )
+        print( " - fixed " + str(changed) + " line(s)" )
+        altPath = path + ".backup"
+        os.rename( path, altPath )
+        f2 = open( path, 'w' )
+        for line in lines:
+            f2.write( line )
+        f2.close()
+        os.remove( altPath )
+
+fixAllFilesInDir(catchPath)
+if changedFiles > 0:
+    print( "Fixed " + str(changedFiles) + " file(s)" )
+else:
+    print( "No trailing whitespace found" )