Skip to content

Commit

Permalink
Migrate from tempdir (deprecated) to tempfile
Browse files Browse the repository at this point in the history
  • Loading branch information
crisidev committed Jan 21, 2025
1 parent c64cc42 commit f5c495e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 90 deletions.
136 changes: 56 additions & 80 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ tracing-subscriber = { version = "0.3.19", default-features = false, features =

[dev-dependencies]
pretty_assertions = "1.4.1"
tempdir = "0.3.7"
tempfile = "3.15.0"
12 changes: 6 additions & 6 deletions src/bacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ mod tests {
use std::io::Write;

use super::*;
use tempdir::TempDir;
use tempfile::TempDir;

#[tokio::test]
async fn test_valid_bacon_preferences() {
Expand All @@ -213,7 +213,7 @@ mod tests {
path = "{LOCATIONS_FILE}"
"#
);
let tmp_dir = TempDir::new("bacon").unwrap();
let tmp_dir = TempDir::new().unwrap();
let file_path = tmp_dir.path().join("prefs.toml");
let mut file = std::fs::File::create(&file_path).unwrap();
write!(file, "{}", valid_toml).unwrap();
Expand All @@ -236,7 +236,7 @@ mod tests {
"#
);

let tmp_dir = TempDir::new("bacon").unwrap();
let tmp_dir = TempDir::new().unwrap();
let file_path = tmp_dir.path().join("prefs.toml");
let mut file = std::fs::File::create(&file_path).unwrap();
write!(file, "{}", invalid_toml).unwrap();
Expand All @@ -259,7 +259,7 @@ mod tests {
"#
);

let tmp_dir = TempDir::new("bacon").unwrap();
let tmp_dir = TempDir::new().unwrap();
let file_path = tmp_dir.path().join("prefs.toml");
let mut file = std::fs::File::create(&file_path).unwrap();
write!(file, "{}", invalid_toml).unwrap();
Expand Down Expand Up @@ -300,7 +300,7 @@ mod tests {

#[tokio::test]
async fn test_file_write_failure() {
let tmp_dir = TempDir::new("bacon").unwrap();
let tmp_dir = TempDir::new().unwrap();
let file_path = tmp_dir.path().join("prefs.toml");
// Simulate write failure by closing the file prematurely
let file = File::create(&file_path).await.unwrap();
Expand All @@ -311,7 +311,7 @@ mod tests {

#[tokio::test]
async fn test_empty_bacon_preferences_file() {
let tmp_dir = TempDir::new("bacon").unwrap();
let tmp_dir = TempDir::new().unwrap();
let file_path = tmp_dir.path().join("empty_prefs.toml");
std::fs::File::create(&file_path).unwrap();
assert!(Bacon::validate_preferences_file(&file_path).await.is_err());
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ mod tests {

use super::*;
use pretty_assertions::assert_eq;
use tempdir::TempDir;
use tempfile::TempDir;

const ERROR_LINE: &str = "error|:|/app/github/bacon-ls/src/lib.rs|:|352|:|352|:|9|:|20|:|cannot find value `one` in this scope\n |\n352 | one\n | ^^^ help: a unit variant with a similar name exists: `None`\n |\n ::: /Users/matteobigoi/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:576:5\n |\n576 | None,\n | ---- similarly named unit variant `None` defined here\n\nFor more information about this error, try `rustc --explain E0425`.\nerror: could not compile `bacon-ls` (lib) due to 1 previous error|:|none";

Expand Down Expand Up @@ -433,7 +433,7 @@ error: could not compile `bacon-ls` (lib) due to 1 previous error"#
#[cfg(not(target_os = "windows"))]
#[tokio::test]
async fn test_multiline_diagnostics_production() {
let tmp_dir = TempDir::new("bacon-ls").unwrap();
let tmp_dir = TempDir::new().unwrap();
let file_path = tmp_dir.path().join(".bacon-locations");
let mut tmp_file = std::fs::File::create(file_path).unwrap();
let error_path = format!("{}/src/lib.rs", tmp_dir.path().display());
Expand Down Expand Up @@ -505,7 +505,7 @@ error: could not compile `bacon-ls` (lib) due to 1 previous error"#
#[cfg(not(target_os = "windows"))]
#[tokio::test]
async fn test_diagnostics_production_and_deduplication() {
let tmp_dir = TempDir::new("bacon-ls").unwrap();
let tmp_dir = TempDir::new().unwrap();
let file_path = tmp_dir.path().join(".bacon-locations");
let mut tmp_file = std::fs::File::create(file_path).unwrap();
let error_path = format!("{}/src/lib.rs", tmp_dir.path().display());
Expand Down

0 comments on commit f5c495e

Please sign in to comment.