Merge pull request #153 from LnL7/nix-test-ansi

fix tests with nix 2.0
This commit is contained in:
Graham Christensen 2018-04-10 19:01:53 -04:00 committed by GitHub
commit bfa6af6929
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 11 deletions

View file

@ -304,6 +304,14 @@ mod tests {
return cwd; return cwd;
} }
fn strip_ansi(string: &str) -> String {
string
.replace("", "'")
.replace("", "'")
.replace("\u{1b}[31;1m", "") // red
.replace("\u{1b}[0m", "") // reset
}
#[derive(Debug)] #[derive(Debug)]
enum Expect { enum Expect {
Pass, Pass,
@ -325,7 +333,7 @@ mod tests {
let buildlog = lines let buildlog = lines
.into_iter() .into_iter()
.map(|line| line.replace("\u{1b}[0m", "")) // ANSI reset .map(|line| strip_ansi(&line))
.map(|line| format!(" | {}", line)) .map(|line| format!(" | {}", line))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("\n"); .join("\n");
@ -588,10 +596,10 @@ mod tests {
assert_eq!(ret.0, vec!["passes-instantiation"]); assert_eq!(ret.0, vec!["passes-instantiation"]);
assert_eq!(ret.1[0].0, "fails-instantiation"); assert_eq!(ret.1[0].0, "fails-instantiation");
assert_eq!(ret.1[0].1[0], "trace: You just can\'t frooble the frozz on this particular system."); assert_eq!(ret.1[0].1[0], "trace: You just can't frooble the frozz on this particular system.");
assert_eq!(ret.1[1].0, "missing-attr"); assert_eq!(ret.1[1].0, "missing-attr");
assert_eq!(ret.1[1].1[0], "error: attribute missing-attr in selection path missing-attr not found"); assert_eq!(strip_ansi(&ret.1[1].1[0]), "error: attribute 'missing-attr' in selection path 'missing-attr' not found");
} }
#[test] #[test]

View file

@ -397,7 +397,6 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker {
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -442,17 +441,26 @@ mod tests {
return hash.trim().to_owned(); return hash.trim().to_owned();
} }
fn strip_escaped_ansi(string: &str) -> String {
string
.replace("", "'")
.replace("", "'")
.replace("\\u001b[31;1m", "") // red
.replace("\\u001b[0m", "") // reset
}
fn assert_contains_job(actions: &mut IntoIter<worker::Action>, text_to_match: &str) { fn assert_contains_job(actions: &mut IntoIter<worker::Action>, text_to_match: &str) {
println!("\n\nSearching for {:?}", text_to_match); println!("\n\n Searching: {:?}", text_to_match);
actions actions
.position(|job| match job { .position(|job| match job {
worker::Action::Publish(ref body) => { worker::Action::Publish(ref body) => {
let mystr = String::from_utf8(body.content.clone()).unwrap(); let content = String::from_utf8(body.content.clone()).unwrap();
if mystr.contains(text_to_match) { let text = strip_escaped_ansi(&content);
println!(" Matched: {:?}", mystr); if text.contains(text_to_match) {
println!(" ok");
return true; return true;
} else { } else {
println!(" miss: {:?}", mystr); println!(" notContains: {:?}", text);
return false; return false;
} }
} }
@ -554,7 +562,7 @@ mod tests {
println!("Total actions: {:?}", dummyreceiver.actions.len()); println!("Total actions: {:?}", dummyreceiver.actions.len());
let mut actions = dummyreceiver.actions.into_iter(); let mut actions = dummyreceiver.actions.into_iter();
assert_contains_job(&mut actions, "\"line_number\":1,\"output\":\"Cannot nix-instantiate `not-real\' because:\""); assert_contains_job(&mut actions, "\"line_number\":1,\"output\":\"Cannot nix-instantiate `not-real\' because:\"");
assert_contains_job(&mut actions, "\"line_number\":2,\"output\":\"error: attribute not-real in selection path not-real not found\"}"); assert_contains_job(&mut actions, "\"line_number\":2,\"output\":\"error: attribute 'not-real' in selection path 'not-real' not found\"}");
assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // First one to the github poster assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // First one to the github poster
assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // This one to the logs assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // This one to the logs
assert_eq!(actions.next(), Some(worker::Action::Ack)); assert_eq!(actions.next(), Some(worker::Action::Ack));