1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
//! An LCOV record. //! //! The [`Record`] structure represents all kinds of LCOV records. //! //! [`Record`]: enum.Record.html pub use self::display::*; pub use self::parse::*; use std::path::PathBuf; mod display; mod parse; #[cfg(test)] mod tests; /// Represents all kinds of LCOV records. /// /// This `struct` can be created by parsing an LCOV record string by [`parse`] method (provided by the `FromStr` trait). /// This `struct` can be converted into an LCOV record string by [`to_string`] method (provided by the `ToString` trait). /// /// See those documentation for more. /// /// [`parse`]: enum.Record.html#method.parse /// [`to_string`]: enum.Record.html#method.to_string #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)] pub enum Record { /// Represents a `TN` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("TN:test_name".parse(), Ok(Record::TestName { name: "test_name".into() })); /// ``` TestName { /// test name name: String, }, /// Represents a `SF` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("SF:/usr/include/stdio.h".parse(), /// Ok(Record::SourceFile { path: "/usr/include/stdio.h".into() })); /// ``` SourceFile { /// Absolute path to the source file. path: PathBuf, }, /// Represents a `FN` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("FN:10,main".parse(), /// Ok(Record::FunctionName { name: "main".into(), start_line: 10 })); /// ``` FunctionName { /// Function name. name: String, /// Line number of function start. start_line: u32, }, /// Represents a `FNDA` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("FNDA:1,main".parse(), /// Ok(Record::FunctionData { name: "main".into(), count: 1 })); /// ``` FunctionData { /// Function name. name: String, /// Execution count. count: u64, }, /// Represents a `FNF` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("FNF:10".parse(), Ok(Record::FunctionsFound { found: 10 })); /// ``` FunctionsFound { /// Number of functions found. found: u32, }, /// Represents a `FNH` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("FNH:7".parse(), Ok(Record::FunctionsHit { hit: 7 })); /// ``` FunctionsHit { /// Number of functions hit. hit: u32, }, /// Represents a `BRDA` record. /// /// `block` and `branch` are gcc internal IDs for the branch. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("BRDA:10,30,40,-".parse(), /// Ok(Record::BranchData { line: 10, block: 30, branch: 40, taken: None })); /// assert_eq!("BRDA:10,30,40,3".parse(), /// Ok(Record::BranchData { line: 10, block: 30, branch: 40, taken: Some(3) })); /// ``` BranchData { /// Line number. line: u32, /// Block number. block: u32, /// Branch number. branch: u32, /// A number indicating how often that branch was taken. taken: Option<u64>, }, /// Represents a `BRF` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("BRF:40".parse(), Ok(Record::BranchesFound { found: 40 })); /// ``` BranchesFound { /// Number of branches found. found: u32, }, /// Represents a `BRH` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("BRH:20".parse(), Ok(Record::BranchesHit { hit: 20 })); /// ``` BranchesHit { /// Number of branches hit. hit: u32, }, /// Represents a `DA` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("DA:8,30".parse(), Ok(Record::LineData { line: 8, count: 30, checksum: None })); /// assert_eq!("DA:8,30,asdfasdf".parse(), /// Ok(Record::LineData { line: 8, count: 30, checksum: Some("asdfasdf".into()) })); /// ``` LineData { /// Line number. line: u32, /// Execution count. count: u64, /// Checksum for each instrumented line. checksum: Option<String>, }, /// Represents a `LF` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("LF:123".parse(), Ok(Record::LinesFound { found: 123 })); /// ``` LinesFound { /// Number of instrumented line. found: u32, }, /// Represents a `LH` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("LH:45".parse(), Ok(Record::LinesHit { hit: 45 })); /// ``` LinesHit { /// Number of lines with a non-zero execution count. hit: u32, }, /// Represents a `end_of_record` record. /// /// # Examples /// /// ```rust /// use lcov::Record; /// assert_eq!("end_of_record".parse(), Ok(Record::EndOfRecord)); /// ``` EndOfRecord, } /// Represents all LCOV record kinds. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] pub enum RecordKind { /// Represents a `TN` record. TestName, /// Represents a `SF` record. SourceFile, /// Represents a `FN` record. FunctionName, /// Represents a `FNDA` record. FunctionData, /// Represents a `FNF` record. FunctionsFound, /// Represents a `FNH` record. FunctionsHit, /// Represents a `BRDA` record. BranchData, /// Represents a `BRF` record. BranchesFound, /// Represents a `BRH` record. BranchesHit, /// Represents a `DA` record. LineData, /// Represents a `LF` record. LinesFound, /// Represents a `LH` record. LinesHit, /// Represents a `end_of_record` record. EndOfRecord, } macro_rules! kind_impl { ($rec:expr; $($kind:ident),*) => { match $rec { $(Record::$kind { .. } => RecordKind::$kind),* } } } impl Record { /// Returns the corresponding `RecordKind` for this record. /// /// # Examples /// /// ```rust /// use lcov::{Record, RecordKind}; /// let rec = Record::LinesHit { hit: 32 }; /// assert_eq!(rec.kind(), RecordKind::LinesHit); /// ``` pub fn kind(&self) -> RecordKind { kind_impl! { *self; TestName, SourceFile, FunctionName, FunctionData, FunctionsFound, FunctionsHit, BranchData, BranchesFound, BranchesHit, LineData, LinesFound, LinesHit, EndOfRecord } } } impl RecordKind { /// Returns the corresponding `&str` for the record kind. /// /// # Examples /// /// ```rust /// use lcov::RecordKind; /// assert_eq!(RecordKind::TestName.as_str(), "TN"); /// ``` pub fn as_str(&self) -> &'static str { use RecordKind::*; match *self { TestName => "TN", SourceFile => "SF", FunctionName => "FN", FunctionData => "FNDA", FunctionsFound => "FNF", FunctionsHit => "FNH", BranchData => "BRDA", BranchesFound => "BRF", BranchesHit => "BRH", LineData => "DA", LinesFound => "LF", LinesHit => "LH", EndOfRecord => "end_of_record", } } }