1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use anyhow::Result;
#[allow(clippy::wildcard_imports)]
use dylint_internal::{self, cargo::*};
use std::{
fs::read_dir,
path::{Path, PathBuf},
};
pub fn build() -> Result<()> {
dylint_internal::build()
.sanitize_environment()
.current_dir(
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join("dylint-link"),
)
.success()?;
for example in iter()? {
let example = example?;
dylint_internal::build()
.sanitize_environment()
.current_dir(&example)
.success()?;
}
Ok(())
}
pub fn iter() -> Result<impl Iterator<Item = Result<PathBuf>>> {
let iter = read_dir(env!("CARGO_MANIFEST_DIR"))?;
Ok(iter
.map(|entry| -> Result<Option<PathBuf>> {
let entry = entry?;
let path = entry.path();
Ok(
if path.is_dir() && path.file_name() != Some(std::ffi::OsStr::new("src")) {
Some(path)
} else {
None
},
)
})
.filter_map(Result::transpose))
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn examples() {
for path in iter().unwrap() {
let path = path.unwrap();
dylint_internal::test()
.sanitize_environment()
.current_dir(path)
.success()
.unwrap();
}
}
}