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
// SPDX-License-Identifier: MPL-2.0
/*!
This module provides test support utilities working with the main thread.
Your main options are:
* doctests using `doctest_main`
* integration tests using `integration_test_harness`
Examples using this module are kept in the `examples/test_example` crate.
*/
/**
A custom test harness for integration tests.
The test harness will:
1. Bring up the main thread environment
2. Run the provided closure
3. Tear down the main thread environment
# Example
To use this, add the following to your `Cargo.toml`:
```toml
[[test]]
name = "your_custom_test_name"
path = "tests/your_custom_test_name.rs"
harness = false
```
Then in `tests/your_custom_test_name.rs`:
```rust,no_run
# // no_run because: this is a code example
# #[allow(clippy::needless_doctest_main)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn main() {
app_window::test_support::integration_test_harness(|| {
test_fn_1();
test_fn_2();
});
fn test_fn_1() { }
fn test_fn_2() { }
}
```
# Caveats
* This must be called from the main thread.
* On wasm32, this should be marked #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
*/
/**
A version of [`crate::application::main`] for doctests.
doctests generally pick one of two execution models:
* On most platforms, they run in separate processes, on the main thread
* On wasm32, they run in one process, on the main thread sequentially
This function implements a version of `main` that works in both cases.
It brings up a temporary main thread environment for the duration of the test.
Note: wasm_thread does not generally work in node.js, so you may need to run your tests in a browser.
```
#[cfg(target_arch = "wasm32")] {
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
}
use app_window::test_support::doctest_main;
eprintln!("Will call doctest_main");
doctest_main(|| {
eprintln!("Hello world");
});
```
*/