Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/mft.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmer Ben-Amram <omerbenamram@gmail.com>2020-01-06 22:36:30 +0300
committerOmer Ben-Amram <omerbenamram@gmail.com>2020-01-06 22:36:30 +0300
commit2df0d10f21a0f283772dd73711b4be712c1da2f9 (patch)
treeceeaf4d603c04c5a0c24c8863f17d29895e79a2f
parent517061677ab30b2417e72c6eb988cd46dbe133b2 (diff)
entire non-windows test is now a module
-rw-r--r--tests/test_cli_interactive.rs141
1 files changed, 74 insertions, 67 deletions
diff --git a/tests/test_cli_interactive.rs b/tests/test_cli_interactive.rs
index 2366454..f2655f2 100644
--- a/tests/test_cli_interactive.rs
+++ b/tests/test_cli_interactive.rs
@@ -5,71 +5,78 @@
mod fixtures;
#[cfg(not(target_os = "windows"))]
-use rexpect::spawn;
-
-// It should behave the same on windows, but interactive testing relies on unix pty internals.
-#[test]
-#[cfg(not(target_os = "windows"))]
-fn test_it_confirms_before_overwriting_a_file() {
- let d = tempdir().unwrap();
- let f = d.as_ref().join("test.out");
-
- let mut file = File::create(&f).unwrap();
- file.write_all(b"I'm a file!").unwrap();
-
- let sample = mft_sample();
-
- let cmd_string = format!(
- "{bin} -f {output_file} {sample}",
- bin = cargo_bin("mft_dump").display(),
- output_file = f.to_string_lossy(),
- sample = sample.to_str().unwrap()
- );
-
- let mut p = spawn(&cmd_string, Some(20000)).unwrap();
- p.exp_regex(r#"Are you sure you want to override.*"#)
- .unwrap();
- p.send_line("y").unwrap();
- p.exp_eof().unwrap();
-
- let mut expected = vec![];
-
- File::open(&f).unwrap().read_to_end(&mut expected).unwrap();
- assert!(
- !expected.len() > 100,
- "Expected output to be printed to file"
- )
-}
-
-#[test]
-#[cfg(not(target_os = "windows"))]
-fn test_it_confirms_before_overwriting_a_file_and_quits() {
- let d = tempdir().unwrap();
- let f = d.as_ref().join("test.out");
-
- let mut file = File::create(&f).unwrap();
- file.write_all(b"I'm a file!").unwrap();
-
- let sample = mft_sample();
-
- let cmd_string = format!(
- "{bin} -f {output_file} {sample}",
- bin = cargo_bin("mft_dump").display(),
- output_file = f.to_string_lossy(),
- sample = sample.to_str().unwrap()
- );
-
- let mut p = spawn(&cmd_string, Some(20000)).unwrap();
- p.exp_regex(r#"Are you sure you want to override.*"#)
- .unwrap();
- p.send_line("n").unwrap();
- p.exp_eof().unwrap();
-
- let mut expected = vec![];
-
- File::open(&f).unwrap().read_to_end(&mut expected).unwrap();
- assert!(
- !expected.len() > 100,
- "Expected output to be printed to file"
- )
+mod tests {
+ use fixtures::*;
+
+ use std::fs::File;
+ use std::io::{Read, Write};
+ use tempfile::tempdir;
+
+ use assert_cmd::cargo::cargo_bin;
+ use rexpect::spawn;
+
+ // It should behave the same on windows, but interactive testing relies on unix pty internals.
+ #[test]
+ fn test_it_confirms_before_overwriting_a_file() {
+ let d = tempdir().unwrap();
+ let f = d.as_ref().join("test.out");
+
+ let mut file = File::create(&f).unwrap();
+ file.write_all(b"I'm a file!").unwrap();
+
+ let sample = mft_sample();
+
+ let cmd_string = format!(
+ "{bin} -f {output_file} {sample}",
+ bin = cargo_bin("mft_dump").display(),
+ output_file = f.to_string_lossy(),
+ sample = sample.to_str().unwrap()
+ );
+
+ let mut p = spawn(&cmd_string, Some(20000)).unwrap();
+ p.exp_regex(r#"Are you sure you want to override.*"#)
+ .unwrap();
+ p.send_line("y").unwrap();
+ p.exp_eof().unwrap();
+
+ let mut expected = vec![];
+
+ File::open(&f).unwrap().read_to_end(&mut expected).unwrap();
+ assert!(
+ !expected.len() > 100,
+ "Expected output to be printed to file"
+ )
+ }
+
+ #[test]
+ fn test_it_confirms_before_overwriting_a_file_and_quits() {
+ let d = tempdir().unwrap();
+ let f = d.as_ref().join("test.out");
+
+ let mut file = File::create(&f).unwrap();
+ file.write_all(b"I'm a file!").unwrap();
+
+ let sample = mft_sample();
+
+ let cmd_string = format!(
+ "{bin} -f {output_file} {sample}",
+ bin = cargo_bin("mft_dump").display(),
+ output_file = f.to_string_lossy(),
+ sample = sample.to_str().unwrap()
+ );
+
+ let mut p = spawn(&cmd_string, Some(20000)).unwrap();
+ p.exp_regex(r#"Are you sure you want to override.*"#)
+ .unwrap();
+ p.send_line("n").unwrap();
+ p.exp_eof().unwrap();
+
+ let mut expected = vec![];
+
+ File::open(&f).unwrap().read_to_end(&mut expected).unwrap();
+ assert!(
+ !expected.len() > 100,
+ "Expected output to be printed to file"
+ )
+ }
}