@@ -4,6 +4,7 @@ from __future__ import print_function, unicode_literals
4
4
5
5
import argparse
6
6
import difflib
7
+ from functools import reduce
7
8
import logging
8
9
import os
9
10
import subprocess
@@ -17,7 +18,8 @@ class RoundTripTask(object):
17
18
def __init__ (self , input_filename , action , swift_syntax_test ,
18
19
skip_bad_syntax ):
19
20
assert action == '-round-trip-parse' or action == '-round-trip-lex'
20
- assert type (input_filename ) == unicode
21
+ if sys .version_info [0 ] < 3 :
22
+ assert type (input_filename ) == unicode
21
23
assert type (swift_syntax_test ) == str
22
24
23
25
assert os .path .isfile (input_filename ), \
@@ -51,9 +53,9 @@ class RoundTripTask(object):
51
53
self .output_file .close ()
52
54
self .stderr_file .close ()
53
55
54
- with open (self .output_file .name , 'r ' ) as stdout_in :
56
+ with open (self .output_file .name , 'rb ' ) as stdout_in :
55
57
self .stdout = stdout_in .read ()
56
- with open (self .stderr_file .name , 'r ' ) as stderr_in :
58
+ with open (self .stderr_file .name , 'rb ' ) as stderr_in :
57
59
self .stderr = stderr_in .read ()
58
60
59
61
os .remove (self .output_file .name )
@@ -75,7 +77,7 @@ class RoundTripTask(object):
75
77
raise RuntimeError ()
76
78
77
79
contents = '' .join (map (lambda l : l .decode ('utf-8' , errors = 'replace' ),
78
- open (self .input_filename ).readlines ()))
80
+ open (self .input_filename , 'rb' ).readlines ()))
79
81
stdout_contents = self .stdout .decode ('utf-8' , errors = 'replace' )
80
82
81
83
if contents == stdout_contents :
@@ -92,7 +94,7 @@ def swift_files_in_dir(d):
92
94
swift_files = []
93
95
for root , dirs , files in os .walk (d ):
94
96
for basename in files :
95
- if not basename .decode ( 'utf-8' ). endswith ('.swift' ):
97
+ if not basename .endswith ('.swift' ):
96
98
continue
97
99
abs_file = os .path .abspath (os .path .join (root , basename ))
98
100
swift_files .append (abs_file )
@@ -149,7 +151,8 @@ This driver invokes swift-syntax-test using -round-trip-lex and
149
151
all_input_files = [filename for dir_listing in dir_listings
150
152
for filename in dir_listing ]
151
153
all_input_files += args .individual_input_files
152
- all_input_files = [f .decode ('utf-8' ) for f in all_input_files ]
154
+ if sys .version_info [0 ] < 3 :
155
+ all_input_files = [f .decode ('utf-8' ) for f in all_input_files ]
153
156
154
157
if len (all_input_files ) == 0 :
155
158
logging .error ('No input files!' )
0 commit comments