-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_architecture.rs
89 lines (76 loc) · 2.83 KB
/
test_architecture.rs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#![cfg(test)]
use rust_arkitect::dsl::architectural_rules::ArchitecturalRules;
use rust_arkitect::dsl::arkitect::Arkitect;
use rust_arkitect::dsl::project::Project;
#[test]
fn test_architectural_rules() {
Arkitect::init_logger();
let project = Project::from_current_crate();
#[rustfmt::skip]
let rules = ArchitecturalRules::define()
.rules_for_project()
.it_must_not_have_circular_dependencies(999)
.rules_for_module("rust_arkitect::dsl")
.it_may_depend_on(&[
"rust_arkitect::engine",
"rust_arkitect::builtin_rules",
"rust_arkitect::rule",
"rust_arkitect::rust_file",
"std::collections",
"std::marker::PhantomData",
"std::path",
"std::fmt",
"std::env",
"std::fs"
])
.rules_for_module("rust_arkitect::engine")
.it_may_depend_on(&[
"rust_arkitect::rule",
"rust_arkitect::rust_file",
"rust_arkitect::rust_project",
"ansi_term",
"log",
"std::env",
"std::fs",
"std::path",
"toml"
])
.rules_for_module("rust_arkitect::builtin_rules")
.it_may_depend_on(&[
"rust_arkitect::rust_file",
"rust_arkitect::rust_project",
"rust_arkitect::rule",
"ansi_term",
"log",
"std::fmt",
"std::collections",
])
.rules_for_crate("rust_arkitect::rule")
.it_may_depend_on(&[
"rust_arkitect::rust_file",
"rust_arkitect::rust_project",
"std::fmt",
])
.rules_for_crate("rust_arkitect::rust_file")
.it_may_depend_on(&[
"rust_arkitect::dependency_parsing", // Used to parse dependencies, only this module is allowed to depend on it
"std::path", // Used to navigate the file system and get the logical name of the module
"syn", // Used to parse Rust code and build the AST
"toml", // Used to read Cargo.toml and find the crate of the file
])
.rules_for_crate("rust_arkitect::dependency_parsing")
.it_may_depend_on(&[
"syn",
"std::collections",
"std::path",
"std::ops",
"std::fs"
])
.build();
let result = Arkitect::ensure_that(project).complies_with(rules);
assert!(
result.is_ok(),
"Detected {} violations",
result.err().unwrap().len()
);
}