11"""Test runner for data-flow analysis test cases."""
22
33import os .path
4- import re
5- import shutil
6- from typing import List , Set
74
8- from mypy import build
9- from mypy .test .data import parse_test_cases , DataDrivenTestCase
5+ from mypy .test .data import DataDrivenTestCase
106from mypy .test .config import test_temp_dir
117from mypy .errors import CompileError
12- from mypy .options import Options
13- from mypy import experiments
148
159from mypyc import analysis
16- from mypyc import genops
1710from mypyc import exceptions
18- from mypyc .ops import format_func , Register , Value
11+ from mypyc .ops import format_func , is_empty_module_top_level
1912from mypyc .test .testutil import (
20- ICODE_GEN_BUILTINS , use_custom_builtins , MypycDataSuite , assert_test_output
13+ ICODE_GEN_BUILTINS , use_custom_builtins , MypycDataSuite , build_ir_for_single_file ,
14+ assert_test_output , remove_comment_lines
2115)
2216
2317files = [
@@ -34,35 +28,18 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
3428 """Perform a data-flow analysis test case."""
3529
3630 with use_custom_builtins (os .path .join (self .data_prefix , ICODE_GEN_BUILTINS ), testcase ):
37- program_text = '\n ' .join (testcase .input )
38-
39- options = Options ()
40- options .use_builtins_fixtures = True
41- options .show_traceback = True
42- options .python_version = (3 , 6 )
43- options .export_types = True
44-
45- source = build .BuildSource ('main' , '__main__' , program_text )
4631 try :
47- # Construct input as a single single.
48- # Parse and type check the input program.
49- result = build .build (sources = [source ],
50- options = options ,
51- alt_lib_path = test_temp_dir )
32+ ir = build_ir_for_single_file (testcase .input )
5233 except CompileError as e :
5334 actual = e .messages
5435 else :
55- if result .errors :
56- actual = result .errors
57- else :
58- modules = genops .build_ir ([result .files ['__main__' ]], result .types )
59- module = modules [0 ][1 ]
60- assert len (module .functions ) == 2 , (
61- "Only 1 function definition expected per test case" )
62- fn = module .functions [0 ]
36+ actual = []
37+ for fn in ir :
38+ if is_empty_module_top_level (fn ):
39+ # Skip trivial module top levels that only return.
40+ continue
6341 exceptions .insert_exception_handling (fn )
64- actual = format_func (fn )
65- actual = actual [actual .index ('L0:' ):]
42+ actual .extend (format_func (fn ))
6643 cfg = analysis .get_cfg (fn .blocks )
6744
6845 args = set (reg for reg , i in fn .env .indexes .items () if i < len (fn .args ))
@@ -85,7 +62,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
8562 else :
8663 assert False , 'No recognized _AnalysisName suffix in test case'
8764
88- actual .append ('' )
8965 for key in sorted (analysis_result .before .keys (),
9066 key = lambda x : (x [0 ].label , x [1 ])):
9167 pre = ', ' .join (sorted (reg .name
0 commit comments