diff options
-rw-r--r-- | bin/core/imag-header/src/lib.rs | 4 | ||||
-rw-r--r-- | bin/core/imag-init/src/lib.rs | 2 | ||||
-rw-r--r-- | bin/core/imag-view/src/lib.rs | 2 | ||||
-rw-r--r-- | bin/core/imag/src/main.rs | 152 | ||||
-rw-r--r-- | bin/domain/imag-calendar/src/filters.rs | 8 | ||||
-rw-r--r-- | bin/domain/imag-calendar/src/lib.rs | 16 | ||||
-rw-r--r-- | bin/domain/imag-calendar/src/util.rs | 44 | ||||
-rw-r--r-- | bin/domain/imag-todo/src/import.rs | 10 | ||||
-rw-r--r-- | bin/domain/imag-todo/src/lib.rs | 19 | ||||
-rw-r--r-- | bin/domain/imag-todo/src/ui.rs | 1 | ||||
-rw-r--r-- | lib/domain/libimagcalendar/src/store.rs | 4 | ||||
-rw-r--r-- | tests/ui/src/imag.rs | 5 | ||||
-rw-r--r-- | tests/ui/src/imag_create.rs | 2 | ||||
-rw-r--r-- | tests/ui/src/imag_grep.rs | 4 | ||||
-rw-r--r-- | tests/ui/src/imag_view.rs | 2 | ||||
-rw-r--r-- | tests/version-sync/src/lib.rs | 8 |
16 files changed, 132 insertions, 151 deletions
diff --git a/bin/core/imag-header/src/lib.rs b/bin/core/imag-header/src/lib.rs index 7617a16a..243cd939 100644 --- a/bin/core/imag-header/src/lib.rs +++ b/bin/core/imag-header/src/lib.rs @@ -176,7 +176,7 @@ fn has<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()> iter.and_then_ok(|entry| { trace!("Processing headers: working on {:?}", entry.get_location()); - if let Some(_) = entry.get_header().read(header_path)? { + if entry.get_header().read(header_path)?.is_some() { if !rt.output_is_pipe() { writeln!(output, "{}", entry.get_location())?; } @@ -197,7 +197,7 @@ fn hasnt<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()> iter.and_then_ok(|entry| { trace!("Processing headers: working on {:?}", entry.get_location()); - if let Some(_) = entry.get_header().read(header_path)? { + if entry.get_header().read(header_path)?.is_some() { Ok(()) } else { if !rt.output_is_pipe() { diff --git a/bin/core/imag-init/src/lib.rs b/bin/core/imag-init/src/lib.rs index b273f2de..a0336df8 100644 --- a/bin/core/imag-init/src/lib.rs +++ b/bin/core/imag-init/src/lib.rs @@ -141,7 +141,7 @@ pub fn imag_init() -> Result<()> { config_path }; - let _ = OpenOptions::new() + OpenOptions::new() .write(true) .create(true) .open(config_path) diff --git a/bin/core/imag-view/src/lib.rs b/bin/core/imag-view/src/lib.rs index e0245308..d97d8711 100644 --- a/bin/core/imag-view/src/lib.rs +++ b/bin/core/imag-view/src/lib.rs @@ -259,7 +259,7 @@ fn create_tempfile_for<'a>(entry: &FileLockEntry<'a>, view_header: bool, hide_co .path() .to_str() .map(String::from) - .ok_or_else(|| Error::from(err_msg("Cannot build path")))?; + .ok_or_else(|| err_msg("Cannot build path"))?; Ok((tmpfile, file_path)) } diff --git a/bin/core/imag/src/main.rs b/bin/core/imag/src/main.rs index d879d755..628c1093 100644 --- a/bin/core/imag/src/main.rs +++ b/bin/core/imag/src/main.rs @@ -196,89 +196,87 @@ fn main() -> Result<()> { if matches.is_present("version") { debug!("Showing version"); writeln!(out, "imag {}", env!("CARGO_PKG_VERSION")).map_err(Error::from) - } else { - if matches.is_present("versions") { - debug!("Showing versions"); - commands - .iter() - .map(|command| { - match Command::new(format!("imag-{}", command)) - .stdin(::std::process::Stdio::inherit()) - .stdout(::std::process::Stdio::piped()) - .stderr(::std::process::Stdio::inherit()) - .arg("--version") - .output() - .map(|v| v.stdout) - { - Ok(s) => match String::from_utf8(s) { - Ok(s) => format!("{:15} -> {}", command, s), - Err(e) => format!("UTF8 Error while working with output of imag{}: {:?}", command, e), - }, - Err(e) => format!("Failed calling imag-{} -> {:?}", command, e), - } - }) - .fold(Ok(()), |_, line| { - // The amount of newlines may differ depending on the subprocess - writeln!(out, "{}", line.trim()).map_err(Error::from) - }) - } else { - let aliases = fetch_aliases(config.as_ref()) - .map_err(Error::from) - .context("Error while fetching aliases from configuration file")?; - - // Matches any subcommand given, except calling for example 'imag --versions', as this option - // does not exit. There's nothing to do in such a case - if let (subcommand, Some(scmd)) = matches.subcommand() { - // Get all given arguments and further subcommands to pass to - // the imag-<> binary - // Providing no arguments is OK, and is therefore ignored here - let mut subcommand_args : Vec<String> = match scmd.values_of("") { - Some(values) => values.map(String::from).collect(), - None => Vec::new() - }; - - debug!("Processing forwarding of commandline arguments"); - forward_commandline_arguments(&matches, &mut subcommand_args); - - let subcommand = String::from(subcommand); - let subcommand = aliases.get(&subcommand).cloned().unwrap_or(subcommand); - - debug!("Calling 'imag-{}' with args: {:?}", subcommand, subcommand_args); - - // Create a Command, and pass it the gathered arguments - match Command::new(format!("imag-{}", subcommand)) - .stdin(Stdio::inherit()) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .args(&subcommand_args[..]) - .spawn() - .and_then(|mut c| c.wait()) + } else if matches.is_present("versions") { + debug!("Showing versions"); + commands + .iter() + .map(|command| { + match Command::new(format!("imag-{}", command)) + .stdin(::std::process::Stdio::inherit()) + .stdout(::std::process::Stdio::piped()) + .stderr(::std::process::Stdio::inherit()) + .arg("--version") + .output() + .map(|v| v.stdout) { - Ok(exit_status) => if !exit_status.success() { - debug!("imag-{} exited with non-zero exit code: {:?}", subcommand, exit_status); - Err(format_err!("imag-{} exited with non-zero exit code", subcommand)) - } else { - debug!("Successful exit!"); - Ok(()) + Ok(s) => match String::from_utf8(s) { + Ok(s) => format!("{:15} -> {}", command, s), + Err(e) => format!("UTF8 Error while working with output of imag{}: {:?}", command, e), }, + Err(e) => format!("Failed calling imag-{} -> {:?}", command, e), + } + }) + .fold(Ok(()), |_, line| { + // The amount of newlines may differ depending on the subprocess + writeln!(out, "{}", line.trim()).map_err(Error::from) + }) + } else { + let aliases = fetch_aliases(config.as_ref()) + .map_err(Error::from) + .context("Error while fetching aliases from configuration file")?; + + // Matches any subcommand given, except calling for example 'imag --versions', as this option + // does not exit. There's nothing to do in such a case + if let (subcommand, Some(scmd)) = matches.subcommand() { + // Get all given arguments and further subcommands to pass to + // the imag-<> binary + // Providing no arguments is OK, and is therefore ignored here + let mut subcommand_args : Vec<String> = match scmd.values_of("") { + Some(values) => values.map(String::from).collect(), + None => Vec::new() + }; + + debug!("Processing forwarding of commandline arguments"); + forward_commandline_arguments(&matches, &mut subcommand_args); + + let subcommand = String::from(subcommand); + let subcommand = aliases.get(&subcommand).cloned().unwrap_or(subcommand); + + debug!("Calling 'imag-{}' with args: {:?}", subcommand, subcommand_args); + + // Create a Command, and pass it the gathered arguments + match Command::new(format!("imag-{}", subcommand)) + .stdin(Stdio::inherit()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .args(&subcommand_args[..]) + .spawn() + .and_then(|mut c| c.wait()) + { + Ok(exit_status) => if !exit_status.success() { + debug!("imag-{} exited with non-zero exit code: {:?}", subcommand, exit_status); + Err(format_err!("imag-{} exited with non-zero exit code", subcommand)) + } else { + debug!("Successful exit!"); + Ok(()) + }, - Err(e) => { - debug!("Error calling the subcommand"); - match e.kind() { - ErrorKind::NotFound => { - writeln!(out, "No such command: 'imag-{}'", subcommand)?; - writeln!(out, "See 'imag --help' for available subcommands").map_err(Error::from) - }, - ErrorKind::PermissionDenied => { - writeln!(out, "No permission to execute: 'imag-{}'", subcommand).map_err(Error::from) - }, - _ => writeln!(out, "Error spawning: {:?}", e).map_err(Error::from), - } + Err(e) => { + debug!("Error calling the subcommand"); + match e.kind() { + ErrorKind::NotFound => { + writeln!(out, "No such command: 'imag-{}'", subcommand)?; + writeln!(out, "See 'imag --help' for available subcommands").map_err(Error::from) + }, + ErrorKind::PermissionDenied => { + writeln!(out, "No permission to execute: 'imag-{}'", subcommand).map_err(Error::from) + }, + _ => writeln!(out, "Error spawning: {:?}", e).map_err(Error::from), } } - } else { - Ok(()) } + } else { + Ok(()) } } } diff --git a/bin/domain/imag-calendar/src/filters.rs b/bin/domain/imag-calendar/src/filters.rs index 20743671..d587026b 100644 --- a/bin/domain/imag-calendar/src/filters.rs +++ b/bin/domain/imag-calendar/src/filters.rs @@ -55,9 +55,9 @@ pub fn event_is_before<'a>(event: &Event<'a>, before_spec: &NaiveDateTime) -> bo trace!("dtstamp_is_before_spec = {:?}", dtstamp_is_before_spec); match (dtend_is_before_spec, dtstamp_is_before_spec) { - (Ok(b), _) => return b, - (_, Ok(b)) => return b, - (Err(e), _) => return Err(e).map_err_trace_exit_unwrap() + (Ok(b), _) => b, + (_, Ok(b)) => b, + (Err(e), _) => Err(e).map_err_trace_exit_unwrap() } } @@ -66,7 +66,7 @@ pub fn event_is_after<'a>(event: &Event<'a>, after_spec: &NaiveDateTime) -> bool } fn try_to_parse_datetime(s: &str) -> Result<NaiveDateTime> { - const FORMATS : &[&'static str] = &[ + const FORMATS : &[&str] = &[ "%Y%m%dT%H%M%S", "%Y%m%dT%H%M%SZ" ]; diff --git a/bin/domain/imag-calendar/src/lib.rs b/bin/domain/imag-calendar/src/lib.rs index cc60b602..ff479757 100644 --- a/bin/domain/imag-calendar/src/lib.rs +++ b/bin/domain/imag-calendar/src/lib.rs @@ -135,7 +135,6 @@ fn import(rt: &Runtime) -> Result<()> { let iter = scmd .values_of("filesordirs") .unwrap() // save by clap - .into_iter() .map(PathBuf::from) .map(|path| if path.is_dir() { // Find all files Box::new(WalkDir::new(path) @@ -157,7 +156,7 @@ fn import(rt: &Runtime) -> Result<()> { } else { // is file, ensured by clap validator Box::new(std::iter::once(Ok(path))) }) - .flat_map(|it| it) // From Iter<Iter<Result<PathBuf>>> to Iter<Result<PathBuf>> + .flatten() // From Iter<Iter<Result<PathBuf>>> to Iter<Result<PathBuf>> .and_then_ok(|path| { trace!("Importing {}", path.display()); Ok({ @@ -168,7 +167,7 @@ fn import(rt: &Runtime) -> Result<()> { }) // Iter<Result<Iter<_>> .collect::<Result<Vec<_>>>()? .into_iter() - .flat_map(|it| it) + .flatten() .and_then_ok(|fle| rt.report_touched(fle.get_location()).map_err(Error::from)); if do_fail { @@ -241,14 +240,14 @@ fn list(rt: &Runtime) -> Result<()> { parsed_entry .get_data() .events() - .map_err(|component| Error::from(format_err!("Failed to parse entry: {}", component.name))) + .map_err(|component| format_err!("Failed to parse entry: {}", component.name)) .and_then_ok(|event| { event_filter(&event).map(|b| (event, b)) }) .filter_ok(|tpl| (*tpl).1) .map_ok(|tpl| tpl.0) .and_then_ok(|event| { - listed_events = listed_events + 1; + listed_events += 1; let data = build_data_object_for_handlebars(listed_events, &event); let rendered = list_format.render("format", &data)?; @@ -275,7 +274,6 @@ fn show(rt: &Runtime) -> Result<()> { scmd.values_of("show-ids") .unwrap() // safe by clap - .into_iter() .map(|id| { let e = util::find_event_by_id(rt.store(), id, &ref_config)?; debug!("Found => {:?}", e); @@ -289,14 +287,14 @@ fn show(rt: &Runtime) -> Result<()> { parsed_entry .get_data() .events() - .map_err(|component| Error::from(format_err!("Failed to parse entry: {}", component.name))) + .map_err(|component| format_err!("Failed to parse entry: {}", component.name)) .filter_ok(|pent| { let relevant = pent.uid().map(|uid| uid.raw().starts_with(id)).unwrap_or(false); debug!("Relevant {} => {}", parsed_entry.get_entry().get_location(), relevant); relevant }) .and_then_ok(|event| { - shown_events = shown_events + 1; + shown_events += 1; let data = util::build_data_object_for_handlebars(shown_events, &event); let rendered = list_format.render("format", &data)?; @@ -312,6 +310,6 @@ fn show(rt: &Runtime) -> Result<()> { /// helper function to check whether a DirEntry points to something hidden (starting with dot) fn is_not_hidden(entry: &DirEntry) -> bool { - !entry.file_name().to_str().map(|s| s.starts_with(".")).unwrap_or(false) + !entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) } diff --git a/bin/domain/imag-calendar/src/util.rs b/bin/domain/imag-calendar/src/util.rs index a3f17350..f6a45460 100644 --- a/bin/domain/imag-calendar/src/util.rs +++ b/bin/domain/imag-calendar/src/util.rs @@ -132,14 +132,11 @@ pub fn kairos_parse(spec: &str) -> Result<NaiveDateTime> { ::kairos::parser::Parsed::TimeType(tt) => { trace!("before-filter spec resulted in timetype"); - let tt = tt.calculate() + tt.calculate() .map_err_trace_exit_unwrap() .get_moment() - .ok_or_else(|| format_err!("Not a moment in time: {}", spec))? - .clone(); - - trace!("Before filter spec {} => {}", spec, tt); - Ok(tt) + .cloned() + .ok_or_else(|| format_err!("Not a moment in time: {}", spec)) } } } @@ -160,25 +157,26 @@ pub fn find_event_by_id<'a>(store: &'a Store, id: &str, refconfig: &Config) -> R trace!("Checking whether {} is represented by {}", id, event.get_location()); let parsed = ParsedEventFLE::parse(event, refconfig)?; - if parsed + let found = parsed .get_data() .events() - .filter_map(|event| if event - .as_ref() - .map(|e| { - trace!("Checking whether {:?} starts with {}", e.uid(), id); - e.uid().map(|uid| uid.raw().starts_with(id)).unwrap_or(false) - }) - .unwrap_or(false) - { - trace!("Seems to be relevant"); - Some(event) - } else { - None - }) - .next() - .is_some() - { + .any(|event| { + let take = event + .as_ref() + .map(|e| { + trace!("Checking whether {:?} starts with {}", e.uid(), id); + e.uid().map(|uid| uid.raw().starts_with(id)).unwrap_or(false) + }) + .unwrap_or(false); + + if take { + trace!("Seems to be relevant"); + } + + take + }); + + if found { return Ok(Some(parsed)) } } diff --git a/bin/domain/imag-todo/src/import.rs b/bin/domain/imag-todo/src/import.rs index 6194bcbd..81d39297 100644 --- a/bin/domain/imag-todo/src/import.rs +++ b/bin/domain/imag-todo/src/import.rs @@ -89,12 +89,11 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { taskwarrior_import(stdin)? .into_iter() .map(|task| { - let hash = task.uuid().clone(); let mut todo = store .todo_builder() .with_check_sanity(false) // data should be imported, even if it is not sane .with_status(translate_status(task.status())) - .with_uuid(Some(task.uuid().clone())) + .with_uuid(Some(*task.uuid())) .with_due(task.due().map(Deref::deref).cloned()) .with_scheduled(task.scheduled().map(Deref::deref).cloned()) .with_hidden(task.wait().map(Deref::deref).cloned()) @@ -104,13 +103,12 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { todo.set_content(task.description().clone()); if let Some(tags) = task.tags() { - tags.into_iter().map(|tag| { - let tag = tag.clone(); + tags.iter().map(|tag| { if libimagentrytag::tag::is_tag_str(&tag).is_err() { warn!("Not a valid tag, ignoring: {}", tag); Ok(()) } else { - todo.add_tag(tag) + todo.add_tag(tag.clone()) } }).collect::<Result<Vec<_>>>()?; } @@ -130,7 +128,7 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { } let dependends = task.depends().cloned().unwrap_or_else(|| vec![]); - Ok((hash, dependends)) + Ok((*task.uuid(), dependends)) }) .collect::<Result<HashMap<Uuid, Vec<Uuid>>>>()? diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs index 968b4d14..96ff913f 100644 --- a/bin/domain/imag-todo/src/lib.rs +++ b/bin/domain/imag-todo/src/lib.rs @@ -147,7 +147,7 @@ impl ImagApplication for ImagTodo { /// The blacklist is checked first, followed by the whitelist. /// In case the whitelist is empty, the StatusMatcher works with a /// blacklist-only approach. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct StatusMatcher { is: Vec<Status>, is_not: Vec<Status>, @@ -155,10 +155,7 @@ pub struct StatusMatcher { impl StatusMatcher { pub fn new() -> Self { - StatusMatcher { - is: Vec::new(), - is_not: Vec::new(), - } + StatusMatcher { ..Default::default() } } pub fn is(mut self, s: Status) -> Self { @@ -170,6 +167,7 @@ impl StatusMatcher { self.is.push(s); } + #[allow(clippy::wrong_self_convention)] pub fn is_not(mut self, s: Status) -> Self { self.add_is_not(s); self @@ -180,15 +178,14 @@ impl StatusMatcher { } pub fn matches(&self, todo: Status) -> bool { - if self.is_not.iter().find(|t| **t == todo).is_some() { + if self.is_not.iter().any(|t| *t == todo) { // On blacklist false - } else if self.is.len() < 1 || self.is.iter().find(|t| **t == todo).is_some() { - // No whitelist or on whitelist - true } else { + // No whitelist or on whitelist + // or // Not on blacklist, but whitelist exists and not on it either - false + self.is.is_empty() || self.is.iter().any(|t| *t == todo) } } } @@ -289,7 +286,7 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul let hidden = util::get_dt_str(entry.get_hidden(), "Not hidden")?; let due = util::get_dt_str(entry.get_due(), "No due")?; let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string()) - .unwrap_or("No prio".to_string()); + .unwrap_or_else(|| "No prio".to_string()); writeln!(sink, "{uuid} - {status} - {sched} - {hidden} - {due} - {prio}: {first_line}", uuid = uuid, diff --git a/bin/domain/imag-todo/src/ui.rs b/bin/domain/imag-todo/src/ui.rs index b5646273..0b9cf73f 100644 --- a/bin/domain/imag-todo/src/ui.rs +++ b/bin/domain/imag-todo/src/ui.rs @@ -216,7 +216,6 @@ impl IdPathProvider for PathProvider { _ => unimplemented!() } .map(|v| v - .into_iter() .map(|s| if s.starts_with("todo") { s.to_string() } else { diff --git a/lib/domain/libimagcalendar/src/store.rs b/lib/domain/libimagcalendar/src/store.rs index 99bc06da..00d365c5 100644 --- a/lib/domain/libimagcalendar/src/store.rs +++ b/lib/domain/libimagcalendar/src/store.rs @@ -93,10 +93,10 @@ impl<'a> EventStore<'a> for Store { let uid_header = Value::String(uid.into_raw()); let mut entry = self.create(sid)?; - let _ = entry + entry .as_ref_with_hasher_mut::<DefaultHasher>() .make_ref(p.as_ref(), basepath_name.as_ref(), refconfig, force)?; - let _ = entry.get_header_mut().insert("calendar.event.uid", uid_header)?; + entry.get_header_mut().insert("calendar.event.uid", uid_header)?; entry.set_isflag::<IsEvent>()?; Ok(entry) }) diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs index fb413ab3..1faba635 100644 --- a/tests/ui/src/imag.rs +++ b/tests/ui/src/imag.rs @@ -67,11 +67,6 @@ pub fn stderr_of_command(command: &mut Command) -> (Assert, Vec<String>) { (assert, lines) } -/// Create a PathBuf for a file in a TempDir -pub fn file_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf { - create_path_for(tempdir.path().to_path_buf(), path_elements) -} - pub fn store_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf { let mut path = tempdir.path().to_path_buf(); path.push("store"); diff --git a/tests/ui/src/imag_create.rs b/tests/ui/src/imag_create.rs index 993ba366..18571952 100644 --- a/tests/ui/src/imag_create.rs +++ b/tests/ui/src/imag_create.rs @@ -63,7 +63,7 @@ fn test_creating_works() { { let version_line = lines.next().unwrap(); assert!(version_line.starts_with("version = '")); - assert!(version_line.ends_with("'")); + assert!(version_line.ends_with('\'')); let version = version_line.replace("version = '", "").replace("'", ""); let semver = semver::Version::parse(&version); assert!(semver.is_ok()); diff --git a/tests/ui/src/imag_grep.rs b/tests/ui/src/imag_grep.rs index 9eac75a7..3b8c3a24 100644 --- a/tests/ui/src/imag_grep.rs +++ b/tests/ui/src/imag_grep.rs @@ -77,7 +77,7 @@ fn test_grepping_not_available_string() { .open(&filepath) .unwrap(); - let _ = writeln!(file, "unavailable").unwrap(); + writeln!(file, "unavailable").unwrap(); } let output = call(&imag_home, "something"); @@ -104,7 +104,7 @@ fn test_grepping_available_string() { .open(&filepath) .unwrap(); - let _ = writeln!(file, "{}", filetext).unwrap(); + writeln!(file, "{}", filetext).unwrap(); } let output = call(&imag_home, filetext); diff --git a/tests/ui/src/imag_view.rs b/tests/ui/src/imag_view.rs index e7bfe5e4..f499b1cc 100644 --- a/tests/ui/src/imag_view.rs +++ b/tests/ui/src/imag_view.rs @@ -19,9 +19,7 @@ use std::process::Command; -use assert_cmd::prelude::*; use assert_fs::fixture::TempDir; -use predicates::prelude::*; /// Helper to call imag-init pub fn call(tempdir: &TempDir, targets: &[&str]) -> Vec<String> { diff --git a/tests/version-sync/src/lib.rs b/tests/version-sync/src/lib.rs index b167c74a..7e74f80d 100644 --- a/tests/version-sync/src/lib.rs +++ b/tests/version-sync/src/lib.rs @@ -70,8 +70,8 @@ fn test_all_cargotoml_files() { None }) .for_each(|cargotoml| { - let filecontent = std::fs::read_to_string(&cargotoml).expect(&format!("Failed to read {}", cargotoml.display())); - let toml = filecontent.parse::<Value>().expect(&format!("Failed to parse toml: {}", cargotoml.display())); + let filecontent = std::fs::read_to_string(&cargotoml).unwrap_or_else(|_| panic!("Failed to read {}", cargotoml.display())); + let toml = filecontent.parse::<Value>().unwrap_or_else(|_| panic!("Failed to parse toml: {}", cargotoml.display())); match toml.get("dependencies") { Some(Value::Table(ref tab)) => { @@ -80,7 +80,7 @@ fn test_all_cargotoml_files() { match v { Value::String(s) => assert!(s.contains(current_version)), Value::Table(ref dep) => { - let version = dep.get("version").expect(&format!("No 'version' key for dependencies at {}", cargotoml.display())); + let version = dep.get("version").unwrap_or_else(|| panic!("No 'version' key for dependencies at {}", cargotoml.display())); let version_str = version.as_str().unwrap(); assert!(version_str.contains(current_version), "failed for: {} ('{}')", cargotoml.display(), version_str) }, @@ -100,7 +100,7 @@ fn test_all_cargotoml_files() { match v { Value::String(s) => assert!(s.contains(current_version)), Value::Table(ref dep) => { - let version = dep.get("version").expect(&format!("No 'version' key for dev-dependencies at {}", cargotoml.display())); + let version = dep.get("version").unwrap_or_else(|| panic!("No 'version' key for dev-dependencies at {}", cargotoml.display())); let version_str = version.as_str().unwrap(); assert!(version_str.contains(current_version), "failed for: {} ('{}')", cargotoml.display(), version_str) }, |