Adds snap and coverage

This commit is contained in:
Dandaedre 2025-03-07 07:21:11 +01:00
parent 897ea9983a
commit e838e4e286
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
16 changed files with 32390 additions and 14 deletions

4
.gitignore vendored
View File

@ -27,8 +27,8 @@ Cargo.lock
callgrind*
cache.out
tarpaulin-report.html
.html
*.html
*.bkp
coverage/
testdata/
snapshots/
# snapshots/

View File

@ -1,3 +1,5 @@
*.drawio
*.db
*.svg
snapshots
*.snap

View File

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 34%"><title>test-coverage: 34%</title><linearGradient id="bms-748b3214a2ea76fd" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-748b3214a2ea76fd"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-748b3214a2ea76fd)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#e05d44"/><rect width="122" height="18" fill="url(#bms-748b3214a2ea76fd)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">34%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">34%</text></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 38%"><title>test-coverage: 38%</title><linearGradient id="bms-ef2093ce1077dbe3" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-ef2093ce1077dbe3"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-ef2093ce1077dbe3)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#e05d44"/><rect width="122" height="18" fill="url(#bms-ef2093ce1077dbe3)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">38%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">38%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -7,3 +7,6 @@ edition = "2024"
clap = { version = "4.5.28", features = ["derive"] }
phf = { version = "0.11.3", features = ["macros"] }
serde = { version = "1.0.217", features = ["derive"] }
[dev-dependencies]
insta = { version = "1.42.2", features = ["yaml"] }

View File

@ -49,6 +49,7 @@ static HELP_STR_TO_GRAPH: LazyLock<String> = LazyLock::new(|| {
});
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
/// All target type
pub enum GraphTargetType {
/// Make all graphs
@ -71,11 +72,29 @@ impl From<&str> for GraphTargetType {
}
}
// #[cfg(test)]
// mod tests {
// use super::*;
#[cfg(test)]
mod test {
use crate::graph::HELP_STR_TO_GRAPH;
// #[test]
// fn it_works() {}
// }
//
use super::GraphTargetType;
#[test]
fn test_help_str() {
insta::assert_yaml_snapshot!(HELP_STR_TO_GRAPH.to_string());
}
#[test]
fn test_block_prog_and_verbosity() {
assert_eq!(GraphTargetType::from("generate"), GraphTargetType::Generate);
assert_eq!(GraphTargetType::from("gen"), GraphTargetType::Generate);
assert_eq!(GraphTargetType::from("remove"), GraphTargetType::Remove);
assert_eq!(GraphTargetType::from("clean"), GraphTargetType::Remove);
assert_eq!(GraphTargetType::from("init"), GraphTargetType::Init);
}
#[test]
#[should_panic]
fn test_bad_graph() {
let _ = GraphTargetType::from("bad_graph");
}
}

View File

@ -148,3 +148,41 @@ impl From<&str> for MakeTargets {
}
}
}
#[cfg(test)]
mod test {
use crate::make::{
HELP_BLOCK_SELECTION, HELP_BUILD_TARGET_LIST, HELP_VERBOSITY_LEVEL, VerboseLevel,
};
use super::MakeTargets;
#[test]
fn test_help_str() {
insta::assert_yaml_snapshot!(HELP_BLOCK_SELECTION.to_string());
insta::assert_yaml_snapshot!(HELP_VERBOSITY_LEVEL.to_string());
insta::assert_yaml_snapshot!(HELP_BUILD_TARGET_LIST.to_string());
}
#[test]
fn test_block_prog_and_verbosity() {
assert_eq!(VerboseLevel::from("misc"), VerboseLevel::Misc);
assert_eq!(VerboseLevel::from("box"), VerboseLevel::Box);
assert_eq!(VerboseLevel::from("context"), VerboseLevel::Context);
assert_eq!(VerboseLevel::from("info"), VerboseLevel::Info);
assert_eq!(VerboseLevel::from("warning"), VerboseLevel::Warning);
assert_eq!(VerboseLevel::from("error"), VerboseLevel::Error);
assert_eq!(VerboseLevel::from("critical"), VerboseLevel::Critical);
}
#[test]
#[should_panic]
fn test_bad_verbose() {
let _ = VerboseLevel::from("bad_level");
}
#[test]
#[should_panic]
fn test_bad_make() {
let _ = MakeTargets::from("bad_make");
}
}

