forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolden_output.rs
46 lines (40 loc) · 1023 Bytes
/
golden_output.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
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0
use goldenfile::Mint;
use std::{
fmt::Debug,
fs::File,
io::Write,
path::PathBuf,
sync::{Arc, Mutex},
};
pub const GOLDEN_DIR_PATH: &str = "goldens";
#[derive(Clone)]
pub(crate) struct GoldenOutputs {
#[allow(dead_code)]
mint: Arc<Mint>,
file: Arc<Mutex<File>>,
}
impl GoldenOutputs {
pub fn new(name: String) -> Self {
let mut mint = Mint::new(GOLDEN_DIR_PATH);
let mut file_path = PathBuf::new();
file_path.push(name);
let file = Arc::new(Mutex::new(
mint.new_goldenfile(file_path.with_extension("json"))
.unwrap(),
));
Self {
mint: Arc::new(mint),
file,
}
}
pub fn log(&self, msg: &str) {
self.file.lock().unwrap().write_all(msg.as_bytes()).unwrap();
}
}
impl Debug for GoldenOutputs {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "")
}
}