73个版本 (稳定版)

3.1.2 2024年5月15日
3.1.0 2024年4月30日
3.0.0 2024年3月15日
2.6.1 2024年1月23日
0.1.0-pre.32021年3月29日

#396 in 测试

Download history 95/week @ 2024-05-03 282/week @ 2024-05-10 118/week @ 2024-05-17 53/week @ 2024-05-24 63/week @ 2024-05-31 83/week @ 2024-06-07 62/week @ 2024-06-14 71/week @ 2024-06-21 39/week @ 2024-06-28 75/week @ 2024-07-05 164/week @ 2024-07-12 210/week @ 2024-07-19 372/week @ 2024-07-26 109/week @ 2024-08-02 108/week @ 2024-08-09 360/week @ 2024-08-16

1,038 每月下载量

MIT/Apache

200KB
4K SLoC

dylint测试

docs.rs 文档

此包提供对 compiletest_rs 包的便捷访问,用于测试 Dylint 库。

注意:如果您的测试有依赖项,您必须使用 ui_test_exampleui_test_examples 请参阅此存储库中的 question_mark_in_expression 示例。

此包提供以下三个函数

对于大多数情况,您可以在库的 lib.rs 文件中添加以下内容

#[test]
fn ui() {
    dylint_testing::ui_test(
        env!("CARGO_PKG_NAME"),
        &std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("ui"),
    );
}

并在库的 src 目录旁边的一个或多个 .rs.stderr 文件中包含一个 ui 目录。请参阅此存储库中的 示例

测试构建器

除了上述三个功能之外,ui::Test 是一个测试 "构建器"。目前,使用 Test 而不是上述函数的主要优势在于,Test 允许将标志传递给 rustc。有关其使用的示例,请参阅此存储库中的 non_thread_safe_call_in_test

Test 有三个构造函数,分别对应上述三个函数如下

在这种情况下,构造函数的参数与相应函数的参数完全相同。

Test 实例有以下方法

  • dylint_toml - 设置 dylint.toml 文件的内容(用于测试 可配置库
  • rustc_flags - 在运行测试时传递标志
  • run - 运行测试

更新 .stderr 文件

如果运行你的 .rs 文件产生的标准错误与你的 .stderr 文件内容不同,compiletest_rs 将生成如下报告

diff of stderr:

 error: calling `std::env::set_var` in a test could affect the outcome of other tests
   --> $DIR/main.rs:8:5
    |
 LL |     std::env::set_var("KEY", "VALUE");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `-D non-thread-safe-call-in-test` implied by `-D warnings`

-error: aborting due to previous error
+error: calling `std::env::set_var` in a test could affect the outcome of other tests
+  --> $DIR/main.rs:23:9
+   |
+LL |         std::env::set_var("KEY", "VALUE");
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors



The actual stderr differed from the expected stderr.
Actual stderr saved to ...

每行的含义如下

  • 以加号 (+) 开头的行实际标准错误中存在,但不在你的 .stderr 文件中。
  • 以减号 (-) 开头的行在你 .stderr 文件中存在,但不在实际标准错误中。
  • 以空格 ( ) 开头的行在实际标准错误和你的 .stderr 文件中都存在,并提供上下文。
  • 所有其他行(例如,diff of stderr:)包含 compiletest_rs 消息。

注意: 在实际标准错误中,通常在 error: aborting due to N previous errors 行之后跟一个空行。因此,正确的 .stderr 文件通常在末尾包含一个空行。

通常情况下,手动更新 .stderr 文件并不太难。然而,compiletest_rs 报告应该包含形如 实际 stderr 保存到 PATH 的行。将 PATH 复制到您的 .stderr 文件中应能完全更新它。

有关 compiletest_rs 的更多文档可以在 其仓库 中找到。

依赖项

~17–28MB
~497K SLoC