From 1bb8267565731843d5df127ea1023e0819a6f972 Mon Sep 17 00:00:00 2001 From: tabokie Date: Mon, 13 Jun 2022 18:55:06 +0800 Subject: [PATCH] use ignore message instead of test name Signed-off-by: tabokie --- components/tikv_alloc/src/jemalloc.rs | 4 ++-- components/tikv_alloc/src/lib.rs | 31 ++++++++++----------------- rust-toolchain | 2 +- scripts/test-all | 2 +- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/components/tikv_alloc/src/jemalloc.rs b/components/tikv_alloc/src/jemalloc.rs index 8b87c82c7f8..e8a21115142 100644 --- a/components/tikv_alloc/src/jemalloc.rs +++ b/components/tikv_alloc/src/jemalloc.rs @@ -191,9 +191,9 @@ mod profiling { // // TODO: need a test for the dump_prof(None) case, but // the cleanup afterward is not simple. - #[allow(non_snake_case)] #[test] - fn test_profiling_memory_where_MALLOC_CONF() { + #[ignore = "#ifdef MALLOC_CONF"] + fn test_profiling_memory_ifdef_malloc_conf() { // Make sure somebody has turned on profiling assert!(is_profiling_on(), "set MALLOC_CONF=prof:true"); diff --git a/components/tikv_alloc/src/lib.rs b/components/tikv_alloc/src/lib.rs index f97ca325e56..e3e40e1a260 100644 --- a/components/tikv_alloc/src/lib.rs +++ b/components/tikv_alloc/src/lib.rs @@ -134,34 +134,25 @@ mod runner { extern crate test; use test::*; - /// Test cases with name _where_ will be checked for - /// whether the environment variable is set. Cases are ignored if its - /// depending variable is unset. + /// Check for test cases with ignore message "#ifdef ". The test + /// case will be un-ignored if the specific environment variable is set. pub fn run_env_conditional_tests(cases: &[&TestDescAndFn]) { let cases: Vec<_> = cases .iter() .map(|case| { let mut desc = case.desc.clone(); let testfn = match case.testfn { - TestFn::StaticTestFn(f) => TestFn::DynTestFn(Box::new(move || { - f(); - })), - TestFn::StaticBenchFn(f) => TestFn::DynTestFn(Box::new(move || { - bench::run_once(move |b| f(b)); - })), + TestFn::StaticTestFn(f) => TestFn::StaticTestFn(f), + TestFn::StaticBenchFn(f) => TestFn::StaticBenchFn(f), ref f => panic!("unexpected testfn {:?}", f), }; - if !desc.ignore { - let name = desc.name.as_slice().to_owned(); - if let Some(idx) = name.find("_where_") { - let v = &name[idx + 7..]; - if !v.is_empty() - && !v.chars().any(|c| c.is_ascii_lowercase()) - && std::env::var(v).is_err() - { - desc.ignore = true; - // TODO: uncomment this on a toolchain > 2022-02-25 - // desc.ignore_message = Some("required environment variable not set"); + if let Some(msg) = desc.ignore_message { + let keyword = "#ifdef"; + if let Some(idx) = msg.find(keyword) { + let v = &msg[idx + keyword.len()..].trim(); + if v.is_empty() || std::env::var(v).is_ok() { + desc.ignore = false; + desc.ignore_message = None; } } } diff --git a/rust-toolchain b/rust-toolchain index f24eb00edaf..b91c1b17580 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-02-14 +nightly-2022-05-01 diff --git a/scripts/test-all b/scripts/test-all index 3ee6dff285e..246a8f22176 100755 --- a/scripts/test-all +++ b/scripts/test-all @@ -16,7 +16,7 @@ fi # Re-run tests that requires specific environment variables. if [[ "$(uname)" == "Linux" ]]; then export MALLOC_CONF=prof:true - ./scripts/test where_MALLOC_CONF "$@" -- --nocapture + ./scripts/test ifdef_malloc_conf "$@" -- --nocapture fi if [[ "$(uname)" = "Linux" ]]; then