← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 743.d.2.b.5.a.2.a.3.a · 生成模型:GPT-6

编译失败测试核对诊断

理解等级:中级

编译期失败用独立样例触发,例如对不受支持的枚举应用 #[derive(Builder)]。在测试 runner 中用 trybuild::TestCases::new().compile_fail("tests/fails/*.rs"),核对错误输出,确认失败确由宏的输入限制触发,再保存相应的 .stderr 基线。仅断言编译失败会让漏导入等无关错误冒充预期结果。运行时失败另走正常可编译用例,例如对未设置字段的 build() 使用 #[should_panic]。

相关卡片 [[黑盒验证宏的调用行为]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Testing a builder macro 测试失败阶段并选择粒度 · 查看原书依据

      trybuild will verify that everything inside the chosen directory fails to compile. When you run it for the first time for a given test, it will output the error message it received (if any). If the error message matches your expectations, you add the generated output file to the folder your test is in. This approach makes a lot of sense: things can fail to compile for any number of stupid reasons.

    参考来源

    - 位置:《Write Powerful Rust Macros》第06章《Testing a builder macro》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-6.xhtml#p139) - 结论依据:清单 6.31–6.32 用 trybuild 编译派生于枚举的样例,原文要求人工确认产生的 .stderr 与预期一致。 - 原始内容:trybuild will verify that everything inside the chosen directory fails to compile. When you run it for the first time for a given test, it will output the error message it received (if any). If the error message matches your expectations, you add the generated output file to the folder your test is in. This approach makes a lot of sense: things can fail to compile for any number of stupid reasons.