From afb4bf47340f4ae6dbfb1dcfd199dcdacc42c378 Mon Sep 17 00:00:00 2001 From: Ryan Geary Date: Sun, 15 Mar 2020 16:14:17 -0400 Subject: Return ParseIntErrors from parse_choice --- src/config.rs | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/config.rs b/src/config.rs index cacc87e..9814a85 100644 --- a/src/config.rs +++ b/src/config.rs @@ -83,10 +83,9 @@ impl Config { Some(v) => v, None => match src.parse() { Ok(x) => return Ok(Choice::new(x, x)), - Err(_) => { + Err(e) => { eprintln!("failed to parse choice argument: {}", src); - // Exit code of 2 means failed to parse choice argument - process::exit(2); + return Err(e); } }, }; @@ -96,9 +95,9 @@ impl Config { } else { match cap[1].parse() { Ok(x) => x, - Err(_) => { + Err(e) => { eprintln!("failed to parse range start: {}", &cap[1]); - process::exit(2); + return Err(e); } } }; @@ -108,9 +107,9 @@ impl Config { } else { match cap[2].parse() { Ok(x) => x, - Err(_) => { + Err(e) => { eprintln!("failed to parse range end: {}", &cap[2]); - process::exit(2); + return Err(e); } } }; @@ -165,16 +164,14 @@ mod tests { ) } - // These tests should pass once parse_choice return errors properly, but until that time - // makes running other tests impossible. - //#[test] - //fn parse_bad_choice() { - //assert!(Config::parse_choice("d").is_err()); - //} - - //#[test] - //fn parse_bad_range() { - //assert!(Config::parse_choice("d:i").is_err()); - //} + #[test] + fn parse_bad_choice() { + assert!(Config::parse_choice("d").is_err()); + } + + #[test] + fn parse_bad_range() { + assert!(Config::parse_choice("d:i").is_err()); + } } } -- cgit v1.2.3