From 3e78d2068ecceedaf08573022cf4c04f9177cc01 Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Mon, 20 Jul 2026 14:48:40 +0200 Subject: [PATCH] icons: Add test to ensure all icon variants exist (#61337) This is just to help with bookkeeping, as we currently do not ensure anywhere icons do actually exist. Release Notes: - N/A --- assets/icons/supermaven.svg | 8 ------- crates/icons/src/icons.rs | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) delete mode 100644 assets/icons/supermaven.svg diff --git a/assets/icons/supermaven.svg b/assets/icons/supermaven.svg deleted file mode 100644 index af778c70b7..0000000000 --- a/assets/icons/supermaven.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/crates/icons/src/icons.rs b/crates/icons/src/icons.rs index 6a94f8c7b4..d1005517d7 100644 --- a/crates/icons/src/icons.rs +++ b/crates/icons/src/icons.rs @@ -309,3 +309,45 @@ impl IconName { format!("icons/{file_stem}.svg").into() } } + +#[cfg(test)] +mod tests { + use std::path::PathBuf; + + use strum::{IntoEnumIterator as _, ParseError}; + + use crate::IconName; + + #[test] + fn test_all_icons_exist() { + let asset_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../assets"); + + for icon in IconName::iter() { + let icon_path = asset_path.join(&*icon.path()); + assert!( + icon_path.exists(), + "Icon {icon:?} does not exist at {icon_path:?}", + ); + } + } + + #[test] + fn test_no_dangling_icons() -> Result<(), ParseError> { + let icons_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../assets/icons"); + + for entry in std::fs::read_dir(&icons_dir).expect("failed to read icons directory") { + let path = entry.expect("failed to read icons directory entry").path(); + if path.extension().is_none_or(|extension| extension != "svg") { + continue; + } + let file_stem = path + .file_stem() + .and_then(|file_stem| file_stem.to_str()) + .expect("icon file name is not valid UTF-8"); + + file_stem.parse::()?; + } + + Ok(()) + } +}