ControlFlowGraph { public Set<CfgBlock> blocks() { return blocks; } ControlFlowGraph(Set<CfgBlock> blocks, CfgBlock start, CfgBlock end); @CheckForNull static ControlFlowGraph build(FunctionDef functionDef, PythonFile file); @CheckForNull static ControlFlowGraph build(FileInput fileInput, PythonFile file); CfgBlock start(); CfgBlock end(); Set<CfgBlock> blocks(); @Override String toString();  }
@Test public void return_in_try() { ControlFlowGraph cfg = cfg( "before_try(succ = [try_body])", "try:", " try_body(succ = [except_cond], syntSucc = _empty)", " return", "except except_cond(succ = [except_block, finally_block]):", " except_block(succ = [finally_block])", "finally:", " finally_block(succ = [after_try, END])", " pass", "after_try(succ = [END])"); ExpectedCfgStructure expectedCfgStructure = ExpectedCfgStructure.parse(cfg.blocks(), expected -> { expected.createEmptyBlockExpectation() .withSuccessorsIds("except_cond", "finally_block"); return expected; }); new CfgValidator(expectedCfgStructure).assertCfg(cfg); }
@Test public void continue_in_try() { ControlFlowGraph cfg = cfg( "before_while(succ = [cond])", "while cond(succ = [try_body, after_while]):", " try:", " try_body(succ = [except_cond], syntSucc = _empty)", " continue", " except except_cond(succ = [except_block, finally_block]):", " except_block(succ = [finally_block])", " print()", " finally:", " finally_block(succ = [after_try, END])", " pass", " after_try(succ = [cond])", "after_while(succ = [END])"); ExpectedCfgStructure expectedCfgStructure = ExpectedCfgStructure.parse(cfg.blocks(), expected -> { expected.createEmptyBlockExpectation() .withSuccessorsIds("except_cond", "finally_block"); return expected; }); new CfgValidator(expectedCfgStructure).assertCfg(cfg); }