]> git.proxmox.com Git - pmg-log-tracker.git/blame - tests/utils.rs
debcargo: fix maintainer directive
[pmg-log-tracker.git] / tests / utils.rs
CommitLineData
aee1def7
ML
1use std::io::BufRead;
2
abd7fe2d
FG
3use std::env;
4use std::path::PathBuf;
5
6fn get_target_dir() -> PathBuf {
7 let bin = env::current_exe().expect("exe path");
8 let mut target_dir = PathBuf::from(bin.parent().expect("bin parent"));
9 target_dir.pop();
10 target_dir
11}
12
13pub fn log_tracker_path() -> String {
14 let mut target_dir = get_target_dir();
15 target_dir.push("pmg-log-tracker");
16 target_dir.to_str().unwrap().to_string()
17}
18
aee1def7
ML
19pub fn compare_output<R: BufRead, R2: BufRead>(command: R, expected: R2) {
20 let expected_lines: Vec<String> = expected.lines().map(|l| l.unwrap()).collect();
21 let command_lines: Vec<String> = command.lines().map(|l| l.unwrap()).collect();
22 assert_eq!(
23 expected_lines.len(),
24 command_lines.len(),
25 "expected: {}, command: {}",
26 expected_lines.len(),
27 command_lines.len()
28 );
77b430e0 29 for (old, new) in expected_lines.iter().zip(command_lines.iter()) {
aee1def7
ML
30 if new.starts_with("# ") && old.starts_with("# ") {
31 continue;
32 } else if new.starts_with("# ") {
33 assert!(
34 false,
35 "comment line found in command output, but not in expected output"
36 );
37 } else if old.starts_with("# ") {
38 assert!(
39 false,
40 "comment line found in expected output, but not in command output"
41 );
42 }
43
44 assert_eq!(new, old);
45 }
46}