testing_conventions/
config.rs1use std::path::Path;
12
13use anyhow::{Context, Result};
14use serde::Deserialize;
15
16#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
23#[serde(deny_unknown_fields)]
24pub struct Config {
25 pub python: Option<PythonConfig>,
26 pub typescript: Option<TypeScriptConfig>,
27 pub rust: Option<RustConfig>,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
32#[serde(deny_unknown_fields)]
33pub struct PythonConfig {
34 pub coverage: PythonCoverage,
35}
36
37#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
39#[serde(deny_unknown_fields)]
40pub struct TypeScriptConfig {
41 pub coverage: TypeScriptCoverage,
42}
43
44#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
46#[serde(deny_unknown_fields)]
47pub struct RustConfig {
48 pub coverage: RustCoverage,
49}
50
51#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
53#[serde(deny_unknown_fields)]
54pub struct PythonCoverage {
55 pub branch: bool,
56 pub fail_under: u8,
57}
58
59#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
61#[serde(deny_unknown_fields)]
62pub struct TypeScriptCoverage {
63 pub lines: u8,
64 pub branches: u8,
65 pub functions: u8,
66 pub statements: u8,
67}
68
69#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
72#[serde(deny_unknown_fields)]
73pub struct RustCoverage {
74 pub regions: u8,
75 pub lines: u8,
76}
77
78pub fn load_config(path: impl AsRef<Path>) -> Result<Config> {
85 let path = path.as_ref();
86 let contents = std::fs::read_to_string(path)
87 .with_context(|| format!("reading config file `{}`", path.display()))?;
88 toml::from_str(&contents).with_context(|| format!("parsing config file `{}`", path.display()))
89}