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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//! This module provides a way to run tests with reusing
//! the same [`Executor`] via [`run_test_and_block_on_local`]
//! and [`run_test_and_block_on_shared`].
//!
//! # Example
//!
//! ```no_run
//! use orengine::test::run_test_and_block_on_local;
//!
//! async fn awesome_async_function() -> usize {
//! 42
//! }
//!
//! #[cfg(test)]
//! fn test_awesome_async_function() {
//! run_test_and_block_on_local(async {
//! assert_eq!(awesome_async_function().await, 42);
//! });
//! }
//! ```
//!
//! # Shortcuts
//!
//! You can use macro [`orengine::test::test_local`](crate::test::test_local) instead
//! of [`run_test_and_block_on_local`] and [`orengine::test::test_shared`](crate::test::test_shared)
//! instead of [`run_test_and_block_on_shared`]. Read [`run_test_and_block_on_local`] and
//! [`run_test_and_block_on_shared`] for examples.
use crateBUG_MESSAGE;
use crateget_local_executor_ref;
use crateConfig;
use crate::;
use Future;
/// Initializes the local executor only if it is not initialized
/// and returns `&'static mut Executor`.
pub
/// Upgrades provided future to release all previous tasks.
pub async
/// Initializes the local executor (if it is not initialized) and blocks the current
/// thread until the `local` future is completed.
///
/// # The difference between `run_test_and_block_on_local` and [`run_test_and_block_on_shared`]
///
/// `run_test_and_block_on_local` creates a `local` task, while `run_test_and_block_on_shared`
/// creates a `shared` task.
///
/// Read more about `local` and `shared` tasks in [`Executor`].
///
/// # Example
///
/// ```no_run
/// use orengine::test::run_test_and_block_on_local;
///
/// async fn awesome_async_function() -> usize {
/// 42
/// }
///
/// #[cfg(test)]
/// fn test_awesome_async_function() {
/// run_test_and_block_on_local(async {
/// assert_eq!(awesome_async_function().await, 42);
/// });
/// }
/// ```
///
/// # Shortcut
///
/// You can use [`orengine::test::test_local`](crate::test::test_local).
/// An example below is equivalent to the one above:
///
/// ```no_run
/// async fn awesome_async_function() -> usize {
/// 42
/// }
///
/// #[orengine::test::test_local]
/// fn test_awesome_async_function() {
/// assert_eq!(awesome_async_function().await, 42);
/// }
/// ```
/// Initializes the local executor (if it is not initialized) and blocks the current
/// thread until the `shared` future is completed.
///
/// # The difference between `run_test_and_block_on_shared` and [`run_test_and_block_on_local`]
///
/// `run_test_and_block_on_shared` creates a `shared` task, while `run_test_and_block_on_local`
/// creates a `local` task.
///
/// Read more about `local` and `shared` tasks in [`Executor`].
///
/// # Example
///
/// ```no_run
/// use orengine::test::run_test_and_block_on_shared;
/// # async fn get_some_result_from_shared_state() -> Result<(), ()> { Ok(()) }
///
/// async fn awesome_async_shared_function() -> usize {
/// if get_some_result_from_shared_state().await.is_err() {
/// return 0;
/// }
///
/// 3
/// }
///
/// #[cfg(test)]
/// fn test_awesome_async_function() {
/// run_test_and_block_on_shared(async {
/// assert_eq!(awesome_async_shared_function().await, 3);
/// });
/// }
/// ```
///
/// # Shortcut
///
/// You can use [`orengine::test::test_shared`](crate::test::test_shared).
/// An example below is equivalent to the one above:
///
/// ```no_run
/// # async fn get_some_result_from_shared_state() -> Result<(), ()> { Ok(()) }
///
/// async fn awesome_async_shared_function() -> usize {
/// if get_some_result_from_shared_state().await.is_err() {
/// return 0;
/// }
///
/// 3
/// }
///
/// #[orengine::test::test_shared]
/// fn test_awesome_async_function() {
/// assert_eq!(awesome_async_shared_function().await, 3);
/// }
/// ```