]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/libcoretest.rs
Simplify SaveHandler trait
[rust.git] / src / tools / tidy / src / libcoretest.rs
1 //! Tidy check to ensure `#[test]` is not used directly inside `libcore`.
2 //!
3 //! `#![no_core]` libraries cannot be tested directly due to duplicating lang
4 //! item. All tests must be written externally in `libcore/tests`.
5
6 use std::path::Path;
7
8 pub fn check(path: &Path, bad: &mut bool) {
9     let libcore_path = path.join("libcore");
10     super::walk(
11         &libcore_path,
12         &mut |subpath| t!(subpath.strip_prefix(&libcore_path)).starts_with("tests"),
13         &mut |entry, contents| {
14             let subpath = entry.path();
15             if let Some("rs") = subpath.extension().and_then(|e| e.to_str()) {
16                 let contents = contents.trim();
17                 if !contents.starts_with("//") && contents.contains("#[test]") {
18                     tidy_error!(
19                         bad,
20                         "`{}` contains `#[test]`; libcore tests must be placed inside \
21                         `src/libcore/tests/`",
22                         subpath.display()
23                     );
24                 }
25             }
26         },
27     );
28 }