fix(cli): always persist white report before black-box run; handle empty --black-box=
This commit is contained in:
+18
-24
@@ -1421,7 +1421,8 @@ def _extract_black_box_args(args: list) -> tuple[bool, str | None]:
|
||||
continue
|
||||
if a.startswith('--black-box='):
|
||||
do_black_box = True
|
||||
black_box_arg = a.split('=', 1)[1]
|
||||
val = a.split('=', 1)[1]
|
||||
black_box_arg = val or None
|
||||
args.pop(i)
|
||||
continue
|
||||
i += 1
|
||||
@@ -1910,7 +1911,7 @@ def main():
|
||||
multi_write_fds=multi_write_fds,
|
||||
skip_records=skip_records,
|
||||
skip_term_types=skip_term_types,
|
||||
write_report=not do_black_box,
|
||||
write_report=True,
|
||||
)
|
||||
|
||||
passed = sum(1 for r in group_results if r.passed)
|
||||
@@ -1929,31 +1930,24 @@ 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(
|
||||
filepath.stem, str(prog_outdir), _bb_temp,
|
||||
fields_dict, fd_fields, select_info, open_dir,
|
||||
roles, field_to_fd, bb_groups,
|
||||
source_dir=str(filepath.parent),
|
||||
data_fields=fields_dict,
|
||||
multi_write_fds=multi_write_fds,
|
||||
)
|
||||
all_results = list(group_results) + list(bb_results)
|
||||
all_reports = list(white_java_reports) + list(bb_java_reports)
|
||||
if all_reports:
|
||||
try:
|
||||
try:
|
||||
_bb_temp = temp_dir or str(prog_outdir / '.gcov_cache')
|
||||
bb_results, bb_java_reports = run_external_groups(
|
||||
filepath.stem, str(prog_outdir), _bb_temp,
|
||||
fields_dict, fd_fields, select_info, open_dir,
|
||||
roles, field_to_fd, bb_groups,
|
||||
source_dir=str(filepath.parent),
|
||||
data_fields=fields_dict,
|
||||
multi_write_fds=multi_write_fds,
|
||||
)
|
||||
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)
|
||||
except Exception as e: # noqa: BLE001
|
||||
logger.warning(f" 测试报告生成失败: {e}")
|
||||
except Exception as e: # noqa: BLE001
|
||||
logger.warning(f" 黑盒运行/比对失败,保留白盒报告: {e}")
|
||||
|
||||
if do_run and proc_div and _HAVE_RUNNER:
|
||||
run_and_compare(
|
||||
|
||||
@@ -64,3 +64,11 @@ def test_no_black_box_resets_arg():
|
||||
assert do is False
|
||||
assert arg is None
|
||||
assert args == ["src.cbl"]
|
||||
|
||||
|
||||
def test_black_box_equals_empty_value():
|
||||
args = ["--black-box=", "src.cbl"]
|
||||
do, arg = _extract_black_box_args(args)
|
||||
assert do is True
|
||||
assert arg is None
|
||||
assert args == ["src.cbl"]
|
||||
|
||||
Reference in New Issue
Block a user