fix(cli): consume nonexistent --black-box dir; keep white report on empty black-box
This commit is contained in:
@@ -1394,8 +1394,10 @@ def _inject_c01_coverage_records(records, fields, base_assignments):
|
||||
def _extract_black_box_args(args: list) -> tuple[bool, str | None]:
|
||||
"""就地解析 --black-box / --no-black-box,返回 (do_black_box, black_box_arg)。
|
||||
|
||||
`--black-box <dir>`:仅当后一个 token 是「已存在的目录」且非 COBOL 源码后缀时
|
||||
才消费为目录;否则视为裸 `--black-box`(自动探测 <outdir>/<PGM>/black_box)。
|
||||
`--black-box <dir>`:后一个 token 非 `--` 开头且不是 COBOL 源码后缀(.cbl/.cob/.cpy)
|
||||
时消费为目录;否则视为裸 `--black-box`(自动探测 <outdir>/<PGM>/black_box)。
|
||||
这样既支持 `--black-box <source.cbl> <outdir>` 的自动探测形式,也不会把
|
||||
尚不存在(或拼写错误)的目录 token 漏给位置参数分类逻辑而误判为 outdir。
|
||||
"""
|
||||
do_black_box = False
|
||||
black_box_arg = None
|
||||
@@ -1404,6 +1406,7 @@ def _extract_black_box_args(args: list) -> tuple[bool, str | None]:
|
||||
a = args[i]
|
||||
if a == '--no-black-box':
|
||||
do_black_box = False
|
||||
black_box_arg = None
|
||||
args.pop(i)
|
||||
continue
|
||||
if a == '--black-box':
|
||||
@@ -1411,7 +1414,6 @@ def _extract_black_box_args(args: list) -> tuple[bool, str | None]:
|
||||
if i + 1 < len(args):
|
||||
nxt = args[i + 1]
|
||||
if (not nxt.startswith('--')
|
||||
and Path(nxt).is_dir()
|
||||
and Path(nxt).suffix.upper() not in ('.CBL', '.COB', '.CPY')):
|
||||
black_box_arg = nxt
|
||||
args.pop(i + 1)
|
||||
@@ -1927,6 +1929,13 @@ def main():
|
||||
bb_groups = load_black_box_groups(bb_dir, fd_fields, select_info, fields_dict)
|
||||
if not bb_groups:
|
||||
logger.warning(f" --black-box: 未在 {bb_dir} 找到可用黑盒数据,跳过")
|
||||
if white_java_reports:
|
||||
try:
|
||||
_write_java_test_report(str(prog_outdir), filepath.stem,
|
||||
list(group_results),
|
||||
list(white_java_reports))
|
||||
except Exception as e: # noqa: BLE001
|
||||
logger.warning(f" 测试报告生成失败: {e}")
|
||||
else:
|
||||
_bb_temp = temp_dir or str(prog_outdir / '.gcov_cache')
|
||||
bb_results, bb_java_reports = run_external_groups(
|
||||
@@ -1940,8 +1949,11 @@ def main():
|
||||
all_results = list(group_results) + list(bb_results)
|
||||
all_reports = list(white_java_reports) + list(bb_java_reports)
|
||||
if all_reports:
|
||||
_write_java_test_report(str(prog_outdir), filepath.stem,
|
||||
all_results, all_reports)
|
||||
try:
|
||||
_write_java_test_report(str(prog_outdir), filepath.stem,
|
||||
all_results, all_reports)
|
||||
except Exception as e: # noqa: BLE001
|
||||
logger.warning(f" 测试报告生成失败: {e}")
|
||||
|
||||
if do_run and proc_div and _HAVE_RUNNER:
|
||||
run_and_compare(
|
||||
|
||||
@@ -48,3 +48,19 @@ def test_no_flags_leaves_args_untouched():
|
||||
assert do is False
|
||||
assert arg is None
|
||||
assert args == ["src.cbl", "out"]
|
||||
|
||||
|
||||
def test_black_box_nonexistent_dir_consumed():
|
||||
args = ["--black-box", "no/such/dir", "src.cbl", "out"]
|
||||
do, arg = _extract_black_box_args(args)
|
||||
assert do is True
|
||||
assert arg == "no/such/dir"
|
||||
assert args == ["src.cbl", "out"]
|
||||
|
||||
|
||||
def test_no_black_box_resets_arg():
|
||||
args = ["--black-box", "bbdir", "--no-black-box", "src.cbl"]
|
||||
do, arg = _extract_black_box_args(args)
|
||||
assert do is False
|
||||
assert arg is None
|
||||
assert args == ["src.cbl"]
|
||||
|
||||
Reference in New Issue
Block a user