diff --git a/src/json.rs b/src/json.rs index 7a9ec698..a8f7b297 100644 --- a/src/json.rs +++ b/src/json.rs @@ -16,11 +16,11 @@ use serde_derive::{Deserialize, Serialize}; #[cfg_attr(test, serde(deny_unknown_fields))] pub struct LlvmCovJsonExport { /// List of one or more export objects - pub(crate) data: Vec, + data: Vec, // llvm.coverage.json.export #[serde(rename = "type")] - pub(crate) type_: String, - pub(crate) version: String, + type_: String, + version: String, /// Additional information injected into the export data. #[serde(skip_deserializing, skip_serializing_if = "Option::is_none")] cargo_llvm_cov: Option, @@ -29,10 +29,10 @@ pub struct LlvmCovJsonExport { /// /// /// This represents the fraction: `{covered}/{count}`. -#[derive(Default, Debug)] -pub(crate) struct CodeCovCoverage { - pub(crate) count: u64, - pub(crate) covered: u64, +#[derive(Debug, Default)] +struct CodeCovCoverage { + count: u64, + covered: u64, } impl Serialize for CodeCovCoverage { @@ -46,7 +46,7 @@ impl Serialize for CodeCovCoverage { /// line -> coverage in fraction #[derive(Default)] -pub struct CodeCovExport(BTreeMap); +struct CodeCovExport(BTreeMap); /// Custom serialize [`CodeCovExport`] as "string" -> JSON (as function) /// Serialize as "string" -> JSON @@ -66,7 +66,7 @@ impl Serialize for CodeCovExport { #[derive(Default, Serialize)] pub struct CodeCovJsonExport { /// filename -> list of uncovered lines. - pub(crate) coverage: BTreeMap, + coverage: BTreeMap, } impl CodeCovJsonExport { @@ -144,7 +144,7 @@ impl CodeCovJsonExport { } /// Files -> list of uncovered lines. -pub(crate) type UncoveredLines = BTreeMap>; +type UncoveredLines = BTreeMap>; #[non_exhaustive] #[derive(Clone, Copy)] @@ -318,77 +318,72 @@ impl LlvmCovJsonExport { /// Json representation of one `CoverageMapping` #[derive(Debug, Serialize, Deserialize)] #[cfg_attr(test, serde(deny_unknown_fields))] -pub(crate) struct Export { +struct Export { /// List of objects describing coverage for files - pub(crate) files: Vec, + files: Vec, /// List of objects describing coverage for functions /// /// This is None if report is summary-only. #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) functions: Option>, - pub(crate) totals: serde_json::Value, + functions: Option>, + totals: serde_json::Value, } /// Coverage for a single file #[derive(Debug, Serialize, Deserialize)] #[cfg_attr(test, serde(deny_unknown_fields))] -pub(crate) struct File { +struct File { /// List of Branches in the file /// /// This is None if report is summary-only. // https://github.com/llvm/llvm-project/blob/llvmorg-17.0.0-rc2/llvm/tools/llvm-cov/CoverageExporterJson.cpp#L92 #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) branches: Option>, + branches: Option>, /// List of expansion records /// /// This is None if report is summary-only. #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) expansions: Option>, - pub(crate) filename: String, + expansions: Option>, + filename: String, /// List of Segments contained in the file /// /// This is None if report is summary-only. #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) segments: Option>, + segments: Option>, /// Object summarizing the coverage for this file - pub(crate) summary: Summary, + summary: Summary, } /// Describes a segment of the file with a counter // https://github.com/llvm/llvm-project/blob/llvmorg-17.0.0-rc2/llvm/tools/llvm-cov/CoverageExporterJson.cpp#L79 #[derive(Serialize, Deserialize)] #[cfg_attr(test, serde(deny_unknown_fields))] -pub(crate) struct Segment( - /* Line */ pub(crate) u64, - /* Col */ pub(crate) u64, - /* Count */ pub(crate) u64, - /* HasCount */ pub(crate) bool, - /* IsRegionEntry */ pub(crate) bool, - /* IsGapRegion */ pub(crate) bool, +struct Segment( + /* Line */ u64, + /* Col */ u64, + /* Count */ u64, + /* HasCount */ bool, + /* IsRegionEntry */ bool, + /* IsGapRegion */ bool, ); impl Segment { - pub(crate) fn line(&self) -> u64 { + fn line(&self) -> u64 { self.0 } - - pub(crate) fn col(&self) -> u64 { + fn col(&self) -> u64 { self.1 } - - pub(crate) fn count(&self) -> u64 { + fn count(&self) -> u64 { self.2 } - - pub(crate) fn has_count(&self) -> bool { + fn has_count(&self) -> bool { self.3 } - - pub(crate) fn is_region_entry(&self) -> bool { + fn is_region_entry(&self) -> bool { self.4 } - - pub(crate) fn is_gap_region(&self) -> bool { + fn is_gap_region(&self) -> bool { self.5 } } @@ -410,79 +405,80 @@ impl fmt::Debug for Segment { /// Coverage info for a single function #[derive(Debug, Serialize, Deserialize)] #[cfg_attr(test, serde(deny_unknown_fields))] -pub(crate) struct Function { - pub(crate) branches: Vec, - pub(crate) count: u64, +struct Function { + branches: Vec, + count: u64, /// List of filenames that the function relates to - pub(crate) filenames: Vec, - pub(crate) name: String, - pub(crate) regions: Vec, + filenames: Vec, + name: String, + regions: Vec, } #[derive(Copy, Clone, Serialize, Deserialize)] #[cfg_attr(test, serde(deny_unknown_fields))] -pub(crate) struct Region( - /* LineStart */ pub(crate) u64, - /* ColumnStart */ pub(crate) u64, - /* LineEnd */ pub(crate) u64, - /* ColumnEnd */ pub(crate) u64, - /* ExecutionCount */ pub(crate) u64, - /* FileID */ pub(crate) u64, - /* ExpandedFileID */ pub(crate) u64, - /* Kind */ pub(crate) u64, +struct Region( + /* LineStart */ u64, + /* ColumnStart */ u64, + /* LineEnd */ u64, + /* ColumnEnd */ u64, + /* ExecutionCount */ u64, + /* FileID */ u64, + /* ExpandedFileID */ u64, + /* Kind */ u64, ); impl Region { - pub(crate) fn line_start(&self) -> u64 { + fn line_start(&self) -> u64 { self.0 } - - pub(crate) fn column_start(&self) -> u64 { + fn column_start(&self) -> u64 { self.1 } - - pub(crate) fn line_end(&self) -> u64 { + fn line_end(&self) -> u64 { self.2 } - - pub(crate) fn column_end(&self) -> u64 { + fn column_end(&self) -> u64 { self.3 } - - pub(crate) fn execution_count(&self) -> u64 { + fn execution_count(&self) -> u64 { self.4 } - - pub(crate) fn file_id(&self) -> u64 { + fn file_id(&self) -> u64 { self.5 } - - pub(crate) fn expanded_file_id(&self) -> u64 { + fn expanded_file_id(&self) -> u64 { self.6 } - - pub(crate) fn kind(&self) -> u64 { + fn kind(&self) -> u64 { self.7 } } +impl fmt::Debug for Region { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Region") + .field("line_start", &self.line_start()) + .field("column_start", &self.column_start()) + .field("line_end", &self.line_end()) + .field("column_end", &self.column_end()) + .field("execution_count", &self.execution_count()) + .field("file_id", &self.file_id()) + .field("expanded_file_id", &self.expanded_file_id()) + .field("kind", &self.kind()) + .finish() + } +} + /// The location of a region #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)] -pub(crate) struct RegionLocation { +struct RegionLocation { start_line: u64, end_line: u64, - start_column: u64, - end_column: u64, } impl From<&Region> for RegionLocation { fn from(region: &Region) -> Self { - Self { - start_line: region.line_start(), - end_line: region.line_end(), - start_column: region.column_start(), - end_column: region.column_end(), - } + Self { start_line: region.line_start(), end_line: region.line_end() } } } @@ -492,45 +488,30 @@ impl RegionLocation { } } -impl fmt::Debug for Region { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Region") - .field("line_start", &self.line_start()) - .field("column_start", &self.column_start()) - .field("line_end", &self.line_end()) - .field("column_end", &self.column_end()) - .field("execution_count", &self.execution_count()) - .field("file_id", &self.file_id()) - .field("expanded_file_id", &self.expanded_file_id()) - .field("kind", &self.kind()) - .finish() - } -} - /// Object summarizing the coverage for this file #[derive(Debug, Serialize, Deserialize)] #[cfg_attr(test, serde(deny_unknown_fields))] -pub(crate) struct Summary { +struct Summary { /// Object summarizing branch coverage - pub(crate) branches: CoverageCounts, + branches: CoverageCounts, /// Object summarizing function coverage - pub(crate) functions: CoverageCounts, - pub(crate) instantiations: CoverageCounts, + functions: CoverageCounts, + instantiations: CoverageCounts, /// Object summarizing line coverage - pub(crate) lines: CoverageCounts, + lines: CoverageCounts, /// Object summarizing region coverage - pub(crate) regions: CoverageCounts, + regions: CoverageCounts, } #[derive(Debug, Serialize, Deserialize)] #[cfg_attr(test, serde(deny_unknown_fields))] -pub(crate) struct CoverageCounts { - pub(crate) count: u64, - pub(crate) covered: u64, +struct CoverageCounts { + count: u64, + covered: u64, // Currently only branches and regions has this field. #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) notcovered: Option, - pub(crate) percent: f64, + notcovered: Option, + percent: f64, } /// Information that is not part of the llvm-cov JSON export, but instead injected afterwards by us.