已关闭
[issue]: bot-metric 存在对集成测试模块误报情况 #23
LeeLiangmin创建于  9月10日关闭于  9月23日
LeeLiangmin
LeeLiangmin成员
9月10日 创建

问题概述

bot-metric analyze --include-tests 执行时误报 error[BM102]:集成测试模块对应源文件存在,误报不存在。

影响范围

项目 内容
分析对象 Cargo 软件包
受影响的指标、规则或报告字段 quality gates 全部字段
影响程度 严重

复现步骤

简单的一个集成测试。文件结构如下:

demo/
├── .gitignore
├── Cargo.lock
├── Cargo.toml
├── src/
│ └── main.rs
└── tests/
├── tests.rs
└── util.rs

  1. tests/util.rs
pub fn sum(xs: &[i32]) -> i32 {
    return xs.iter().copied().sum();
}
  1. test/tests.rs
mod util;
#[test]
fn it_adds() {
    assert_eq!(util::sum(&[1,2,3]), 6);
}

复现步骤如下:

1.  进入到  demo 项目中
2.  执行:bot-metric analyze --include-tests

预期结果

预期是正常的 metric 的分析。

实际结果

Diagnostics
error[BM102]: module `util` declared in \\?\D:\test\bot-metric\demo\tests\tests.rs has no matching source file
  = definition: a declared module has no matching source file
  = help: create the `.rs` file, correct its path, or remove the declaration

分析环境与范围

项目 内容
BotMetric 版本或提交号 1.2.0
操作系统与架构 win11 / x86_64
软件包 / 目标 / 特性 / 范围参数
文件数 / 代码行数 2 / 15
likedislike
LeeLiangminLeeLiangmin成员
9月10日 添加了label:bug
LeeLiangminLeeLiangmin成员
9月10日 将 VaynNecol 设为负责人
WWangZijun成员
9月11日 移除了负责人 VaynNecol
WWangZijun成员
9月11日 将 WangZijun23 设为负责人
WWangZijun成员
9月23日 关联了pull request:fix: cover integration test module resolution (issue#23)
WangZijun成员
9月23日 评论:

https://gitcode.com/xuanwu/bot-metric/pulls/19

结论:

  • 问题可以复现(issue#19 修复前会稳定触发 BM102)。
  • 问题已修复,当前分支新增回归测试并验证集成测试模块正确解析。

具体修复:

  • Cargo 集成测试 target 按 crate root 解析模块,tests/tests.rs 的 mod util 正确解析到 tests/util.rs。
  • 新增 --include-tests 端到端回归测试,确认无 BM102 且模块状态为 resolved。
likedislike
VVaynNecol成员
9月23日 关联了pull request:fix: cover integration test module resolution (issue#23)
VVaynNecol成员
9月23日 关闭了 issue