Skip to content

Commit d26a940

Browse files
Hyasknadzyah
authored andcommitted
tests: fix this too opinionated test suite to work on my machine
Before those fixes, running the test suite resulted in the following errors: ``` running 9 tests test tests::test_can_tail_file_with_directory ... ok test tests::test_can_tail_file_with_nonexistent_file ... FAILED test tests::test_can_tail_file_with_existing_file ... ok test tests::test_can_tail_file_with_unreadable_file ... ok test tests::test_run_command_nonexistent_command ... ok test tests::test_run_command_success ... ok test tests::test_run_command_with_args ... ok test tests::test_main_fails_without_fallback_command ... FAILED test tests::test_run_command_calling_tailor_again ... ok failures: ---- tests::test_can_tail_file_with_nonexistent_file stdout ---- thread 'tests::test_can_tail_file_with_nonexistent_file' panicked at src/main.rs:114:9: Should not be able to tail a nonexistent file note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ---- tests::test_main_fails_without_fallback_command stdout ---- thread 'tests::test_main_fails_without_fallback_command' panicked at /home/skia/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5: Unexpected success command=`"/home/skia/workspace/ubuntu/tailor/target/debug/tailor" "/tmp/nonexistent_file_12345"` code=0 stdout="" stderr="" failures: tests::test_can_tail_file_with_nonexistent_file tests::test_main_fails_without_fallback_command test result: FAILED. 7 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s ``` I believe this is because the test suite is too opinionated, and relies on an arbitrary file not existing. I happened to use that important file in my personal workflow, hence the test suite broke. Thankfully, I'm a nice contributor and was able to use my skills to fix this. It now passes on my machine. Thank you.
1 parent 8761b7a commit d26a940

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ mod tests {
110110

111111
#[test]
112112
fn test_can_tail_file_with_nonexistent_file() {
113-
let result = can_tail_file("/tmp/nonexistent_file_12345").unwrap();
113+
let temp_file = NamedTempFile::new().unwrap();
114+
let file_path = temp_file.path().to_str().unwrap();
115+
std::fs::remove_file(file_path).unwrap();
116+
let result = can_tail_file(file_path).unwrap();
114117
assert!(!result, "Should not be able to tail a nonexistent file");
115118
}
116119

@@ -212,8 +215,11 @@ mod tests {
212215

213216
#[test]
214217
fn test_main_fails_without_fallback_command() {
218+
let temp_file = NamedTempFile::new().unwrap();
219+
let file_path = temp_file.path().to_str().unwrap();
220+
std::fs::remove_file(file_path).unwrap();
215221
let mut cmd = Command::cargo_bin("tailor").unwrap();
216-
cmd.arg("/tmp/nonexistent_file_12345")
222+
cmd.arg(file_path)
217223
.assert()
218224
.failure()
219225
.stderr(contains("no fallback command"));

0 commit comments

Comments
 (0)