Updates coverage

This commit is contained in:
Dandaedre 2025-03-06 04:43:37 +01:00
parent d7e7ffcb17
commit fadd82ff3b
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
14 changed files with 115 additions and 68 deletions

View File

@ -3,7 +3,7 @@
[workspace]
members = [ "cli_parser", "config", "graphs", "make", "more_fields", "more_fields_macro",
"ravenous-tools", "stats",
"tablegen", "weaponry", "xtask",
"tablegen", "weaponry",
]
resolver = "3"
@ -31,5 +31,3 @@ lto = false
codegen-units = 256
incremental = true
panic = "abort"

View File

@ -1,4 +1,4 @@
![version](badges/version.svg) ![code coverage](badges/plastic.svg)
![version](badges/version.svg) ![code coverage](badges/coverage.svg)
# ravenous-tools

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: 17%"><title>test-coverage: 17%</title><linearGradient id="bms-986ff3b3470c1920" 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-986ff3b3470c1920"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-986ff3b3470c1920)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#e05d44"/><rect width="122" height="18" fill="url(#bms-986ff3b3470c1920)"/></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">17%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">17%</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: 23%"><title>test-coverage: 23%</title><linearGradient id="bms-446d4cb5ae0bdc86" 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-446d4cb5ae0bdc86"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-446d4cb5ae0bdc86)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#e05d44"/><rect width="122" height="18" fill="url(#bms-446d4cb5ae0bdc86)"/></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">23%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">23%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -28,3 +28,6 @@ clap = { version = "4.5.30", features = ["derive"] }
[[bench]]
name = "iter_creation"
harness = false
# [lints.rust]
# unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }

View File

@ -30,17 +30,21 @@ where
/// Generate a SELECT query with fields generated from a struct. Returns a SQL request as a String
#[inline]
#[coverage(off)] // INCORRECT: Error with line report
fn generate_select_query<T: more_fields::FieldsAsSlice>(
table_name: &str,
filter: Option<&str>,
) -> String {
let fields = T::attributes_slice()
.iter()
.map(|(k, _v)| k.to_owned())
.collect::<Vec<_>>()
.join(",");
let filter = filter.map_or_else(String::default, |j| " WHERE ".to_string() + j);
format!("SELECT {} FROM {}{};", fields, table_name, filter)
format!(
"SELECT {} FROM {}{};",
T::attributes_slice()
.iter()
.map(|(k, _v)| k.to_owned())
.collect::<Vec<_>>()
.join(","),
table_name,
filter.map_or_else(String::default, |j| " WHERE ".to_string() + j)
)
}
/// Generate create table_name with fields as columns

View File

