Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some unit tests (rustc copy) #152

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,29 @@ fn parse_normalization_string(line: &mut &str) -> Option<String> {
*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).");
}
28 changes: 28 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"));
}