Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/desktop/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/desktop/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ libc = "0.2"
sha2 = "=0.10.9"

[dev-dependencies]
enum-iterator = "2.3.0"
23 changes: 18 additions & 5 deletions apps/desktop/core/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::state::{Action, LocalContext};

/// Every designed state that can be shown with `--fixtures <name>`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(test, derive(enum_iterator::Sequence))]
pub enum Fixture {
EnvLoading,
EnvError,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -253,7 +255,7 @@ impl Fixture {

#[must_use]
pub fn parse(name: &str) -> Option<Self> {
Self::ALL.into_iter().find(|f| f.name() == name)
Self::ALL.iter().copied().find(|f| f.name() == name)
}
}

Expand Down Expand Up @@ -1273,17 +1275,28 @@ mod tests {
assert!(opens_doctor(Fixture::Doctor) && !opens_doctor(Fixture::Running));
}

#[test]
fn all_lists_every_variant_once() {
for fixture in enum_iterator::all::<Fixture>() {
assert!(
Fixture::ALL.contains(&fixture),
"missing fixture {fixture:?}"
);
}
assert_eq!(Fixture::ALL.len(), enum_iterator::cardinality::<Fixture>());
}

#[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);
}

#[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))
Expand All @@ -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/"));
}
Expand Down
Loading