mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
execute with local tracing environment
sadly the level passed is ignored, and it warns about an invalid filter directive but RUST_LOG environment variables work as expected
This commit is contained in:
@ -334,17 +334,20 @@ mod tests {
|
||||
use rand_chacha::ChaChaRng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::convert::TryInto;
|
||||
use tracing::{info, Level};
|
||||
use tracing::{info, Dispatch, Level};
|
||||
use tracing_subscriber::{filter::EnvFilter, FmtSubscriber};
|
||||
use vek::Vec2;
|
||||
|
||||
// enable info!
|
||||
fn init() {
|
||||
fn execute_with_tracing(level: Level, func: fn()) {
|
||||
tracing::dispatcher::with_default(
|
||||
&Dispatch::new(
|
||||
FmtSubscriber::builder()
|
||||
.with_max_level(Level::ERROR)
|
||||
.with_max_level(level)
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.try_init()
|
||||
.unwrap_or_default();
|
||||
.finish(),
|
||||
),
|
||||
func,
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -461,10 +464,13 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// output the economy of the currently active world
|
||||
// this expensive test is for manual inspection, not to be run automated
|
||||
// recommended command: cargo test test_economy0 -- --nocapture --ignored
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_economy0() {
|
||||
init();
|
||||
execute_with_tracing(Level::INFO, || {
|
||||
let threadpool = rayon::ThreadPoolBuilder::new().build().unwrap();
|
||||
info!("init");
|
||||
let seed = 59686;
|
||||
@ -482,12 +488,15 @@ mod tests {
|
||||
info!("Civs created");
|
||||
crate::sim2::simulate(&mut index, &mut sim);
|
||||
show_economy(&index.sites);
|
||||
});
|
||||
}
|
||||
|
||||
/// output the economy of a small set of villages, loaded from ron
|
||||
// this cheaper test is for manual inspection, not to be run automated
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_economy1() {
|
||||
init();
|
||||
execute_with_tracing(Level::INFO, || {
|
||||
let threadpool = rayon::ThreadPoolBuilder::new().build().unwrap();
|
||||
info!("init");
|
||||
let seed = 59686;
|
||||
@ -567,9 +576,13 @@ mod tests {
|
||||
common::terrain::site::SitesKind::Castle => crate::site::Site::castle(
|
||||
crate::site::Castle::generate(wpos, None, &mut rng),
|
||||
),
|
||||
common::terrain::site::SitesKind::Dungeon => crate::site::Site::dungeon(
|
||||
crate::site2::Site::generate_dungeon(&crate::Land::empty(), &mut rng, wpos),
|
||||
),
|
||||
common::terrain::site::SitesKind::Dungeon => {
|
||||
crate::site::Site::dungeon(crate::site2::Site::generate_dungeon(
|
||||
&crate::Land::empty(),
|
||||
&mut rng,
|
||||
wpos,
|
||||
))
|
||||
},
|
||||
// common::terrain::site::SitesKind::Settlement |
|
||||
_ => crate::site::Site::settlement(crate::site::Settlement::generate(
|
||||
wpos, None, &mut rng,
|
||||
@ -593,7 +606,9 @@ mod tests {
|
||||
let mut neighbors: Vec<crate::site::economy::NeighborInformation> = e
|
||||
.neighbors
|
||||
.iter()
|
||||
.flat_map(|(nid, dist)| index.sites.recreate_id(*nid).map(|i| (i, dist)))
|
||||
.flat_map(|(nid, dist)| {
|
||||
index.sites.recreate_id(*nid).map(|i| (i, dist))
|
||||
})
|
||||
.map(|(nid, dist)| crate::site::economy::NeighborInformation {
|
||||
id: nid,
|
||||
travel_distance: *dist,
|
||||
@ -612,6 +627,7 @@ mod tests {
|
||||
}
|
||||
crate::sim2::simulate(&mut index, &mut sim);
|
||||
show_economy(&index.sites);
|
||||
});
|
||||
}
|
||||
|
||||
struct Simenv {
|
||||
@ -621,7 +637,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
// test whether a site in moderate climate can survive on its own
|
||||
/// test whether a site in moderate climate can survive on its own
|
||||
fn test_economy_moderate_standalone() {
|
||||
fn add_settlement(
|
||||
env: &mut Simenv,
|
||||
@ -649,7 +665,7 @@ mod tests {
|
||||
id
|
||||
}
|
||||
|
||||
init();
|
||||
execute_with_tracing(Level::ERROR, || {
|
||||
let threadpool = rayon::ThreadPoolBuilder::new().build().unwrap();
|
||||
info!("init");
|
||||
let seed = 59686;
|
||||
@ -718,5 +734,6 @@ mod tests {
|
||||
for (id, site) in env.index.sites.iter() {
|
||||
assert!(site.economy.pop >= env.targets[&id]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user