From 0b19af338168d37d3e7a39f57af1f92e622fed92 Mon Sep 17 00:00:00 2001 From: George Pollard Date: Mon, 14 Nov 2022 12:45:05 +1300 Subject: [PATCH] Switch to quick-xml (#2611) --- src/agent/Cargo.lock | 29 +- src/agent/coverage/Cargo.toml | 3 +- src/agent/coverage/src/cobertura.rs | 811 ++++++++-------------------- src/agent/onefuzz-task/Cargo.toml | 2 +- src/agent/srcview/Cargo.toml | 2 +- src/agent/storage-queue/Cargo.toml | 2 +- 6 files changed, 251 insertions(+), 598 deletions(-) diff --git a/src/agent/Cargo.lock b/src/agent/Cargo.lock index 7717e3c6a3..5aad442fc2 100644 --- a/src/agent/Cargo.lock +++ b/src/agent/Cargo.lock @@ -159,7 +159,7 @@ dependencies = [ "reqwest", "rustc_version", "serde", - "serde-xml-rs 0.6.0", + "serde-xml-rs", "serde_json", "time", "url", @@ -182,7 +182,7 @@ dependencies = [ "log", "once_cell", "serde", - "serde-xml-rs 0.6.0", + "serde-xml-rs", "serde_derive", "serde_json", "sha2", @@ -206,7 +206,7 @@ dependencies = [ "log", "md5", "serde", - "serde-xml-rs 0.6.0", + "serde-xml-rs", "serde_derive", "serde_json", "time", @@ -521,7 +521,9 @@ dependencies = [ "msvc-demangler", "pdb 0.7.0", "pete", + "pretty_assertions", "procfs", + "quick-xml", "regex", "rustc-demangle", "serde", @@ -531,7 +533,6 @@ dependencies = [ "uuid 0.8.2", "win-util", "winapi", - "xml-rs", ] [[package]] @@ -1984,7 +1985,7 @@ dependencies = [ "reqwest", "reqwest-retry", "serde", - "serde-xml-rs 0.5.1", + "serde-xml-rs", "serde_json", "stacktrace-parser", "storage-queue", @@ -2390,9 +2391,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58e21a144a0ffb5fad7b464babcdab934a325ad69b7c0373bcfef5cbd9799ca9" +checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd" dependencies = [ "memchr", ] @@ -2753,18 +2754,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-xml-rs" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65162e9059be2f6a3421ebbb4fef3e74b7d9e7c60c50a0e292c6239f19f1edfa" -dependencies = [ - "log", - "serde", - "thiserror", - "xml-rs", -] - [[package]] name = "serde-xml-rs" version = "0.6.0" @@ -3007,7 +2996,7 @@ dependencies = [ "reqwest", "reqwest-retry", "serde", - "serde-xml-rs 0.5.1", + "serde-xml-rs", "serde_derive", "serde_json", "tokio", diff --git a/src/agent/coverage/Cargo.toml b/src/agent/coverage/Cargo.toml index 933d07c97d..ef5e276df5 100644 --- a/src/agent/coverage/Cargo.toml +++ b/src/agent/coverage/Cargo.toml @@ -27,7 +27,7 @@ serde = { version = "1.0", features = ["derive"] } symbolic = { version = "8.8", features = ["debuginfo", "demangle", "symcache"] } uuid = { version = "0.8", features = ["guid"] } win-util = { path = "../win-util" } -xml-rs = "0.8" +quick-xml = "0.26" [target.'cfg(target_os = "windows")'.dependencies] pdb = "0.7" @@ -43,3 +43,4 @@ procfs = { version = "0.12", default-features = false, features=["flate2"] } env_logger = "0.9" serde_json = { version = "1.0", features = ["preserve_order"] } structopt = "0.3" +pretty_assertions ="1.3" diff --git a/src/agent/coverage/src/cobertura.rs b/src/agent/coverage/src/cobertura.rs index d613b70509..ddf7d24b70 100644 --- a/src/agent/coverage/src/cobertura.rs +++ b/src/agent/coverage/src/cobertura.rs @@ -3,10 +3,11 @@ use crate::source::SourceFileCoverage; use anyhow::Context; use anyhow::Error; use anyhow::Result; +use quick_xml::writer::Writer; +use std::io::Cursor; use std::path::Path; use std::path::PathBuf; use std::time::{SystemTime, UNIX_EPOCH}; -use xml::writer::{EmitterConfig, XmlEvent}; pub struct LineValues { pub valid_lines: u64, @@ -77,11 +78,9 @@ pub fn get_parent_path(path_slash: &str) -> PathBuf { }; parent_path.to_path_buf() } + pub fn cobertura(source_coverage: SourceCoverage) -> Result { - let mut backing: Vec = Vec::new(); - let mut emitter = EmitterConfig::new() - .perform_indent(true) - .create_writer(&mut backing); + let mut writer = Writer::new_with_indent(Cursor::new(Vec::new()), b' ', 4); let unixtime = SystemTime::now() .duration_since(UNIX_EPOCH) @@ -89,82 +88,107 @@ pub fn cobertura(source_coverage: SourceCoverage) -> Result { .as_secs(); let coverage_line_values = compute_line_values_coverage(&source_coverage.files); - - emitter.write( - XmlEvent::start_element("coverage") - .attr( + writer + .create_element("coverage") + .with_attributes([ + ( "line-rate", - &format!("{:.02}", coverage_line_values.line_rate), - ) - .attr("branch-rate", "0") - .attr( + format!("{:.02}", coverage_line_values.line_rate).as_str(), + ), + ("branch-rate", "0"), + ( "lines-covered", - &format!("{}", coverage_line_values.hit_lines), - ) - .attr( + coverage_line_values.hit_lines.to_string().as_str(), + ), + ( "lines-valid", - &format!("{}", coverage_line_values.valid_lines), - ) - .attr("branches-covered", "0") - .attr("branches-valid", "0") - .attr("complexity", "0") - .attr("version", "0.1") - .attr("timestamp", &format!("{}", unixtime)), - )?; - - emitter.write(XmlEvent::start_element("packages"))?; - // path (excluding file name) is package name for better results with ReportGenerator - // class name is only file name (no path) - for file in &source_coverage.files { - let path = convert_path(file); - let parent_path = get_parent_path(&path); - let package_line_values = compute_line_values_package(file); - let class_name = get_file_name(&path); - - emitter.write( - XmlEvent::start_element("package") - .attr("name", &(parent_path.display().to_string())) - .attr( - "line-rate", - &format!("{:.02}", package_line_values.line_rate), - ) - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - emitter.write(XmlEvent::start_element("classes"))?; - emitter.write( - XmlEvent::start_element("class") - .attr("name", &class_name) - .attr("filename", &path) - .attr( - "line-rate", - &format!("{:.02}", package_line_values.line_rate), - ) - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - emitter.write(XmlEvent::start_element("lines"))?; - let line_locations = &file.locations; - for location in line_locations { - emitter.write( - XmlEvent::start_element("line") - .attr("number", &location.line.to_string()) - .attr("hits", &location.count.to_string()) - .attr("branch", "false"), - )?; - emitter.write(XmlEvent::end_element())?; // line - } - emitter.write(XmlEvent::end_element())?; // lines - emitter.write(XmlEvent::end_element())?; // class - - emitter.write(XmlEvent::end_element())?; // classes - emitter.write(XmlEvent::end_element())?; // package - } - - emitter.write(XmlEvent::end_element())?; // packages - emitter.write(XmlEvent::end_element())?; // coverage + coverage_line_values.valid_lines.to_string().as_str(), + ), + ("branches-covered", "0"), + ("branches-valid", "0"), + ("complexity", "0"), + ("version", "0.1"), + ("timestamp", unixtime.to_string().as_str()), + ]) + .write_inner_content(|writer| { + writer + .create_element("packages") + .write_inner_content(|writer| { + // path (excluding file name) is package name for better results with ReportGenerator + // class name is only file name (no path) + for file in &source_coverage.files { + write_file(writer, file)?; + } + + Ok(()) + })?; + + Ok(()) + })?; + + Ok(String::from_utf8(writer.into_inner().into_inner())?) +} - Ok(String::from_utf8(backing)?) +fn write_file( + writer: &mut Writer>>, + file: &SourceFileCoverage, +) -> quick_xml::Result<()> { + let path = convert_path(file); + let parent_path = get_parent_path(&path); + let package_line_values = compute_line_values_package(file); + let class_name = get_file_name(&path); + + writer + .create_element("package") + .with_attributes([ + ("name", parent_path.display().to_string().as_str()), + ( + "line-rate", + format!("{:.02}", package_line_values.line_rate).as_str(), + ), + ("branch-rate", "0"), + ("complexity", "0"), + ]) + .write_inner_content(|writer| { + writer + .create_element("classes") + .write_inner_content(|writer| { + writer + .create_element("class") + .with_attributes([ + ("name", class_name.as_str()), + ("filename", path.as_str()), + ( + "line-rate", + format!("{:.02}", package_line_values.line_rate).as_str(), + ), + ("branch-rate", "0"), + ("complexity", "0"), + ]) + .write_inner_content(|writer| { + writer + .create_element("lines") + .write_inner_content(|writer| { + let line_locations = &file.locations; + for location in line_locations { + writer + .create_element("line") + .with_attributes([ + ("number", location.line.to_string().as_str()), + ("hits", location.count.to_string().as_str()), + ("branch", "false"), + ]) + .write_empty()?; + } + Ok(()) + })?; + Ok(()) + })?; + Ok(()) + })?; + Ok(()) + })?; + Ok(()) } #[cfg(test)] @@ -173,6 +197,7 @@ mod tests { use super::*; use crate::source::SourceCoverageLocation; use anyhow::Result; + use pretty_assertions::assert_eq; #[test] fn test_cobertura_conversion_windows_to_posix_path() { @@ -381,177 +406,56 @@ mod tests { files: file_coverage_vec1, }); - let mut backing_test: Vec = Vec::new(); - let mut _emitter_test = EmitterConfig::new() - .perform_indent(true) - .create_writer(&mut backing_test); - let unixtime = SystemTime::now() .duration_since(UNIX_EPOCH) .context("system time before unix epoch")? .as_secs(); - _emitter_test.write( - XmlEvent::start_element("coverage") - .attr("line-rate", "0.40") - .attr("branch-rate", "0") - .attr("lines-covered", "2") - .attr("lines-valid", "5") - .attr("branches-covered", "0") - .attr("branches-valid", "0") - .attr("complexity", "0") - .attr("version", "0.1") - .attr("timestamp", &format!("{}", unixtime)), - )?; - - _emitter_test.write(XmlEvent::start_element("packages"))?; - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "c:/users") - .attr("line-rate", "0.50") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "file1.txt") - .attr("filename", "c:/users/file1.txt") - .attr("line-rate", "0.50") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "5") - .attr("hits", "3") - .attr("branch", "false"), - )?; - _emitter_test.write(XmlEvent::end_element())?; // line - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "10") - .attr("hits", "0") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "c:/users") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "file2.txt") - .attr("filename", "c:/users/file2.txt") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "1") - .attr("hits", "0") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "Invalid file format: c:/users/file/..") - .attr("line-rate", "1.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "..") - .attr("filename", "c:/users/file/..") - .attr("line-rate", "1.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "1") - .attr("hits", "1") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "Invalid file format: c:/users/file/..") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "..") - .attr("filename", "c:/users/file/..") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "1") - .attr("hits", "0") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - _emitter_test.write(XmlEvent::end_element())?; // packages - _emitter_test.write(XmlEvent::end_element())?; // coverage - - assert_eq!(source_coverage_result?, String::from_utf8(backing_test)?); + let expected = format!( + r#" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"# + ); + + assert_eq!(source_coverage_result?, expected); Ok(()) } @@ -611,177 +515,56 @@ mod tests { files: file_coverage_vec1, }); - let mut backing_test: Vec = Vec::new(); - let mut _emitter_test = EmitterConfig::new() - .perform_indent(true) - .create_writer(&mut backing_test); - let unixtime = SystemTime::now() .duration_since(UNIX_EPOCH) .context("system time before unix epoch")? .as_secs(); - _emitter_test.write( - XmlEvent::start_element("coverage") - .attr("line-rate", "0.40") - .attr("branch-rate", "0") - .attr("lines-covered", "2") - .attr("lines-valid", "5") - .attr("branches-covered", "0") - .attr("branches-valid", "0") - .attr("complexity", "0") - .attr("version", "0.1") - .attr("timestamp", &format!("{}", unixtime)), - )?; - - _emitter_test.write(XmlEvent::start_element("packages"))?; - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "c:/users") - .attr("line-rate", "0.50") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "file1.txt") - .attr("filename", "c:/users/file1.txt") - .attr("line-rate", "0.50") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "5") - .attr("hits", "3") - .attr("branch", "false"), - )?; - _emitter_test.write(XmlEvent::end_element())?; // line - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "10") - .attr("hits", "0") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "c:/users") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "file2.txt") - .attr("filename", "c:/users/file2.txt") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "1") - .attr("hits", "0") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "Invalid file format: c:/users/file/..") - .attr("line-rate", "1.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "..") - .attr("filename", "c:/users/file/..") - .attr("line-rate", "1.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "1") - .attr("hits", "1") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "Invalid file format: c:/users/file/..") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "..") - .attr("filename", "c:/users/file/..") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "1") - .attr("hits", "0") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - _emitter_test.write(XmlEvent::end_element())?; // packages - _emitter_test.write(XmlEvent::end_element())?; // coverage - - assert_eq!(source_coverage_result?, String::from_utf8(backing_test)?); + let expected = format!( + r#" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"# + ); + + assert_eq!(source_coverage_result?, expected); Ok(()) } @@ -840,177 +623,57 @@ mod tests { let source_coverage_result = cobertura(SourceCoverage { files: file_coverage_vec1, }); - let mut backing_test: Vec = Vec::new(); - let mut _emitter_test = EmitterConfig::new() - .perform_indent(true) - .create_writer(&mut backing_test); let unixtime = SystemTime::now() .duration_since(UNIX_EPOCH) .context("system time before unix epoch")? .as_secs(); - _emitter_test.write( - XmlEvent::start_element("coverage") - .attr("line-rate", "0.40") - .attr("branch-rate", "0") - .attr("lines-covered", "2") - .attr("lines-valid", "5") - .attr("branches-covered", "0") - .attr("branches-valid", "0") - .attr("complexity", "0") - .attr("version", "0.1") - .attr("timestamp", &format!("{}", unixtime)), - )?; - - _emitter_test.write(XmlEvent::start_element("packages"))?; - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "c:/users") - .attr("line-rate", "0.50") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "file1.txt") - .attr("filename", "c:/users/file1.txt") - .attr("line-rate", "0.50") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "5") - .attr("hits", "3") - .attr("branch", "false"), - )?; - _emitter_test.write(XmlEvent::end_element())?; // line - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "10") - .attr("hits", "0") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "c:/users") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "file2.txt") - .attr("filename", "c:/users/file2.txt") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "1") - .attr("hits", "0") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "Invalid file format: c:/users/file/..") - .attr("line-rate", "1.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "..") - .attr("filename", "c:/users/file/..") - .attr("line-rate", "1.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "1") - .attr("hits", "1") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - - _emitter_test.write( - XmlEvent::start_element("package") - .attr("name", "Invalid file format: c:/users/file/..") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("classes"))?; - - _emitter_test.write( - XmlEvent::start_element("class") - .attr("name", "..") - .attr("filename", "c:/users/file/..") - .attr("line-rate", "0.00") - .attr("branch-rate", "0") - .attr("complexity", "0"), - )?; - - _emitter_test.write(XmlEvent::start_element("lines"))?; - - _emitter_test.write( - XmlEvent::start_element("line") - .attr("number", "1") - .attr("hits", "0") - .attr("branch", "false"), - )?; - - _emitter_test.write(XmlEvent::end_element())?; // line - _emitter_test.write(XmlEvent::end_element())?; // lines - _emitter_test.write(XmlEvent::end_element())?; // class - _emitter_test.write(XmlEvent::end_element())?; // classes - _emitter_test.write(XmlEvent::end_element())?; // package - _emitter_test.write(XmlEvent::end_element())?; // packages - _emitter_test.write(XmlEvent::end_element())?; // coverage - - assert_eq!(source_coverage_result?, String::from_utf8(backing_test)?); + let expected = format!( + r#" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"# + ); + + assert_eq!(source_coverage_result?, expected); Ok(()) } } diff --git a/src/agent/onefuzz-task/Cargo.toml b/src/agent/onefuzz-task/Cargo.toml index 71ad4a26ce..dd849c2953 100644 --- a/src/agent/onefuzz-task/Cargo.toml +++ b/src/agent/onefuzz-task/Cargo.toml @@ -29,7 +29,7 @@ regex = "1.6.0" reqwest = { version = "0.11", features = ["json", "stream", "native-tls-vendored"], default-features=false } serde = "1.0" serde_json = "1.0" -serde-xml-rs = "0.5.1" +serde-xml-rs = "0.6" onefuzz = { path = "../onefuzz" } onefuzz-telemetry = { path = "../onefuzz-telemetry" } path-absolutize = "3.0" diff --git a/src/agent/srcview/Cargo.toml b/src/agent/srcview/Cargo.toml index f7f0bc883b..52e1484bb5 100644 --- a/src/agent/srcview/Cargo.toml +++ b/src/agent/srcview/Cargo.toml @@ -15,7 +15,7 @@ nom = "7" pdb = "0.8" regex = "1" serde = { version = "1", features = ["derive"] } -quick-xml = "0.25.0" +quick-xml = "0.26" anyhow = "1.0" structopt = "0.3" env_logger = "0.9" diff --git a/src/agent/storage-queue/Cargo.toml b/src/agent/storage-queue/Cargo.toml index 722e1a0276..9c50a771bc 100644 --- a/src/agent/storage-queue/Cargo.toml +++ b/src/agent/storage-queue/Cargo.toml @@ -20,7 +20,7 @@ reqwest-retry = { path = "../reqwest-retry" } serde = { version = "1.0", features = ["derive"]} serde_derive = "1.0" serde_json = "1.0" -serde-xml-rs = "0.5" +serde-xml-rs = "0.6" tokio = { version = "1.16" , features=["full"] } queue-file = "1.4" uuid = { version = "0.8", features = ["serde", "v4"] }