summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-09-26 11:25:31 +0300
committerLars Wirzenius <liw@liw.fi>2019-09-26 11:25:31 +0300
commit048c226cec9b8f41e19910b23b61d0a7f0d3ac62 (patch)
tree6b2ef1748971857de326ebce35251ef573d7c422 /src
parentfb06994741fb203d7a40b614132b0bddd50f1410 (diff)
downloadroadmap-048c226cec9b8f41e19910b23b61d0a7f0d3ac62.tar.gz
Add: check that there's exactly one goal
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1fc6435..b186ee4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -192,6 +192,11 @@ impl Roadmap {
}
}
+ // Is there exactly one goal?
+ if self.count_goals() != 1 {
+ return Err(format!("must have exactly one goal for roadmap"));
+ }
+
// Does every dependency exist?
for step in self.steps.iter() {
for depname in step.dependencies() {
@@ -211,6 +216,17 @@ impl Roadmap {
Ok(())
}
+ // Count number of steps that nothing depends on.
+ fn count_goals(&self) -> usize {
+ self.steps
+ .iter()
+ .map(|step| {
+ self.is_goal(step)
+ })
+ .filter(|b| *b)
+ .count()
+ }
+
/// Return list of step names.
pub fn step_names<'a>(&'a self) -> Vec<&'a str> {
let mut names = vec![];
@@ -536,8 +552,11 @@ first -> second;
#[test]
fn from_empty_yaml() {
- let roadmap = Roadmap::from_yaml("{}").unwrap();
- assert_eq!(roadmap.step_names().len(), 0);
+ let roadmap = Roadmap::from_yaml("{}");
+ match roadmap {
+ Ok(_) => panic!("expected error for empty dict"),
+ _ => (),
+ }
}
#[test]