-
Notifications
You must be signed in to change notification settings - Fork 34
/
mod.rs
122 lines (96 loc) · 2.46 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (C) 2019-2022 Daniel Mueller <[email protected]>
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
#![allow(clippy::eq_op)]
use tokio::runtime::Builder;
use tracing::debug;
use tracing::error;
use tracing::info;
use tracing::instrument;
mod something {
pub type Error = String;
}
use something::Error;
#[test_log::test]
fn without_return_type() {
assert_eq!(2 + 2, 4);
}
#[test_log::test]
fn with_return_type() -> Result<(), Error> {
Ok(())
}
#[test_log::test]
#[should_panic(expected = "success")]
fn with_panic() {
panic!("success")
}
#[test_log::test(tokio::test)]
async fn with_inner_test_attribute_and_async() {
assert_eq!(async { 42 }.await, 42)
}
#[instrument]
async fn instrumented(input: usize) -> usize {
info!("input = {}", input);
if input == 0 || input == 4 {
error!("here we go");
}
let result = input + 1;
info!("result = {}", result);
result
}
#[test_log::test]
fn trace_with_custom_runtime() {
let rt = Builder::new_current_thread().build().unwrap();
rt.block_on(async {
instrumented(0).await;
instrumented(1).await;
debug!("done");
})
}
#[test_log::test(tokio::test)]
async fn trace_with_tokio_attribute() {
instrumented(6).await;
instrumented(4).await;
debug!("done");
}
#[test_log::test(tokio::test(flavor = "multi_thread", worker_threads = 1))]
async fn trace_with_tokio_attribute_with_arguments() {
instrumented(6).await;
instrumented(4).await;
debug!("done");
}
// A trait containing `map` method that has the potential to cause
// ambiguities in generated initialization code and is here only to
// prevent accidental regressions. In the past we were susceptible to a
// compilation error because generated code was using Iterator::map (but
// not using fully qualified syntax).
trait Foo: Sized {
fn map(self) {}
}
impl<T> Foo for T {}
/// Make sure that Foo::map does not interfere with generated
/// initialization code.
#[test_log::test]
fn unambiguous_map() {}
/// A module used for testing the `test` attribute after importing it
/// via `use` instead of using fuller qualified syntax.
mod local {
use super::Error;
use test_log::test;
#[test]
fn without_return_type() {
assert_eq!(2 + 2, 4);
}
#[test]
fn with_return_type() -> Result<(), Error> {
Ok(())
}
#[test]
#[should_panic(expected = "success")]
fn with_panic() {
panic!("success")
}
#[test(tokio::test)]
async fn with_inner_test_attribute_and_async() {
assert_eq!(async { 42 }.await, 42)
}
}