@@ -26,12 +26,35 @@ def rm_f(fname):
26
26
if os .path .exists (fname ):
27
27
os .remove (fname )
28
28
29
+
30
+ # unescape wanted regex chars and escape unwanted ones
31
+ def convert_regex_escapes (line ):
32
+ cs = []
33
+ escape = False
34
+ for c in str (line , 'utf8' ):
35
+ if escape :
36
+ escape = False
37
+ cs .append (c )
38
+ elif c == '\\ ' :
39
+ escape = True
40
+ elif c in ('(' , ')' , '[' , ']' , '{' , '}' , '.' , '*' , '+' , '^' , '$' ):
41
+ cs .append ('\\ ' + c )
42
+ else :
43
+ cs .append (c )
44
+ # accept carriage-return(s) before final newline
45
+ if cs [- 1 ] == '\n ' :
46
+ cs [- 1 ] = '\r *\n '
47
+ return bytes ('' .join (cs ), 'utf8' )
48
+
49
+
29
50
def run_micropython (pyb , args , test_file ):
30
51
special_tests = ('micropython/meminfo.py' , 'basics/bytes_compare3.py' )
52
+ is_special = False
31
53
if pyb is None :
32
54
# run on PC
33
- if test_file .startswith (('cmdline/' , 'feature_check/' )) or test_file in special_tests :
55
+ if test_file .startswith (('cmdline/' , 'feature_check/' )) or test_file in special_tests :
34
56
# special handling for tests of the unix cmdline program
57
+ is_special = True
35
58
36
59
# check for any cmdline options needed for this test
37
60
args = [MICROPYTHON ]
@@ -81,63 +104,6 @@ def run_micropython(pyb, args, test_file):
81
104
except subprocess .CalledProcessError :
82
105
return b'CRASH'
83
106
84
- # unescape wanted regex chars and escape unwanted ones
85
- def convert_regex_escapes (line ):
86
- cs = []
87
- escape = False
88
- for c in str (line , 'utf8' ):
89
- if escape :
90
- escape = False
91
- cs .append (c )
92
- elif c == '\\ ' :
93
- escape = True
94
- elif c in ('(' , ')' , '[' , ']' , '{' , '}' , '.' , '*' , '+' , '^' , '$' ):
95
- cs .append ('\\ ' + c )
96
- else :
97
- cs .append (c )
98
- # accept carriage-return(s) before final newline
99
- if cs [- 1 ] == '\n ' :
100
- cs [- 1 ] = '\r *\n '
101
- return bytes ('' .join (cs ), 'utf8' )
102
-
103
- # convert parts of the output that are not stable across runs
104
- with open (test_file + '.exp' , 'rb' ) as f :
105
- lines_exp = []
106
- for line in f .readlines ():
107
- if line == b'########\n ' :
108
- line = (line ,)
109
- else :
110
- line = (line , re .compile (convert_regex_escapes (line )))
111
- lines_exp .append (line )
112
- lines_mupy = [line + b'\n ' for line in output_mupy .split (b'\n ' )]
113
- if output_mupy .endswith (b'\n ' ):
114
- lines_mupy = lines_mupy [:- 1 ] # remove erroneous last empty line
115
- i_mupy = 0
116
- for i in range (len (lines_exp )):
117
- if lines_exp [i ][0 ] == b'########\n ' :
118
- # 8x #'s means match 0 or more whole lines
119
- line_exp = lines_exp [i + 1 ]
120
- skip = 0
121
- while i_mupy + skip < len (lines_mupy ) and not line_exp [1 ].match (lines_mupy [i_mupy + skip ]):
122
- skip += 1
123
- if i_mupy + skip >= len (lines_mupy ):
124
- lines_mupy [i_mupy ] = b'######## FAIL\n '
125
- break
126
- del lines_mupy [i_mupy :i_mupy + skip ]
127
- lines_mupy .insert (i_mupy , b'########\n ' )
128
- i_mupy += 1
129
- else :
130
- # a regex
131
- if lines_exp [i ][1 ].match (lines_mupy [i_mupy ]):
132
- lines_mupy [i_mupy ] = lines_exp [i ][0 ]
133
- else :
134
- #print("don't match: %r %s" % (lines_exp[i][1], lines_mupy[i_mupy])) # DEBUG
135
- pass
136
- i_mupy += 1
137
- if i_mupy >= len (lines_mupy ):
138
- break
139
- output_mupy = b'' .join (lines_mupy )
140
-
141
107
else :
142
108
# a standard test
143
109
try :
@@ -160,6 +126,45 @@ def run_micropython(pyb, args, test_file):
160
126
# canonical form for all ports/platforms is to use \n for end-of-line
161
127
output_mupy = output_mupy .replace (b'\r \n ' , b'\n ' )
162
128
129
+ if is_special or test_file in special_tests :
130
+ # convert parts of the output that are not stable across runs
131
+ with open (test_file + '.exp' , 'rb' ) as f :
132
+ lines_exp = []
133
+ for line in f .readlines ():
134
+ if line == b'########\n ' :
135
+ line = (line ,)
136
+ else :
137
+ line = (line , re .compile (convert_regex_escapes (line )))
138
+ lines_exp .append (line )
139
+ lines_mupy = [line + b'\n ' for line in output_mupy .split (b'\n ' )]
140
+ if output_mupy .endswith (b'\n ' ):
141
+ lines_mupy = lines_mupy [:- 1 ] # remove erroneous last empty line
142
+ i_mupy = 0
143
+ for i in range (len (lines_exp )):
144
+ if lines_exp [i ][0 ] == b'########\n ' :
145
+ # 8x #'s means match 0 or more whole lines
146
+ line_exp = lines_exp [i + 1 ]
147
+ skip = 0
148
+ while i_mupy + skip < len (lines_mupy ) and not line_exp [1 ].match (lines_mupy [i_mupy + skip ]):
149
+ skip += 1
150
+ if i_mupy + skip >= len (lines_mupy ):
151
+ lines_mupy [i_mupy ] = b'######## FAIL\n '
152
+ break
153
+ del lines_mupy [i_mupy :i_mupy + skip ]
154
+ lines_mupy .insert (i_mupy , b'########\n ' )
155
+ i_mupy += 1
156
+ else :
157
+ # a regex
158
+ if lines_exp [i ][1 ].match (lines_mupy [i_mupy ]):
159
+ lines_mupy [i_mupy ] = lines_exp [i ][0 ]
160
+ else :
161
+ #print("don't match: %r %s" % (lines_exp[i][1], lines_mupy[i_mupy])) # DEBUG
162
+ pass
163
+ i_mupy += 1
164
+ if i_mupy >= len (lines_mupy ):
165
+ break
166
+ output_mupy = b'' .join (lines_mupy )
167
+
163
168
return output_mupy
164
169
165
170
def run_tests (pyb , tests , args ):
0 commit comments