Skip to content

Commit

Permalink
Add basic test of full raw escape codes output by program
Browse files Browse the repository at this point in the history
  • Loading branch information
mgunyho committed Sep 15, 2024
1 parent 082644e commit 85e97d7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
# CRLF and LF).

README.md text eol=lf

# This is raw output from the program, don't do any conversions on it
tests/expected-output-basic.txt -text
35 changes: 35 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,39 @@ fn skip_first_run_prompt() -> Result<(), RexpectError> {

Ok(())
}

#[test]
fn minimum_escape_codes() -> Result<(), RexpectError> {
// The app should ouptut the minimum amount of escape codes, and not any redundant ones

let mut cmd = get_cmd_no_first_run_prompt();
let tmp = tempdir().expect("error creating temporary folder");

// create some folders
for folder_name in vec!["foo", "bar"] {
let p = tmp.path().join(folder_name);
std::fs::create_dir(p).unwrap();
}

cmd.current_dir(tmp.path())
// note: have to set PWD for this to work...
.env("PWD", tmp.path().as_os_str());

let mut proc = run_app_with_cmd(cmd);
// 0x1b == 0o33 == 27 escape
proc.send("\x1b")?;
proc.writer.flush()?;

let output = proc.exp_eof()?;
let expected_output = include_str!("expected-output-basic.txt");

let tmp_path_str = format!("{}", tmp.path().display());
// The path of the temporary folder will vary, but everything else should be the same as in the
// example output
assert_eq!(
output.replace(&tmp_path_str, "/tmp/xxxxxxxxxx"),
expected_output,
);
Ok(())
}
}
1 change: 1 addition & 0 deletions tests/expected-output-basic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[?25l/tmp/xxxxxxxxxx/tmp/xxxxxxxxxxtere 1.5.1 - Type something to search, press '?' to view help or Esc to exit.gap search from start - smart case - sort:name - 2 / 3search: ..bar foo[?25h[?1049l/tmp/xxxxxxxxxx

0 comments on commit 85e97d7

Please sign in to comment.