diff --git a/.travis.yml b/.travis.yml index 4226a1b..8fc1f20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,18 @@ language: rust matrix: - include: - - rust: nightly - env: FEATURES="" - - rust: beta - env: FEATURES="--features stable" - - rust: stable - env: FEATURES="--features stable" - - rust: nightly - env: FEATURES="--features stable" + include: + - rust: nightly + env: FEATURES="" + - rust: beta + env: FEATURES="--features stable" + - rust: stable + env: FEATURES="--features stable" + - rust: nightly + env: FEATURES="--features stable" -script: cd test-project && cargo test $FEATURES +script: + - cargo test $FEATURES + - cd test-project && cargo test $FEATURES notifications: email: diff --git a/appveyor.yml b/appveyor.yml index 03c1229..4ae4332 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,6 +16,7 @@ build: false test_script: - if %CHANNEL%==stable (cargo build --features stable) else (cargo build) + - if %CHANNEL%==stable (cargo test --features stable) else (cargo test) - cd test-project && if %CHANNEL%==stable (cargo test --features stable) else (cargo test) branches: diff --git a/src/header.rs b/src/header.rs index d57d0c1..9d8727a 100644 --- a/src/header.rs +++ b/src/header.rs @@ -642,3 +642,29 @@ fn parse_normalization_string(line: &mut &str) -> Option { *line = &line[end+1..]; Some(result) } + +#[test] +fn test_parse_normalization_string() { + let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\"."; + let first = parse_normalization_string(&mut s); + assert_eq!(first, Some("something (32 bits)".to_owned())); + assert_eq!(s, " -> \"something ($WORD bits)\"."); + + // Nothing to normalize (No quotes) + let mut s = "normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."; + let first = parse_normalization_string(&mut s); + assert_eq!(first, None); + assert_eq!(s, r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."#); + + // Nothing to normalize (Only a single quote) + let mut s = "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits)."; + let first = parse_normalization_string(&mut s); + assert_eq!(first, None); + assert_eq!(s, "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits)."); + + // Nothing to normalize (Three quotes) + let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)."; + let first = parse_normalization_string(&mut s); + assert_eq!(first, Some("something (32 bits)".to_owned())); + assert_eq!(s, " -> \"something ($WORD bits)."); +} diff --git a/src/util.rs b/src/util.rs index c00f28e..37a395d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -64,6 +64,8 @@ pub fn matches_os(triple: &str, name: &str) -> bool { } panic!("Cannot determine OS from triple"); } + +/// Determine the architecture from `triple` pub fn get_arch(triple: &str) -> &'static str { for &(triple_arch, arch) in ARCH_TABLE { if triple.contains(triple_arch) { @@ -108,3 +110,29 @@ pub fn logv(config: &Config, s: String) { println!("{}", s); } } + +#[test] +#[should_panic(expected = "Cannot determine Architecture from triple")] +fn test_get_arch_failure() { + get_arch("abc"); +} + +#[test] +fn test_get_arch() { + assert_eq!("x86_64", get_arch("x86_64-unknown-linux-gnu")); + assert_eq!("x86_64", get_arch("amd64")); +} + +#[test] +#[should_panic(expected = "Cannot determine OS from triple")] +fn test_matches_os_failure() { + matches_os("abc", "abc"); +} + +#[test] +fn test_matches_os() { + assert!(matches_os("x86_64-unknown-linux-gnu", "linux")); + assert!(matches_os("wasm32-unknown-unknown", "emscripten")); + assert!(matches_os("wasm32-unknown-unknown", "wasm32-bare")); + assert!(!matches_os("wasm32-unknown-unknown", "windows")); +}