write raw log file in complement wrapper

This commit is contained in:
Benjamin Lee 2024-06-22 00:22:33 -07:00
parent 0eee282558
commit e6f5aa6150
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4

View file

@ -247,8 +247,7 @@ fn run_complement_inner(
.wrap_err("error reading output from complement process")?; .wrap_err("error reading output from complement process")?;
ctx.handle_line(&line)?; ctx.handle_line(&line)?;
} }
ctx.finish()
Ok(ctx.results)
} }
/// Schema from <https://pkg.go.dev/cmd/test2json#hdr-Output_Format> /// Schema from <https://pkg.go.dev/cmd/test2json#hdr-Output_Format>
@ -300,6 +299,7 @@ struct TestContext {
// a non-error path, and the file is left in an inconsistent state on an // a non-error path, and the file is left in an inconsistent state on an
// error anyway. // error anyway.
summary_file: BufWriter<File>, summary_file: BufWriter<File>,
raw_log_file: BufWriter<File>,
log_dir: PathBuf, log_dir: PathBuf,
results: TestResults, results: TestResults,
} }
@ -343,6 +343,11 @@ impl TestContext {
.wrap_err("failed to create summary file in output dir")?; .wrap_err("failed to create summary file in output dir")?;
let summary_file = BufWriter::new(summary_file); let summary_file = BufWriter::new(summary_file);
let raw_log_file = File::create(out.join("raw-log.jsonl"))
.into_diagnostic()
.wrap_err("failed to create raw log file in output dir")?;
let raw_log_file = BufWriter::new(raw_log_file);
let log_dir = out.join("logs"); let log_dir = out.join("logs");
let ctx = TestContext { let ctx = TestContext {
@ -352,6 +357,7 @@ impl TestContext {
skip_count: 0, skip_count: 0,
log_dir, log_dir,
summary_file, summary_file,
raw_log_file,
results: BTreeMap::new(), results: BTreeMap::new(),
}; };
@ -359,6 +365,26 @@ impl TestContext {
Ok(ctx) Ok(ctx)
} }
fn finish(mut self) -> Result<TestResults> {
self.raw_log_file
.flush()
.into_diagnostic()
.wrap_err("error flushing writes to raw log file")?;
Ok(self.results)
}
fn write_raw_log_line(&mut self, line: &str) -> Result<()> {
self.raw_log_file
.write_all(line.as_bytes())
.into_diagnostic()
.wrap_err("error writing line to raw log file")?;
self.raw_log_file
.write_all(b"\n")
.into_diagnostic()
.wrap_err("error writing line to raw log file")?;
Ok(())
}
fn update_progress(&self) { fn update_progress(&self) {
self.pb self.pb
.set_position(self.pass_count + self.fail_count + self.skip_count); .set_position(self.pass_count + self.fail_count + self.skip_count);
@ -473,6 +499,7 @@ impl TestContext {
/// Processes a line of output from `test2json` /// Processes a line of output from `test2json`
fn handle_line(&mut self, line: &str) -> Result<()> { fn handle_line(&mut self, line: &str) -> Result<()> {
self.write_raw_log_line(line)?;
match serde_json::from_str(line) { match serde_json::from_str(line) {
Ok(event) => self.handle_event(event)?, Ok(event) => self.handle_event(event)?,
Err(e) => { Err(e) => {