fix: code review issues #1-#9
1. cond.py: 删除重复裸字段代码块 (dedup bare field) 2. coverage.py: 移除_mark_perform无条件fallback (虚假覆盖) 3. pipeline_bridge.py: except:pass加日志记录异常 4. __init__.py: generate_data文档更新 (copybook_dirs等) 5. cond.py: is_field贪婪→非贪婪.*→.*? 6. coverage.py: 移除残留无条件Enter+Skip标记 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -942,9 +942,11 @@ def generate_data(cobol_source: str, structure: dict = None,
|
||||
|
||||
Args:
|
||||
cobol_source: COBOL 程序原始源码文本(未预处理)。
|
||||
内部会调 preprocess + resolve_copybooks。
|
||||
如果已预处理过,传进来会因 COPYBOOK 路径丢失导致字段不全。
|
||||
内部会调 preprocess + resolve_copybooks + resolve_sql_includes。
|
||||
如果已预处理过,传进来会因字段列表不全导致数据不完整。
|
||||
COPYBOOK 路径通过 copybook_dirs 参数传入。
|
||||
structure: 可选,如果已调用 extract_structure() 可传入避免重复解析
|
||||
copybook_dirs: 可选,COPYBOOK 搜索路径列表。指定后可自动展开 COPY 和 EXEC SQL INCLUDE。
|
||||
|
||||
Returns:
|
||||
list[dict]: 测试数据记录列表,每条包含所有字段的值
|
||||
|
||||
@@ -269,7 +269,7 @@ def evaluate_tree(tree, assignment):
|
||||
|
||||
def is_field(name, fields):
|
||||
# Strip subscript: WS-ITEM-STATUS(WS-INDEX-VAR) -> WS-ITEM-STATUS
|
||||
bare = re.sub(r'\s*\(.*\)\s*$', '', name).strip()
|
||||
bare = re.sub(r'\s*\(.*?\)\s*$', '', name).strip()
|
||||
for f in fields:
|
||||
if f['name'] == bare.upper():
|
||||
return True
|
||||
|
||||
@@ -410,9 +410,10 @@ def _mark_perform(dp, cons):
|
||||
else:
|
||||
dp.active_branches.add('Enter')
|
||||
|
||||
if len(dp.active_branches) < 2:
|
||||
dp.active_branches.add('Enter')
|
||||
dp.active_branches.add('Skip')
|
||||
# No unconditional fallback — coverage must come from actual constraint matching
|
||||
# If __DP synthetic constraint exists, it was handled above; if parsed matching
|
||||
# fails, this PERFORM stays uncovered — honest reporting is better than false 100%
|
||||
pass
|
||||
|
||||
|
||||
def _get_fields_in_cond(cond_text):
|
||||
|
||||
@@ -4,7 +4,10 @@ Primary: new procedure_parser (fast, deterministic, no path explosion).
|
||||
Fallback: old BrParser (timeout-guarded for programs new parser can't handle).
|
||||
"""
|
||||
|
||||
import logging
|
||||
from .models import BrSeq, BrIf, BrEval, BrPerform, BrSearch, GoTo
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from .procedure_parser import extract_branch_tree as new_parse, BranchNode
|
||||
|
||||
|
||||
@@ -18,7 +21,8 @@ def build_branch_tree_fallback(proc_text, fields=None):
|
||||
root, assigns_list = new_parse(proc_text, fields)
|
||||
new_tree = _convert_to_model(root)
|
||||
new_assigns = _assigns_list_to_dict(assigns_list)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.warning(f"New parser failed: {e}")
|
||||
pass
|
||||
|
||||
# New parser generates O(N) paths (not O(2^N)), so no cap needed.
|
||||
@@ -42,7 +46,8 @@ def build_branch_tree_fallback(proc_text, fields=None):
|
||||
if d[0] and not e[0] and r[0]:
|
||||
ot, oa = r[0]
|
||||
old_tree, old_assigns = ot, oa
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.warning(f"Old parser fallback failed: {e}")
|
||||
pass
|
||||
|
||||
if old_tree is not None:
|
||||
|
||||
Reference in New Issue
Block a user