1 | // Bare metal platforms usually have very small amounts of RAM |
2 | // (in the order of hundreds of KB) |
3 | pub const DEFAULT_BUF_SIZE: usize = if cfg!(target_os = "espidf" ) { 512 } else { 8 * 1024 }; |
4 | |
5 | #[cfg (test)] |
6 | #[allow (dead_code)] // not used on emscripten |
7 | pub mod test { |
8 | use crate::env; |
9 | use crate::fs; |
10 | use crate::path::{Path, PathBuf}; |
11 | use crate::thread; |
12 | use rand::RngCore; |
13 | |
14 | pub struct TempDir(PathBuf); |
15 | |
16 | impl TempDir { |
17 | pub fn join(&self, path: &str) -> PathBuf { |
18 | let TempDir(ref p) = *self; |
19 | p.join(path) |
20 | } |
21 | |
22 | pub fn path(&self) -> &Path { |
23 | let TempDir(ref p) = *self; |
24 | p |
25 | } |
26 | } |
27 | |
28 | impl Drop for TempDir { |
29 | fn drop(&mut self) { |
30 | // Gee, seeing how we're testing the fs module I sure hope that we |
31 | // at least implement this correctly! |
32 | let TempDir(ref p) = *self; |
33 | let result = fs::remove_dir_all(p); |
34 | // Avoid panicking while panicking as this causes the process to |
35 | // immediately abort, without displaying test results. |
36 | if !thread::panicking() { |
37 | result.unwrap(); |
38 | } |
39 | } |
40 | } |
41 | |
42 | #[track_caller ] // for `test_rng` |
43 | pub fn tmpdir() -> TempDir { |
44 | let p = env::temp_dir(); |
45 | let mut r = crate::test_helpers::test_rng(); |
46 | let ret = p.join(&format!("rust- {}" , r.next_u32())); |
47 | fs::create_dir(&ret).unwrap(); |
48 | TempDir(ret) |
49 | } |
50 | } |
51 | |