mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-12 08:38:18 +01:00
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
This commit is contained in:
parent
643f0bcbe3
commit
3af3549232
@ -6,6 +6,7 @@ use std::fs::File;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
|
use tempfile::tempdir;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -663,12 +664,8 @@ fn config_location_test() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn config_location_when_generating() {
|
fn config_location_when_generating() {
|
||||||
let tmp_config_path = std::path::PathBuf::from("/tmp/should-be-created.conf");
|
let tmp_dir = tempdir().expect("can create temporary directory");
|
||||||
|
let tmp_config_path = tmp_dir.path().join("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());
|
|
||||||
|
|
||||||
// Create the file with bat
|
// Create the file with bat
|
||||||
bat_with_config()
|
bat_with_config()
|
||||||
@ -676,13 +673,13 @@ fn config_location_when_generating() {
|
|||||||
.arg("--generate-config-file")
|
.arg("--generate-config-file")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.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
|
// Now we expect the file to exist. If it exists, we assume contents are correct
|
||||||
assert!(tmp_config_path.exists());
|
assert!(tmp_config_path.exists());
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
std::fs::remove_file(tmp_config_path).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -977,9 +974,7 @@ fn file_with_invalid_utf8_filename() {
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
|
||||||
use tempfile::TempDir;
|
let tmp_dir = tempdir().expect("can create temporary directory");
|
||||||
|
|
||||||
let tmp_dir = TempDir::new().expect("can create temporary directory");
|
|
||||||
let file_path = tmp_dir
|
let file_path = tmp_dir
|
||||||
.path()
|
.path()
|
||||||
.join(OsStr::from_bytes(b"test-invalid-utf8-\xC3(.rs"));
|
.join(OsStr::from_bytes(b"test-invalid-utf8-\xC3(.rs"));
|
||||||
|
Loading…
Reference in New Issue
Block a user