Skip to content

Commit 7c4c28c

Browse files
Merge pull request #159 from microsoft/main
Fork Sync: Update from parent repository
2 parents da4ac2c + b995cc2 commit 7c4c28c

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

src/agent/onefuzz-file-format/src/coverage/binary.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ impl BinaryCoverageJson {
3131
}
3232
}
3333

34+
// Convert into the latest format.
35+
impl From<BinaryCoverage> for BinaryCoverageJson {
36+
fn from(source: BinaryCoverage) -> Self {
37+
v1::BinaryCoverageJson::from(source).into()
38+
}
39+
}
40+
41+
impl From<v0::BinaryCoverageJson> for BinaryCoverageJson {
42+
fn from(v0: v0::BinaryCoverageJson) -> Self {
43+
Self::V0(v0)
44+
}
45+
}
46+
impl From<v1::BinaryCoverageJson> for BinaryCoverageJson {
47+
fn from(v1: v1::BinaryCoverageJson) -> Self {
48+
Self::V1(v1)
49+
}
50+
}
51+
3452
impl TryFrom<BinaryCoverageJson> for BinaryCoverage {
3553
type Error = anyhow::Error;
3654

src/agent/onefuzz-file-format/src/coverage/source.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ impl SourceCoverageJson {
3131
}
3232
}
3333

34+
// Convert into the latest format.
35+
impl From<SourceCoverage> for SourceCoverageJson {
36+
fn from(source: SourceCoverage) -> Self {
37+
v1::SourceCoverageJson::from(source).into()
38+
}
39+
}
40+
41+
impl From<v0::SourceCoverageJson> for SourceCoverageJson {
42+
fn from(v0: v0::SourceCoverageJson) -> Self {
43+
Self::V0(v0)
44+
}
45+
}
46+
impl From<v1::SourceCoverageJson> for SourceCoverageJson {
47+
fn from(v1: v1::SourceCoverageJson) -> Self {
48+
Self::V1(v1)
49+
}
50+
}
51+
3452
impl TryFrom<SourceCoverageJson> for SourceCoverage {
3553
type Error = anyhow::Error;
3654

src/agent/onefuzz-file-format/src/coverage/source/v1.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,37 @@ pub type SourceFile = String;
1212
pub type HitCount = u32;
1313
pub use line_number::LineNumber;
1414

15-
#[derive(Deserialize, Serialize)]
15+
#[derive(Default, Deserialize, Serialize)]
1616
pub struct SourceCoverageJson {
1717
#[serde(flatten)]
1818
pub files: BTreeMap<SourceFile, FileCoverageJson>,
1919
}
2020

21-
#[derive(Deserialize, Serialize)]
21+
#[derive(Default, Deserialize, Serialize)]
2222
pub struct FileCoverageJson {
2323
pub lines: BTreeMap<LineNumber, HitCount>,
2424
}
2525

26+
impl From<SourceCoverage> for SourceCoverageJson {
27+
fn from(source: SourceCoverage) -> Self {
28+
let mut json = SourceCoverageJson::default();
29+
30+
for (path, file) in source.files {
31+
let mut file_json = FileCoverageJson::default();
32+
33+
for (line, count) in file.lines {
34+
let line_number = LineNumber(line.number());
35+
let hit_count = count.0;
36+
file_json.lines.insert(line_number, hit_count);
37+
}
38+
39+
json.files.insert(path.to_string(), file_json);
40+
}
41+
42+
json
43+
}
44+
}
45+
2646
impl TryFrom<SourceCoverageJson> for SourceCoverage {
2747
type Error = anyhow::Error;
2848

0 commit comments

Comments
 (0)