|
6 | 6 | //! and rustc) libtest doesn't include the rendered human-readable output as a JSON field. We had
|
7 | 7 | //! to reimplement all the rendering logic in this module because of that.
|
8 | 8 | use std::collections::HashSet;
|
9 |
| -use std::fs::OpenOptions; |
| 9 | +use std::fs::{File, OpenOptions}; |
10 | 10 | use std::io::{BufRead, BufReader, Read, Write};
|
| 11 | +use std::path::Path; |
11 | 12 | use std::process::{ChildStdout, Command, Stdio};
|
12 | 13 | use std::time::Duration;
|
13 | 14 |
|
@@ -306,13 +307,19 @@ impl<'a> Renderer<'a> {
|
306 | 307 | fn init_tracking(&mut self) {
|
307 | 308 | let mut contents = String::new();
|
308 | 309 | {
|
309 |
| - let mut file = |
310 |
| - OpenOptions::new().read(true).write(true).create(true).open(TRACKER_FILE).unwrap(); |
311 |
| - file.read_to_string(&mut contents).unwrap(); |
312 |
| - } |
| 310 | + let path = Path::new(TRACKER_FILE); |
313 | 311 |
|
314 |
| - if !contents.is_empty() { |
315 |
| - self.tracker = serde_json::from_str(&contents).unwrap(); |
| 312 | + if !path.exists() { |
| 313 | + let mut file = File::create(path).expect(&format!( |
| 314 | + "failed to create test.tracker | {:?}", |
| 315 | + path.canonicalize().unwrap() |
| 316 | + )); |
| 317 | + file.write_all(b"[]").unwrap(); |
| 318 | + } else { |
| 319 | + let mut file = File::open(path).expect("failed to open test.tracker"); |
| 320 | + file.read_to_string(&mut contents).unwrap(); |
| 321 | + self.tracker = serde_json::from_str(&contents).unwrap(); |
| 322 | + } |
316 | 323 | }
|
317 | 324 | }
|
318 | 325 |
|
|
0 commit comments