diff --git a/apps/desktop/Cargo.lock b/apps/desktop/Cargo.lock index 7a92744ff..2e6868368 100644 --- a/apps/desktop/Cargo.lock +++ b/apps/desktop/Cargo.lock @@ -3268,6 +3268,7 @@ dependencies = [ name = "hack-desktop-core" version = "0.0.0" dependencies = [ + "enum-iterator", "libc", "serde", "serde_json", diff --git a/apps/desktop/core/Cargo.toml b/apps/desktop/core/Cargo.toml index 02d3488f5..611e38b99 100644 --- a/apps/desktop/core/Cargo.toml +++ b/apps/desktop/core/Cargo.toml @@ -14,3 +14,4 @@ libc = "0.2" sha2 = "=0.10.9" [dev-dependencies] +enum-iterator = "2.3.0" diff --git a/apps/desktop/core/src/fixtures.rs b/apps/desktop/core/src/fixtures.rs index 664023e60..9da9cb70d 100644 --- a/apps/desktop/core/src/fixtures.rs +++ b/apps/desktop/core/src/fixtures.rs @@ -15,6 +15,7 @@ use crate::state::{Action, LocalContext}; /// Every designed state that can be shown with `--fixtures `. #[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(test, derive(enum_iterator::Sequence))] pub enum Fixture { EnvLoading, EnvError, @@ -106,7 +107,8 @@ pub enum Fixture { } impl Fixture { - pub const ALL: [Self; 64] = [ + /// Every fixture in display order. + pub const ALL: &'static [Self] = &[ Self::EnvLoading, Self::EnvError, Self::EnvNormal, @@ -253,7 +255,7 @@ impl Fixture { #[must_use] pub fn parse(name: &str) -> Option { - Self::ALL.into_iter().find(|f| f.name() == name) + Self::ALL.iter().copied().find(|f| f.name() == name) } } @@ -1273,9 +1275,20 @@ mod tests { assert!(opens_doctor(Fixture::Doctor) && !opens_doctor(Fixture::Running)); } + #[test] + fn all_lists_every_variant_once() { + for fixture in enum_iterator::all::() { + assert!( + Fixture::ALL.contains(&fixture), + "missing fixture {fixture:?}" + ); + } + assert_eq!(Fixture::ALL.len(), enum_iterator::cardinality::()); + } + #[test] fn names_round_trip() { - for f in Fixture::ALL { + for &f in Fixture::ALL { assert_eq!(Fixture::parse(f.name()), Some(f)); } assert_eq!(Fixture::parse("nope"), None); @@ -1283,7 +1296,7 @@ mod tests { #[test] fn every_fixture_has_a_snapshot_or_designed_error() { - for f in Fixture::ALL { + for &f in Fixture::ALL { match (f, snapshot(f)) { (Fixture::Loading, Err(SourceError::Pending)) | (Fixture::CliMissing, Err(SourceError::CliMissing)) @@ -1302,7 +1315,7 @@ mod tests { #[test] fn fixtures_hold_no_private_paths() { - for f in Fixture::ALL { + for &f in Fixture::ALL { let json = serde_json::to_string(&project(f)).unwrap(); assert!(!json.contains("/home/") && !json.contains("/Users/")); }