message: Rework and test gnuplot version parsing to work on older compilers.
diff: @@ -411,6 +411,7 @@ use std::io;
  use std::path::Path;
  use std::process::{Child, Command};
  use std::str;
  +use std::num::ParseIntError;
  use failure::Error;
  @@ -975,8 +976,6 @@ pub enum VersionError {
  /// Returns `gnuplot` version
  pub fn version() -> Result<(usize, usize, usize), Error> {
  - use std::num::ParseIntError;
  -
  let command_output = Command::new("gnuplot").arg("--version").output()
  .map_err(VersionError::Exec)?;
  if !command_output.status.success() {
  @@ -987,14 +986,16 @@ pub fn version() -> Result<(usize, usize, usize), Error> {
  let output = String::from_utf8(command_output.stdout)
  .map_err(|_| VersionError::OutputError)?;
  - let unwrap_none = || { VersionError::ParseError(output.clone()) };
  - let unwrap_err = |_: ParseIntError| { VersionError::ParseError(output.clone()) };
  - let mut words = output.split_whitespace().skip(1);
  - let mut version = words.next().ok_or_else(unwrap_none)?.split('.');
  - let major = version.next().ok_or_else(unwrap_none)?.parse().map_err(unwrap_err)?;
  - let minor = version.next().ok_or_else(unwrap_none)?.parse().map_err(unwrap_err)?;
  - let patchlevel = words.nth(1).ok_or_else(unwrap_none)?.parse().map_err(unwrap_err)?;
  + parse_version(&output).map_err(|_| { VersionError::ParseError(output.clone()).into() })
  +}
  +
  +fn parse_version(version_str: &str) -> Result<(usize, usize, usize), Option<ParseIntError>> {
  + let mut words = version_str.split_whitespace().skip(1);
  + let mut version = words.next().ok_or(None)?.split('.');
  + let major = version.next().ok_or(None)?.parse()?;
  + let minor = version.next().ok_or(None)?.parse()?;
  + let patchlevel = words.nth(1).ok_or(None)?.parse()?;
  Ok((major, minor, patchlevel))
  }
  @@ -1041,4 +1042,26 @@ mod test {
  println!("Gnuplot not installed.");
  }
  }
  +
  + #[test]
  + fn test_parse_version_on_valid_string() {
  + let string = "gnuplot 5.0 patchlevel 7";
  + let version = super::parse_version(&string).unwrap();
  + assert_eq!((5, 0, 7), version);
  + }
  +
  + #[test]
  + fn test_parse_version_returns_error_on_invalid_strings() {
  + let strings = [
  + "",
  + "foobar",
  + "gnuplot 50 patchlevel 7",
  + "gnuplot 5.0 patchlevel",
  + "gnuplot 5.0 patchlevel foo",
  + "gnuplot foo.bar patchlevel 7"
  + ];
  + for string in &strings {
  + assert!(super::parse_version(string).is_err());
  + }
  + }
  }
  