dbrgn / tracing-test

Access and evaluate tracing logs in async and sync tests.
Apache License 2.0
62 stars 27 forks source link

logs_assert contain logs from other tests #18

Closed markcty closed 1 year ago

markcty commented 1 year ago

If the following tests run together, it will fail:

#[cfg(test)]
mod tests {
    use tracing::info;

    #[traced_test]
    #[test]
    fn no_log_from_other_test1() {
        info!("log count");
        logs_assert(|lines: &[&str]| {
            match lines
                .iter()
                .filter(|line| line.contains("log count"))
                .count()
            {
                1 => Ok(()),
                n => Err(format!("Count should be 1, but was {}", n)),
            }
        });
    }

    #[traced_test]
    #[test]
    fn no_log_from_other_test2() {
        info!("log count");
        logs_assert(|lines: &[&str]| {
            match lines
                .iter()
                .filter(|line| line.contains("log count"))
                .count()
            {
                1 => Ok(()),
                n => Err(format!("Count should be 1, but was {}", n)),
            }
        });
    }
}

I don't know if this is intentional. I created a PR to fix this problem.

markcty commented 1 year ago

See https://github.com/dbrgn/tracing-test/pull/19

dbrgn commented 1 year ago

Fixed in #19.