@ -42,6 +42,9 @@ pub enum FatalEquipementError {
#[error("Couldn't parse the CLI argument given \"{0}\"")]
CLIParseError(String),
#[error("Couldn't serialize the object to make a query: \n{0}")]
SerdeRSQLite(#[from] serde_rusqlite::Error),
}
// #[derive(Error, Debug)]

View File

@ -9,7 +9,7 @@ use std::{path::Path, rc::Rc};
use more_fields::FieldsAsSlice;
use rusqlite::Connection;
use serde::de::DeserializeOwned;
use serde::{Serialize, de::DeserializeOwned};
use crate::error::FatalEquipementError;
@ -95,6 +95,7 @@ where
fn from_vectored(list: Vec<Self::Recipes>) -> Self;
/// Create a collection from an iterator of intermediate values T
#[coverage(off)] // INCORRECT: Error with line report
fn from_iter_intermediate<T>(
iter_inter: impl Iterator<Item = Result<T, FatalEquipementError>>,
) -> Result<Self, FatalEquipementError>
@ -218,18 +219,50 @@ pub trait RecipeDatabase {
fn get_connection(&self) -> &Connection;
/// Initialize an empty database & table
fn initialize_empty_table<T: FieldsAsSlice>(
fn initialize_empty_table<T: more_fields::FieldsAsSlice>(
&self,
table: &str,
) -> Result<(), FatalEquipementError>;
) -> Result<(), crate::error::FatalEquipementError> {
// A vector of <attribute, type>
self.get_connection().execute(
crate::database::generate_create_table_query(table, T::attributes_slice()).as_str(),
(),
)?;
Ok(())
}
/// Insert a row inside the database, while mostly unused this function is needed to initialize the empty table with an empty row if needed
fn insert_row<T: DeserializeOwned>(&self, row: T) -> Result<(), FatalEquipementError>;
#[coverage(off)] // INCORRECT: Error with line report
fn insert_row<T: FieldsAsSlice + Serialize>(
&self,
table_name: &str,
row: T,
) -> Result<(), FatalEquipementError> {
let query = format!(
"INSERT INTO {} ({}) VALUES ({});",
table_name,
T::attributes_slice()
.iter()
.map(|(k, _v)| *k)
.collect::<Vec<_>>()
.join(","),
T::attributes_slice()
.iter()
.map(|(k, _v)| ":".to_owned() + *k)
.collect::<Vec<_>>()
.join(","),
);
self.get_connection().execute(
&query,
serde_rusqlite::to_params_named(row)?.to_slice().as_slice(),
)?;
Ok(())
}
/// Serialize a request into an intermediate T representation,
/// T having all the implementation specifics of the part in details
/// eg. EqShape, EqPart etc..
fn serialise_into_intermediate<T>(
fn serialize_into_intermediate<T>(
&self,
table: &str,
filter: Option<&str>,
@ -312,7 +345,7 @@ pub trait Scenario where for<'a> &'a <<<Self as Scenario>::InitialEquipementList
{
RecipeCollection::from_iter_intermediate::<T>(
self.get_database()
.serialise_into_intermediate::<T>(self.get_tablename(), filter)?,
.serialize_into_intermediate::<T>(self.get_tablename(), filter)?,
)
}
}

View File

@ -18,6 +18,7 @@ impl<T> Default for FilterFunction<T> {
}
}
impl<T> PartialEq for FilterFunction<T> {
#[coverage(off)] // INCORRECT: Error with line report
fn eq(&self, _other: &Self) -> bool {
true
}

View File

@ -2,19 +2,12 @@
// File: weaponry/src/weaponry_structs/equipement_impl_database.rs
//! All database specific implementations
// use crate::interfaces::DbSerializable;
// use super::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape};
use crate::database::generate_create_table_query;
use crate::error::FatalEquipementError;
use crate::interfaces::{FixedRecipe, RecipeDatabase};
use rusqlite::Connection;
use serde::de::DeserializeOwned;
use super::EquipementSerializedCategory;
use super::equipement_fields::{WeaponBaseShape, WeaponBaseSize};
use super::equipement_structs::{DatabaseEquipementStats, InnerEquipementStats};
use crate::error::FatalEquipementError;
use crate::interfaces::{FixedRecipe, RecipeDatabase};
use rusqlite::Connection;
/// Struct for database connection.
#[derive(Debug)]
@ -27,34 +20,18 @@ impl RecipeDatabase for EquipementDatabase {
type DeserialisationType = DatabaseEquipementStats;
type InnerType = InnerEquipementStats;
/// Checks if database exists, and returns a rusqlite::Connection. If not, opens database in memory.
fn new(filename: &str) -> Result<Self, FatalEquipementError> {
Ok(EquipementDatabase {
conn: Connection::open(filename)?,
})
}
fn initialize_empty_table<T: more_fields::FieldsAsSlice>(
&self,
table: &str,
) -> Result<(), crate::error::FatalEquipementError> {
// A vector of <attribute, type>
let attr_map = T::attributes_slice();
self.conn
.execute(generate_create_table_query(table, attr_map).as_str(), ())?;
Ok(())
}
fn insert_row<T: DeserializeOwned>(&self, row: T) -> Result<(), FatalEquipementError> {
let _ = row;
todo!()
}
fn get_connection(&self) -> &Connection {
&self.conn
}
fn serialise_into_intermediate<T>(
#[coverage(off)] // INCORRECT: Error with line report
fn serialize_into_intermediate<T>(
&self,
table: &str,
filter: Option<&str>,
@ -154,6 +131,7 @@ impl TryFrom<DatabaseEquipementStats> for InnerEquipementStats {
type SubCategories = (Option<WeaponBaseShape>, Option<WeaponBaseSize>);
/// Infer all subcategories from a deserialized DatabaseCategory
#[coverage(off)] // A test would literally be a copy paste of this match
fn get_sub_categories_from_serde(category: &str) -> Result<SubCategories, FatalEquipementError> {
Ok(if let Some(category) = from_serde!(category)? {
match category {

View File

@ -94,3 +94,23 @@ impl std::ops::Add for SpecialField {
c
}
}
#[cfg(test)]
mod test {
#[test]
fn test_macros() {
assert_eq!(first_correct_option!(None::<i8>, None::<i8>), None);
assert_eq!(first_correct_option!(Some(3), None::<i8>), Some(3));
assert_eq!(first_correct_option!(None::<i8>, Some(4)), Some(4));
assert_eq!(first_correct_option!(Some(1), Some(3)), Some(1));
assert_eq!(add_two_options!(Some(1), Some(3)), Some(4));
assert_eq!(add_two_options!(Some(3), None::<i8>), Some(3));
assert_eq!(add_two_options!(None::<i8>, Some(4)), Some(4));
let a = vec![1, 2];
let b = vec![3];
assert_eq!(add_to_vec!(a, b), vec![1, 2, 3]);
}
}

View File

@ -141,22 +141,16 @@ impl Scenario for CrossRecipeScenario {
#[cfg(test)]
mod test {
use more_fields::FieldsAsSlice;
use crate::{
interfaces::{RecipeDatabase, Scenario},
weaponry_structs::{
equipement_impl_database::EquipementDatabase,
equipement_structs::{DatabaseEquipementStats, EqFinishing, InnerEquipementStats},
equipement_structs::{DatabaseEquipementStats, EqFinishing},
},
};
use super::{ConfigEquipementScenario, CrossRecipeScenario};
struct TestStruct {
id: usize,
name: String,
}
#[test]
fn test_scenario() {}
#[test]
@ -166,7 +160,7 @@ mod test {
conn: rusqlite::Connection::open_in_memory().unwrap(),
},
config: ConfigEquipementScenario {
table_name: "TestStruct".to_owned(),
table_name: "Finishing".to_owned(),
db_path: "None".to_owned(),
shape: None,
materials: None,
@ -175,12 +169,19 @@ mod test {
},
};
b.get_database().conn.execute("CREATE TABLE IF NOT EXISTS Finishing (id INTEGER UNIQUE, name TEXT, PRIMARY KEY('id' AUTOINCREMENT));",[]).unwrap();
b.get_database()
.initialize_empty_table::<DatabaseEquipementStats>("Finishing")
.unwrap();
// let r = b
// .deserde_into_processed_representation::<EqFinishing>(None)
// .unwrap();
b.get_database()
.insert_row::<DatabaseEquipementStats>(
"Finishing",
DatabaseEquipementStats::random_new(),
)
.unwrap();
<CrossRecipeScenario as Scenario>::get_database(&b);
let r = b
.deserde_into_processed_representation::<EqFinishing>(None)
.unwrap();
assert_eq!(r.inner.len(), 1);
}
}

View File

@ -102,3 +102,19 @@ impl Display for Dices {
<usize as Display>::fmt(&self.0, f)
}
}
#[cfg(test)]
mod test {
use crate::weaponry_structs::equipement_thin_types::{Actions, Attacks, Dices, Precision};
#[test]
fn test_displays() {
println!(
"{}, {}, {}, {}",
Attacks(0),
Actions(1),
Precision(2),
Dices(3)
);
}
}

View File

@ -1,7 +0,0 @@
[package]
name = "xtask"
edition = "2024"
version.workspace = true
[dependencies]
xtaskops = "0.4.2"

View File

@ -1,3 +0,0 @@
fn main() {
let _ = xtaskops::tasks::main();
}