Skip to content

Commit 56e8210

Browse files
committed
port style.rs to syn and add tests for the style checker
1 parent 4abcd81 commit 56e8210

File tree

5 files changed

+816
-1
lines changed

5 files changed

+816
-1
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
target
22
Cargo.lock
33
*~
4-
style

libc-test/Cargo.toml

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ A test crate for the libc crate.
1515
[dependencies]
1616
libc = { path = "..", version = "1.0.0-alpha.1", default-features = false }
1717

18+
[dev-dependencies]
19+
syn = { version = "2.0.91", features = ["full", "visit"] }
20+
proc-macro2 = { version = "1.0.92", features = ["span-locations"] }
21+
glob = "0.3.2"
22+
annotate-snippets = { version = "0.11.5", features = ["testing-colors"] }
23+
1824
[build-dependencies]
1925
cc = "1.0.83"
2026
# FIXME: Use fork ctest until the maintainer gets back.
@@ -90,3 +96,13 @@ harness = false
9096
name = "primitive_types"
9197
path = "test/primitive_types.rs"
9298
harness = true
99+
100+
[[test]]
101+
name = "style"
102+
path = "test/check_style.rs"
103+
harness = true
104+
105+
[[test]]
106+
name = "style_tests"
107+
path = "test/style_tests.rs"
108+
harness = true

libc-test/test/check_style.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! Simple script to verify the coding style of this library.
2+
//!
3+
//! ## How to run
4+
//!
5+
//! The first argument to this script is the directory to run on, so running
6+
//! this script should be as simple as:
7+
//!
8+
//! ```notrust
9+
//! cargo test --test style
10+
//! ```
11+
12+
pub mod style;
13+
14+
use std::env;
15+
use std::path::Path;
16+
17+
use style::{Result, StyleChecker};
18+
19+
#[test]
20+
fn check_style() {
21+
let root_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../src");
22+
walk(&root_dir).unwrap();
23+
eprintln!("good style!");
24+
}
25+
26+
fn walk(root_dir: &Path) -> Result<()> {
27+
let mut style_checker = StyleChecker::new();
28+
29+
for entry in glob::glob(&format!(
30+
"{}/**/*.rs",
31+
root_dir.to_str().expect("dir should be valid UTF-8")
32+
))? {
33+
let entry = entry?;
34+
35+
let name = entry
36+
.file_name()
37+
.expect("file name should not end in ..")
38+
.to_str()
39+
.expect("file name should be valid UTF-8");
40+
if let "lib.rs" | "macros.rs" = &name[..] {
41+
continue;
42+
}
43+
44+
let path = entry.as_path();
45+
style_checker.check_file(path)?;
46+
style_checker.reset_state();
47+
}
48+
49+
style_checker.finalize()
50+
}

0 commit comments

Comments
 (0)