Fix newline comparison on windows
This commit is contained in:
parent
2d9dba76cb
commit
90757717a5
17
wscript
17
wscript
@ -2,7 +2,6 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import filecmp
|
|
||||||
import difflib
|
import difflib
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -80,7 +79,9 @@ def run_astyle_tests(bld):
|
|||||||
if os.path.isdir('test'):
|
if os.path.isdir('test'):
|
||||||
test_folder = os.path.join(os.getcwd(), 'test')
|
test_folder = os.path.join(os.getcwd(), 'test')
|
||||||
correct_style = os.path.join(test_folder, 'correct_style.cpp')
|
correct_style = os.path.join(test_folder, 'correct_style.cpp')
|
||||||
correct_lines = open(correct_style, 'U').readlines()
|
# Read the input file using universal newlines (so the line endings
|
||||||
|
# are seen as '\n', even if git checks out the code with '\r\n')
|
||||||
|
correct_lines = open(correct_style, 'rU').readlines()
|
||||||
|
|
||||||
temp_folder = os.path.join(test_folder, 'temp')
|
temp_folder = os.path.join(test_folder, 'temp')
|
||||||
# Make sure that the temp folder is deleted before copytree
|
# Make sure that the temp folder is deleted before copytree
|
||||||
@ -98,14 +99,14 @@ def run_astyle_tests(bld):
|
|||||||
run_command([astyle, options, test_file])
|
run_command([astyle, options, test_file])
|
||||||
|
|
||||||
# Compare the formatted file with the correct style
|
# Compare the formatted file with the correct style
|
||||||
if not filecmp.cmp(correct_style, test_file):
|
test_lines = open(test_file, 'r').readlines()
|
||||||
|
diff = difflib.unified_diff(correct_lines, test_lines)
|
||||||
|
diff_lines = ''.join(diff)
|
||||||
|
|
||||||
|
if len(diff_lines) > 0:
|
||||||
incorrect_files += 1
|
incorrect_files += 1
|
||||||
print('\nIncorrect formatting: {}'.format(test_file))
|
print('\nIncorrect formatting: {}'.format(test_file))
|
||||||
|
print(diff_lines)
|
||||||
test_lines = open(test_file, 'U').readlines()
|
|
||||||
|
|
||||||
diff = difflib.unified_diff(correct_lines, test_lines)
|
|
||||||
print(''.join(diff))
|
|
||||||
|
|
||||||
# Clean up the temp directory
|
# Clean up the temp directory
|
||||||
shutil.rmtree(temp_folder)
|
shutil.rmtree(temp_folder)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user