erg/doc/zh_CN/dev_guide/test.md
GreasySlug c053fb55d0 doc(cn): update hash and contents
basically, copies from en doc
2024-05-20 00:26:01 +09:00

2.1 KiB
Raw Blame History

测试

badge

测试是确保代码质量的重要部分

使用以下命令执行测试

cargo test --features large_thread

由于cargo需要一个小线程来运行测试我们使用 large_thread 标志来避免堆栈溢出

放置测试

根据实现的特性来安排它们。将解析器测试放置在erg_parser/tests下,将编译器(类型检查器等)测试放置在erg_compiler/tests下,将用户可以直接使用的语言特性测试放置在erg/tests下(然而,这些测试目前正在开发中,不一定按照这种惯例安排)

如何编写测试

有两种类型的测试。positive测试和negative测试。 positive测试是检查编译器是否按预期运行的测试而negative测试是检查编译器是否正确地输出无效输入的错误。 由于编程语言处理器的性质,在所有软件中,它们特别容易受到无效输入的影响,并且必须始终将错误呈现给用户,因此后者也必须得到照顾。

如果你在语言中添加了一个新特性你至少需要写一个positive测试。另外如果可能的话请写同时编写negative测试。

#[ignore] attribute

The Erg development team recommends pre-commit. This prevents bugs from getting into the code by running tests before each commit, but some tests are time-consuming and slow down the commit.

Therefore, tests that are heavy or have a low probability of failure are marked with the #[ignore] attribute. Tests with the #[ignore] attribute are not run by cargo test, but can be run with cargo test -- --include-ignored. These tests are run by CI and do not need to be run on the local PC.