From 9afb2ddfa223d6cb8f1850a1e94c92ab9b04d232 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 23 Jul 2025 23:18:05 -0500 Subject: [PATCH] test: Move style logic to `libc-test` source This doesn't need to reside only within the test directory, so move it to the library to make testing simpler. --- ci/run.sh | 2 +- libc-test/Cargo.toml | 13 ++++--------- libc-test/src/lib.rs | 1 + libc-test/{test/style/mod.rs => src/style.rs} | 7 ++++--- .../{test/style_tests.rs => src/style/tests.rs} | 4 +--- libc-test/test/{check_style.rs => style.rs} | 4 +--- 6 files changed, 12 insertions(+), 19 deletions(-) create mode 100644 libc-test/src/lib.rs rename libc-test/{test/style/mod.rs => src/style.rs} (98%) rename libc-test/{test/style_tests.rs => src/style/tests.rs} (99%) rename libc-test/test/{check_style.rs => style.rs} (96%) diff --git a/ci/run.sh b/ci/run.sh index 2d38c0324a5d0..05ff70a2dbdbe 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -10,7 +10,7 @@ target="$1" export RUST_BACKTRACE="${RUST_BACKTRACE:-1}" cmd="cargo test --target $target ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}" -test_flags="--skip check_style" +test_flags="--skip style" # Run tests in the `libc` crate case "$target" in diff --git a/libc-test/Cargo.toml b/libc-test/Cargo.toml index 8163d07f5cfbb..80a8285ca9aa6 100644 --- a/libc-test/Cargo.toml +++ b/libc-test/Cargo.toml @@ -9,14 +9,14 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/libc" [dependencies] +annotate-snippets = { version = "0.11.5", features = ["testing-colors"] } cfg-if = "1.0.1" libc = { path = "..", version = "1.0.0-alpha.1", default-features = false } +proc-macro2 = { version = "1.0.95", features = ["span-locations"] } +syn = { version = "2.0.104", features = ["full", "visit"] } [dev-dependencies] -syn = { version = "2.0.104", features = ["full", "visit"] } -proc-macro2 = { version = "1.0.95", features = ["span-locations"] } glob = "0.3.2" -annotate-snippets = { version = "0.11.5", features = ["testing-colors"] } [build-dependencies] cc = "1.2.29" @@ -95,12 +95,7 @@ harness = true [[test]] name = "style" -path = "test/check_style.rs" -harness = true - -[[test]] -name = "style_tests" -path = "test/style_tests.rs" +path = "test/style.rs" harness = true # FIXME(msrv): These should be moved to the root Cargo.toml as `[workspace.lints.*]` diff --git a/libc-test/src/lib.rs b/libc-test/src/lib.rs new file mode 100644 index 0000000000000..b878bb2c484e9 --- /dev/null +++ b/libc-test/src/lib.rs @@ -0,0 +1 @@ +pub mod style; diff --git a/libc-test/test/style/mod.rs b/libc-test/src/style.rs similarity index 98% rename from libc-test/test/style/mod.rs rename to libc-test/src/style.rs index cc953d32c3aed..857f70f2249e4 100644 --- a/libc-test/test/style/mod.rs +++ b/libc-test/src/style.rs @@ -1,9 +1,7 @@ //! Provides the [StyleChecker] visitor to verify the coding style of //! this library. //! -//! This is split out so that the implementation itself can be tested -//! separately, see test/check_style.rs for how it's used and -//! test/style_tests.rs for the implementation tests. +//! See `tests/style.rs` for the invocation that gets run on CI. //! //! ## Guidelines //! @@ -37,6 +35,9 @@ use syn::spanned::Spanned; use syn::visit::{self, Visit}; use syn::Token; +#[cfg(test)] +mod tests; + const ALLOWED_REPEATED_MACROS: &[&str] = &["s", "s_no_extra_traits", "s_paren"]; pub type Error = Box; diff --git a/libc-test/test/style_tests.rs b/libc-test/src/style/tests.rs similarity index 99% rename from libc-test/test/style_tests.rs rename to libc-test/src/style/tests.rs index be8fddbccf644..5e7f506c33c7e 100644 --- a/libc-test/test/style_tests.rs +++ b/libc-test/src/style/tests.rs @@ -1,8 +1,6 @@ //! Verifies the implementation of the style checker in [style]. -use style::StyleChecker; - -pub mod style; +use super::StyleChecker; #[test] fn check_style_accept_correct_module_layout() { diff --git a/libc-test/test/check_style.rs b/libc-test/test/style.rs similarity index 96% rename from libc-test/test/check_style.rs rename to libc-test/test/style.rs index 24f793e4feb86..a088283d7330b 100644 --- a/libc-test/test/check_style.rs +++ b/libc-test/test/style.rs @@ -9,12 +9,10 @@ //! cargo test --test style //! ``` -pub mod style; - use std::env; use std::path::Path; -use style::{Result, StyleChecker}; +use libc_test::style::{Result, StyleChecker}; /// Relative to `src/`. const SKIP_PREFIXES: &[&str] = &[