From 85e97d744cc1042dab922bbc095d8455d8399563 Mon Sep 17 00:00:00 2001 From: mgunyho <20118130+mgunyho@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:21:27 +0200 Subject: [PATCH] Add basic test of full raw escape codes output by program --- .gitattributes | 3 +++ tests/cli.rs | 35 +++++++++++++++++++++++++++++++++ tests/expected-output-basic.txt | 1 + 3 files changed, 39 insertions(+) create mode 100644 tests/expected-output-basic.txt diff --git a/.gitattributes b/.gitattributes index bd7b84c..505d232 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/tests/cli.rs b/tests/cli.rs index e92e98d..ab2898e 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -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(()) +} } diff --git a/tests/expected-output-basic.txt b/tests/expected-output-basic.txt new file mode 100644 index 0000000..1354d40 --- /dev/null +++ b/tests/expected-output-basic.txt @@ -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