Skip to content

Commit

Permalink
Merge pull request #1120 from chbaker0/main
Browse files Browse the repository at this point in the history
Replace lingering tempdir usages with tempfile
  • Loading branch information
adetaylor authored Jun 7, 2022
2 parents f945331 + 79afb97 commit 4cb1da8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 70 deletions.
56 changes: 1 addition & 55 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 gen/cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ indexmap = "1.8"

[dev-dependencies]
assert_cmd = "1.0.3"
tempdir = "0.3.7"
tempfile = "3.1"
autocxx-integration-tests = { path = "../../integration-tests", version="=0.22.1" }
# This is necessary for building the projects created
# by the trybuild test system...
Expand Down
6 changes: 3 additions & 3 deletions gen/cmd/src/depfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ impl Depfile {
mod tests {
use std::{fs::File, io::Read};

use tempdir::TempDir;
use tempfile::tempdir;

use super::Depfile;

#[test]
fn test_simple_depfile() {
let tmp_dir = TempDir::new("depfile-test").unwrap();
let tmp_dir = tempdir().unwrap();
let f = tmp_dir.path().join("depfile.d");
let mut df = Depfile::new(&f).unwrap();
df.add_output(&tmp_dir.path().join("a/b"));
Expand All @@ -85,7 +85,7 @@ mod tests {

#[test]
fn test_multiple_outputs() {
let tmp_dir = TempDir::new("depfile-test").unwrap();
let tmp_dir = tempdir().unwrap();
let f = tmp_dir.path().join("depfile.d");
let mut df = Depfile::new(&f).unwrap();
df.add_output(&tmp_dir.path().join("a/b"));
Expand Down
16 changes: 8 additions & 8 deletions gen/cmd/tests/cmd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use indexmap::map::IndexMap as HashMap;
use assert_cmd::Command;
use autocxx_integration_tests::{build_from_folder, RsFindMode};
use itertools::Itertools;
use tempdir::TempDir;
use tempfile::{tempdir, TempDir};

static MAIN_RS: &str = concat!(
include_str!("../../../demo/src/main.rs"),
Expand Down Expand Up @@ -107,7 +107,7 @@ where

#[test]
fn test_gen() -> Result<(), Box<dyn std::error::Error>> {
let tmp_dir = TempDir::new("example")?;
let tmp_dir = tempdir()?;
base_test(&tmp_dir, RsGenMode::Single, |_| {})?;
File::create(tmp_dir.path().join("cxx.h"))
.and_then(|mut cxx_h| cxx_h.write_all(autocxx_engine::HEADER.as_bytes()))?;
Expand All @@ -128,7 +128,7 @@ fn test_gen() -> Result<(), Box<dyn std::error::Error>> {

#[test]
fn test_gen_archive() -> Result<(), Box<dyn std::error::Error>> {
let tmp_dir = TempDir::new("example")?;
let tmp_dir = tempdir()?;
base_test(&tmp_dir, RsGenMode::Archive, |_| {})?;
File::create(tmp_dir.path().join("cxx.h"))
.and_then(|mut cxx_h| cxx_h.write_all(autocxx_engine::HEADER.as_bytes()))?;
Expand All @@ -148,7 +148,7 @@ fn test_gen_archive() -> Result<(), Box<dyn std::error::Error>> {

#[test]
fn test_gen_multiple_in_archive() -> Result<(), Box<dyn std::error::Error>> {
let tmp_dir = TempDir::new("example")?;
let tmp_dir = tempdir()?;

let mut files = HashMap::new();
files.insert("input2.h", INPUT2_H.as_bytes());
Expand Down Expand Up @@ -186,7 +186,7 @@ fn test_gen_multiple_in_archive() -> Result<(), Box<dyn std::error::Error>> {

#[test]
fn test_include_prefixes() -> Result<(), Box<dyn std::error::Error>> {
let tmp_dir = TempDir::new("example")?;
let tmp_dir = tempdir()?;
base_test(&tmp_dir, RsGenMode::Single, |cmd| {
cmd.arg("--cxx-h-path")
.arg("foo/")
Expand All @@ -204,7 +204,7 @@ fn test_include_prefixes() -> Result<(), Box<dyn std::error::Error>> {

#[test]
fn test_gen_fixed_num() -> Result<(), Box<dyn std::error::Error>> {
let tmp_dir = TempDir::new("example")?;
let tmp_dir = tempdir()?;
let depfile = tmp_dir.path().join("test.d");
base_test(&tmp_dir, RsGenMode::Single, |cmd| {
cmd.arg("--generate-exact")
Expand Down Expand Up @@ -239,7 +239,7 @@ fn test_gen_fixed_num() -> Result<(), Box<dyn std::error::Error>> {

#[test]
fn test_gen_preprocess() -> Result<(), Box<dyn std::error::Error>> {
let tmp_dir = TempDir::new("example")?;
let tmp_dir = tempdir()?;
let prepro_path = tmp_dir.path().join("preprocessed.h");
base_test(&tmp_dir, RsGenMode::Single, |cmd| {
cmd.env("AUTOCXX_PREPROCESS", prepro_path.to_str().unwrap());
Expand All @@ -253,7 +253,7 @@ fn test_gen_preprocess() -> Result<(), Box<dyn std::error::Error>> {

#[test]
fn test_gen_repro() -> Result<(), Box<dyn std::error::Error>> {
let tmp_dir = TempDir::new("example")?;
let tmp_dir = tempdir()?;
let repro_path = tmp_dir.path().join("repro.json");
base_test(&tmp_dir, RsGenMode::Single, |cmd| {
cmd.env("AUTOCXX_REPRO_CASE", repro_path.to_str().unwrap());
Expand Down
2 changes: 1 addition & 1 deletion tools/reduce/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ indexmap = "1.8"

[dev-dependencies]
assert_cmd = "1.0.3"
tempdir = "0.3.7"
tempfile = "3.1"
indoc = "1.0"
proc-macro2 = "1.0"
4 changes: 2 additions & 2 deletions tools/reduce/tests/reduce_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
path::{Path, PathBuf},
};
use syn::Token;
use tempdir::TempDir;
use tempfile::tempdir;

static INPUT_H: &str = indoc::indoc! {"
inline int DoMath(int a) {
Expand Down Expand Up @@ -169,7 +169,7 @@ where
if creduce_is_broken() {
return Ok(());
}
let tmp_dir = TempDir::new("example")?;
let tmp_dir = tempdir()?;
let demo_code_dir = tmp_dir.path().join("demo");
std::fs::create_dir(&demo_code_dir).unwrap();
let input_header = if include_cxx_h {
Expand Down

0 comments on commit 4cb1da8

Please sign in to comment.