summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Nordholts <enselic@gmail.com>2021-02-28 16:56:16 +0100
committerDavid Peter <sharkdp@users.noreply.github.com>2021-02-28 18:09:44 +0100
commit3af35492320077b2abf7cc70117ea02aa24389a3 (patch)
treebb52cf4ae39d689d2e9c417fe23dd13a4496d2b4
parent643f0bcbe387f5e15a3c97bff5b12f9dc10285a6 (diff)
integration_tests: Use tempdir() in config_location_when_generating
For cleaner code. Use the tempdir() function since that is recommended by the crate docs: https://docs.rs/tempfile/3.2.0/tempfile/index.html
-rw-r--r--tests/integration_tests.rs21
1 files changed, 8 insertions, 13 deletions
diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs
index 4047d5c8..de673784 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -6,6 +6,7 @@ use std::fs::File;
use std::path::Path;
use std::process::{Command, Stdio};
use std::str::from_utf8;
+use tempfile::tempdir;
#[cfg(unix)]
use std::time::Duration;
@@ -663,12 +664,8 @@ fn config_location_test() {
#[test]
fn config_location_when_generating() {
- let tmp_config_path = std::path::PathBuf::from("/tmp/should-be-created.conf");
-
- // Make sure the file does not exist before the test is run
- // If this fails, run the following before running tests:
- // rm /tmp/should-be-created.conf
- assert!(!tmp_config_path.exists());
+ let tmp_dir = tempdir().expect("can create temporary directory");
+ let tmp_config_path = tmp_dir.path().join("should-be-created.conf");
// Create the file with bat
bat_with_config()
@@ -676,13 +673,13 @@ fn config_location_when_generating() {
.arg("--generate-config-file")
.assert()
.success()
- .stdout("Success! Config file written to /tmp/should-be-created.conf\n");
+ .stdout(
+ predicate::str::is_match("Success! Config file written to .*should-be-created.conf\n")
+ .unwrap(),
+ );
// Now we expect the file to exist. If it exists, we assume contents are correct
assert!(tmp_config_path.exists());
-
- // Cleanup
- std::fs::remove_file(tmp_config_path).unwrap();
}
#[test]
@@ -977,9 +974,7 @@ fn file_with_invalid_utf8_filename() {
use std::io::Write;
use std::os::unix::ffi::OsStrExt;
- use tempfile::TempDir;
-
- let tmp_dir = TempDir::new().expect("can create temporary directory");
+ let tmp_dir = tempdir().expect("can create temporary directory");
let file_path = tmp_dir
.path()
.join(OsStr::from_bytes(b"test-invalid-utf8-\xC3(.rs"));