Skip to content

Commit

Permalink
use ignore message instead of test name
Browse files Browse the repository at this point in the history
Signed-off-by: tabokie <xy.tao@outlook.com>
  • Loading branch information
tabokie committed Jun 13, 2022
1 parent 1ddb4da commit 1bb8267
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
4 changes: 2 additions & 2 deletions components/tikv_alloc/src/jemalloc.rs
Expand Up @@ -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");

Expand Down
31 changes: 11 additions & 20 deletions components/tikv_alloc/src/lib.rs
Expand Up @@ -134,34 +134,25 @@ mod runner {
extern crate test;
use test::*;

/// Test cases with name <name>_where_<ENV_VAR_NAME> 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 <VAR_NAME>". 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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
@@ -1 +1 @@
nightly-2022-02-14
nightly-2022-05-01
2 changes: 1 addition & 1 deletion scripts/test-all
Expand Up @@ -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
Expand Down

0 comments on commit 1bb8267

Please sign in to comment.