erg/doc/zh_TW/dev_guide/test.md
GreasySlug 960832eb35 doc(tw): update hash and contents
basically, copies from en doc
2024-05-20 00:26:13 +09:00

2.1 KiB
Raw Permalink 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.