Created
November 17, 2021 13:10
-
-
Save chertov/772076dc74b5382c12ff4c9b77c23749 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// коллбеки на все найденые тесты в нашем проекте | |
type TestFunction = fn() -> Result<(), anyhow::Error>; | |
// глобальный лист всех найденных тестов, который сформируется при загрузке библиотеки в тарантул | |
static TESTS: once_cell::sync::Lazy<parking_lot::RwLock<std::collections::HashMap<String, TestFunction>>> = | |
once_cell::sync::Lazy::new(|| { | |
parking_lot::RwLock::new(std::collections::HashMap::new()) | |
}); | |
// для нашего теста fn test1 процедурный макрос атрибут tnt_test сегенерирует следующую функцию | |
// т.к. у нас используется ctor она будет вызвана при загрузке либы в тарантуле и мы сохраним | |
// информацию о нашем тесте | |
// #[ctor::ctor] | |
// fn test1__init() { | |
// TESTS.write().insert("test".to_string(), test); | |
// } | |
#[tnt_test] | |
pub fn test1() -> Result<(), anyhow::Error> { | |
// .. проверяем функционал | |
Ok(()) | |
} | |
// Запускаем из потока тарантула! для выполнения всех тестов | |
pub fn run_all() -> Result<(), anyhow::Error> { | |
for (test_name, test_func) in TESTS.read() { | |
match test_func() { | |
Ok(()) => trace!("test {} is ok", test_name), | |
Err(err) => error!("test {} is failed! err {:?}", test_name, err), | |
}; | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment