Skip to main content

mantra_schema/report/
source_file.rs

1use relative_path::RelativePathBuf;
2
3use crate::{
4    FmtHash, Line,
5    report::{
6        annotations::ResolvedAnnotations, product::ProductMetadata, review::ReviewReference,
7        sources::SourceProductCoverageSummary, tests::TestReference,
8    },
9};
10
11#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
12#[serde(rename_all = "snake_case")]
13pub struct SourceFileReportSchema {
14    /// The schema version.
15    /// [req("exchange.versioned")]
16    #[serde(serialize_with = "crate::serialize_schema_version")]
17    pub schema_version: Option<String>,
18    #[schemars(with = "String")]
19    pub filepath: RelativePathBuf,
20    pub hashed_info: Vec<HashedSourceFileInfo>,
21    pub product_coverage: Option<Vec<SourceFileProductCoverage>>,
22    pub collected_by: Vec<ProductMetadata>,
23}
24
25#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
26#[serde(rename_all = "snake_case")]
27pub struct HashedSourceFileInfo {
28    pub file_hash: FmtHash,
29    pub content: Option<String>,
30    pub annotations: Option<ResolvedAnnotations>,
31    pub product_coverage: Option<Vec<SourceFileProductCoverage>>,
32}
33
34#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
35#[serde(rename_all = "snake_case")]
36pub struct SourceFileProductCoverage {
37    pub product: ProductMetadata,
38    pub summary: SourceProductCoverageSummary,
39    pub lines: Vec<SourceLineInfo>,
40}
41
42/// Coverage information of a line in a file.
43/// [req("testcov.cov.lines")]
44#[derive(
45    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
46)]
47#[serde(rename_all = "snake_case")]
48pub struct SourceLineInfo {
49    /// The line number.
50    pub nr: Line,
51    pub state: ResolvedLineState,
52}
53
54#[derive(
55    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
56)]
57#[serde(rename_all = "snake_case")]
58pub enum ResolvedLineState {
59    Covered(Vec<CoveredLineTestReference>),
60    /// Line was excluded from coverage analysis.
61    /// An optional reference to an exclusion annotation is given,
62    /// if the exclusion was based on a mantra annotation.
63    Excluded(Option<ExclusionAnnotationReference>),
64    Overriden(Vec<ReviewOverride>),
65    Uncovered,
66}
67
68#[derive(
69    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
70)]
71pub struct CoveredLineTestReference {
72    pub test: TestReference,
73    pub hits: i64,
74}
75
76#[derive(
77    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
78)]
79pub struct ReviewOverride {
80    pub review: ReviewReference,
81    /// The original hits that were collected from the tests.
82    pub original_hits: Option<i64>,
83    /// The hits set by the review.
84    pub set_hits: Option<i64>,
85    pub comment: String,
86}
87
88#[derive(
89    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
90)]
91pub struct ExclusionAnnotationReference {
92    /// The line the exclude annotation was defined at.
93    pub def_line: Line,
94    pub comment: String,
95}