View File

@ -0,0 +1,5 @@
---
source: config/src/graph.rs
expression: HELP_STR_TO_GRAPH.to_string()
---
"init, generate, gen, clean, remove"

View File

@ -0,0 +1,5 @@
---
source: config/src/make.rs
expression: HELP_VERBOSITY_LEVEL.to_string()
---
"box, context, critical, error, info, misc, warning"

View File

@ -0,0 +1,5 @@
---
source: config/src/make.rs
expression: HELP_BUILD_TARGET_LIST.to_string()
---
"clean, list, glossaries, all"

View File

@ -0,0 +1,5 @@
---
source: config/src/make.rs
expression: HELP_BLOCK_SELECTION.to_string()
---
"block, cargo, class, cool, curse, fade, fine, load, neo, rough, vert"

View File

@ -0,0 +1,5 @@
---
source: config/src/tablegen.rs
expression: HELP_STR_TO_TARGET_TABLES.to_string()
---
"all, classes, craft, files"

View File

@ -9,6 +9,7 @@ use std::sync::LazyLock;
/// An enumeration representing different target types.
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(serde::Serialize))]
pub enum TableGenerationTarget {
/// Processes all classes
Classes,
@ -97,3 +98,26 @@ pub struct Craft {
/// The no_headers table end string formatter
pub end_empty: String,
}
#[cfg(test)]
mod test {
use crate::tablegen::{HELP_STR_TO_TARGET_TABLES, TableGenerationTarget};
#[test]
#[should_panic]
fn test_bad_targets() {
let _ = TableGenerationTarget::from("bob");
}
#[test]
fn test_targets() {
let _ = TableGenerationTarget::from("all");
let _ = TableGenerationTarget::from("files");
let _ = TableGenerationTarget::from("craft");
let _ = TableGenerationTarget::from("classes");
}
#[test]
fn test_str_gen() {
insta::assert_yaml_snapshot!(HELP_STR_TO_TARGET_TABLES.to_string());
}
}

View File

@ -4,6 +4,8 @@
//!
#![warn(missing_docs)]
#![warn(clippy::missing_docs_in_private_items)]
#![feature(coverage_attribute)]
#![coverage(off)]
// Workspace
use graphs::make_graphs;

View File

@ -12,8 +12,8 @@ use super::{
Equipement, InitialEquipementList,
equipement_advanced_repr::RefinedEquipementList,
equipement_structs::{
EqFinishing, EqMaterial, EqNature, EqShape, FILTER_TRUE, FILTER_UNIQUE,
FILTER_UNIQUE_AND_RIGHT_CATEGORY, InnerEquipementStats,
EqFinishing, EqMaterial, EqNature, EqShape, FILTER_TRUE, FILTER_UNIQUE_AND_RIGHT_CATEGORY,
InnerEquipementStats,
},
};
use crate::interfaces::Reportable;

View File

@ -82,6 +82,7 @@ pub(crate) static FILTER_UNIQUE_AND_RIGHT_CATEGORY: LazyLock<FilterFunction<Inne
FilterFunction::<InnerEquipementStats>(Arc::new(filter_id_unique_and_right_category()))
});
/// Filter letting the merge happen iff the id is unique (not present in the previous element)
#[allow(dead_code)]
pub(crate) static FILTER_UNIQUE: LazyLock<FilterFunction<InnerEquipementStats>> =
LazyLock::new(|| FilterFunction::<InnerEquipementStats>(Arc::new(filter_id_unique())));
@ -285,8 +286,8 @@ impl From<InnerEquipementStats> for EqFinishing {
#[cfg(test)]
mod test {
use super::{
EqFinishing, EqMaterial, EqNature, EqShape, Equipement, InitialEquipementList,
InnerEquipementStats,
EqFinishing, EqMaterial, EqNature, EqShape, Equipement, FILTER_UNIQUE,
InitialEquipementList, InnerEquipementStats,
};
use crate::{
interfaces::RecipeCollection,
@ -308,6 +309,7 @@ mod test {
fn test_struct_creation() {
let _stats = InnerEquipementStats::default();
let _eq1 = Equipement {
filter_function: FILTER_UNIQUE.clone(),
..Default::default()
};