8
8
import sys
9
9
10
10
from test_util import TestFailedError , run_command , \
11
- serializeIncrParseMarkupFile
11
+ serializeIncrParseMarkupFile , prepareForIncrParse
12
+
13
+
14
+ def testWithParserLib (test_file , test_case , pre_edit_file , post_edit_file ,
15
+ after_roundtrip_file , swiftsyntax_lit_test_helper ):
16
+ # =========================================================================
17
+ # First generate the pre-edit and post-edit Swift file and gather the edits
18
+ # and expected reparse regions. This is the parser for the special edit
19
+ # markup for testing incremental parsing
20
+ # =========================================================================
21
+
22
+ # Gather command line arguments for swift-syntax-test specifiying the
23
+ # performed edits in this list
24
+ incremental_edit_args = []
25
+ reparse_args = []
26
+ try :
27
+ prepareForIncrParse (test_file = test_file , test_case = test_case ,
28
+ pre_edit_file = pre_edit_file ,
29
+ post_edit_file = post_edit_file ,
30
+ incremental_edit_args = incremental_edit_args ,
31
+ reparse_args = reparse_args )
32
+ except TestFailedError as e :
33
+ print ('Test case "%s" of %s FAILed' % (test_case , test_file ),
34
+ file = sys .stderr )
35
+ print (e .message , file = sys .stderr )
36
+ sys .exit (1 )
37
+
38
+ try :
39
+ run_command ([swiftsyntax_lit_test_helper , '-parse-incremental' ] +
40
+ ['-old-source-file' , pre_edit_file ] +
41
+ ['-source-file' , post_edit_file ] +
42
+ incremental_edit_args + reparse_args +
43
+ ['-out' , after_roundtrip_file ])
44
+ except subprocess .CalledProcessError as e :
45
+ print ('Test case "%s" of %s FAILed' % (test_case , test_file ),
46
+ file = sys .stderr )
47
+ print ('Parsing the swift file failed:\n ' , file = sys .stderr )
48
+ print (e .output , file = sys .stderr )
49
+ sys .exit (1 )
50
+
51
+ # Check if the two syntax trees are the same
52
+ try :
53
+ run_command (
54
+ [
55
+ 'diff' , '-u' ,
56
+ post_edit_file ,
57
+ after_roundtrip_file
58
+ ])
59
+ except subprocess .CalledProcessError as e :
60
+ print ('Test case "%s" of %s FAILed' % (test_case , test_file ),
61
+ file = sys .stderr )
62
+ print ('Source file after incrementally parsing '
63
+ 'does not match post-edit source file:\n \n ' ,
64
+ file = sys .stderr )
65
+ print (e .output , file = sys .stderr )
66
+ sys .exit (1 )
12
67
13
68
14
69
def main ():
@@ -43,7 +98,7 @@ def main():
43
98
help = 'A temporary directory where pre-edit and post-edit files can be \
44
99
saved' )
45
100
parser .add_argument (
46
- '--swift-syntax-test' , required = True ,
101
+ '--swift-syntax-test' , required = False ,
47
102
help = 'The path to swift-syntax-test' )
48
103
parser .add_argument (
49
104
'--swiftsyntax-lit-test-helper' , required = True ,
@@ -67,6 +122,21 @@ def main():
67
122
if not os .path .exists (temp_dir ):
68
123
os .makedirs (temp_dir )
69
124
125
+ if not swift_syntax_test :
126
+ pre_edit_file = temp_dir + '/' + test_file_name + '.' + test_case + \
127
+ '.pre.swift'
128
+ post_edit_file = temp_dir + '/' + test_file_name + '.' + test_case + \
129
+ '.post.swift'
130
+ after_roundtrip_file = temp_dir + '/' + test_file_name + '.' \
131
+ + test_case + '.post_after_roundtrip.swift'
132
+ return testWithParserLib (test_file = test_file ,
133
+ test_case = test_case ,
134
+ pre_edit_file = pre_edit_file ,
135
+ post_edit_file = post_edit_file ,
136
+ after_roundtrip_file = after_roundtrip_file ,
137
+ swiftsyntax_lit_test_helper = swiftsyntax_lit_test_helper )
138
+
139
+
70
140
treeFileExtension = serialization_format
71
141
72
142
pre_edit_tree_file = temp_dir + '/' + test_file_name + '.' \
0 commit comments