@@ -56,6 +56,12 @@ constants.""")
56
56
"available if Windows compatibility is enabled." ,
57
57
action = "store_true" )
58
58
59
+ parser .add_argument (
60
+ "--dry-run" ,
61
+ help = "Apply the replacements to the input and print the result "
62
+ "to standard output" ,
63
+ action = "store_true" )
64
+
59
65
args , unknown_args = parser .parse_known_args ()
60
66
61
67
if args .enable_windows_compatibility :
@@ -70,19 +76,25 @@ constants.""")
70
76
71
77
for s in args .sanitize_strings :
72
78
replacement , pattern = s .split ('=' , 1 )
73
- # We are replacing the Unix path separators in the paths passed as
74
- # arguments with a broader pattern to also allow forward slashes and
75
- # double escaped slashes in the result that we are checking. Sigh.
76
- stdin = re .sub (re .sub (r'/' , slashes_re , pattern ), replacement , stdin )
77
-
78
- p = subprocess .Popen (
79
- [args .file_check_path ] + unknown_args , stdin = subprocess .PIPE )
80
- stdout , stderr = p .communicate (stdin )
81
- if stdout is not None :
82
- print (stdout )
83
- if stderr is not None :
84
- print (stderr , file = sys .stderr )
85
- return p .wait ()
79
+ # Since we want to use pattern as a regex in some platforms, we need
80
+ # to escape it first, and then replace the escaped slash
81
+ # literal (r'\\/') for our platform-dependent slash regex.
82
+ stdin = re .sub (re .sub (r'\\/' , slashes_re , re .escape (pattern )),
83
+ replacement ,
84
+ stdin )
85
+
86
+ if args .dry_run :
87
+ print (stdin )
88
+ return 0
89
+ else :
90
+ p = subprocess .Popen (
91
+ [args .file_check_path ] + unknown_args , stdin = subprocess .PIPE )
92
+ stdout , stderr = p .communicate (stdin )
93
+ if stdout is not None :
94
+ print (stdout )
95
+ if stderr is not None :
96
+ print (stderr , file = sys .stderr )
97
+ return p .wait ()
86
98
87
99
88
100
if __name__ == '__main__' :
0 commit comments