Skip to content

Commit

Permalink
Consistent imports
Browse files Browse the repository at this point in the history
  • Loading branch information
allan2 committed Mar 15, 2024
1 parent bbb06cd commit 405689a
Show file tree
Hide file tree
Showing 26 changed files with 103 additions and 138 deletions.
2 changes: 1 addition & 1 deletion dotenv/examples/list_variables.rs
Expand Up @@ -4,7 +4,7 @@ fn main() -> Result<(), Error> {
dotenvy::dotenv()?;
for item in dotenv_iter()? {
let (key, val) = item?;
println!("{}={}", key, val);
println!("{key}={val}");
}
Ok(())
}
3 changes: 1 addition & 2 deletions dotenv/src/bin/dotenvy.rs
@@ -1,6 +1,5 @@
use clap::Arg;
use std::os::unix::process::CommandExt;
use std::process;
use std::{os::unix::process::CommandExt, process};

macro_rules! die {
($fmt:expr) => ({
Expand Down
7 changes: 4 additions & 3 deletions dotenv/src/find.rs
@@ -1,13 +1,14 @@
use crate::{
errors::{Error, Result},
iter::Iter,
};
use std::{
env,
fs::{self, File},
io,
path::{Path, PathBuf},
};

use crate::errors::{Error, Result};
use crate::iter::Iter;

pub struct Finder<'a> {
filename: &'a Path,
}
Expand Down
8 changes: 5 additions & 3 deletions dotenv/tests/common/mod.rs
@@ -1,6 +1,8 @@
use std::fs::File;
use std::io::prelude::*;
use std::{env, io};
use std::{
env,
fs::File,
io::{self, Write},
};
use tempfile::{tempdir, TempDir};

pub fn tempdir_with_dotenv(dotenv_text: &str) -> io::Result<TempDir> {
Expand Down
2 changes: 0 additions & 2 deletions dotenv/tests/integration/util/mod.rs
Expand Up @@ -4,8 +4,6 @@ mod testenv;

use std::env::{self, VarError};

pub use testenv::*;

/// Default key used in envfile
pub const TEST_KEY: &str = "TESTKEY";
/// Default value used in envfile
Expand Down
15 changes: 8 additions & 7 deletions dotenv/tests/integration/util/testenv.rs
@@ -1,13 +1,14 @@
use super::{create_default_envfile, TEST_EXISTING_KEY, TEST_EXISTING_VALUE};
use once_cell::sync::OnceCell;
use std::collections::HashMap;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, PoisonError};
use std::{env, fs, io};
use std::{
collections::HashMap,
env, fs,
io::{self, Write},
path::{Path, PathBuf},
sync::{Arc, Mutex, PoisonError},
};
use tempfile::{tempdir, TempDir};

use super::*;

/// Env var convenience type.
type EnvMap = HashMap<String, String>;

Expand Down
10 changes: 4 additions & 6 deletions dotenv/tests/test-child-dir.rs
@@ -1,19 +1,17 @@
mod common;

use dotenvy::*;
use std::{env, error::Error, fs, result::Result};

use crate::common::*;
use crate::common::make_test_dotenv;
use std::{env, error, fs};

#[test]
fn test_child_dir() -> Result<(), Box<dyn Error>> {
fn test_child_dir() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

fs::create_dir("child")?;

env::set_current_dir("child")?;

dotenv()?;
dotenvy::dotenv()?;
assert_eq!(env::var("TESTKEY")?, "test_val");

env::set_current_dir(dir.path().parent().unwrap())?;
Expand Down
11 changes: 4 additions & 7 deletions dotenv/tests/test-default-location-override.rs
@@ -1,16 +1,13 @@
mod common;

use std::{env, error::Error, result::Result};

use dotenvy::*;

use crate::common::*;
use crate::common::make_test_dotenv;
use std::{env, error};

#[test]
fn test_default_location_override() -> Result<(), Box<dyn Error>> {
fn test_default_location_override() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

dotenv_override()?;
dotenvy::dotenv_override()?;

assert_eq!(env::var("TESTKEY")?, "test_val_overridden");
assert_eq!(env::var("EXISTING")?, "from_file");
Expand Down
11 changes: 4 additions & 7 deletions dotenv/tests/test-default-location.rs
@@ -1,16 +1,13 @@
mod common;

use dotenvy::*;

use std::{env, error::Error, result::Result};

use crate::common::*;
use crate::common::make_test_dotenv;
use std::{env, error};

#[test]
fn test_default_location() -> Result<(), Box<dyn Error>> {
fn test_default_location() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

dotenv()?;
dotenvy::dotenv()?;

assert_eq!(env::var("TESTKEY")?, "test_val");
assert_eq!(env::var("EXISTING")?, "from_env");
Expand Down
10 changes: 4 additions & 6 deletions dotenv/tests/test-dotenv-iter.rs
@@ -1,15 +1,13 @@
mod common;

use dotenvy::*;
use std::{env, error::Error, result::Result};

use crate::common::*;
use crate::common::make_test_dotenv;
use std::{env, error};

#[test]
fn test_dotenv_iter() -> Result<(), Box<dyn Error>> {
fn test_dotenv_iter() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

let iter = dotenv_iter()?;
let iter = dotenvy::dotenv_iter()?;
assert!(env::var("TESTKEY").is_err());

iter.load()?;
Expand Down
10 changes: 4 additions & 6 deletions dotenv/tests/test-from-filename-iter.rs
@@ -1,15 +1,13 @@
mod common;

use dotenvy::*;
use std::{env, error::Error, result::Result};

use crate::common::*;
use crate::common::make_test_dotenv;
use std::{env, error};

#[test]
fn test_from_filename_iter() -> Result<(), Box<dyn Error>> {
fn test_from_filename_iter() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

let iter = from_filename_iter(".env")?;
let iter = dotenvy::from_filename_iter(".env")?;

assert!(env::var("TESTKEY").is_err());

Expand Down
10 changes: 4 additions & 6 deletions dotenv/tests/test-from-filename-override.rs
@@ -1,15 +1,13 @@
mod common;

use dotenvy::*;
use std::{env, error::Error, result::Result};

use crate::common::*;
use crate::common::make_test_dotenv;
use std::{env, error};

#[test]
fn test_from_filename_override() -> Result<(), Box<dyn Error>> {
fn test_from_filename_override() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

from_filename_override(".env")?;
dotenvy::from_filename_override(".env")?;

assert_eq!(env::var("TESTKEY")?, "test_val_overridden");
assert_eq!(env::var("EXISTING")?, "from_file");
Expand Down
9 changes: 4 additions & 5 deletions dotenv/tests/test-from-filename.rs
@@ -1,12 +1,11 @@
mod common;

use dotenvy::*;
use std::{env, error::Error, result::Result};

use crate::common::*;
use crate::common::make_test_dotenv;
use dotenvy::from_filename;
use std::{env, error};

#[test]
fn test_from_filename() -> Result<(), Box<dyn Error>> {
fn test_from_filename() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

from_filename(".env")?;
Expand Down
9 changes: 4 additions & 5 deletions dotenv/tests/test-from-path-iter.rs
@@ -1,12 +1,11 @@
mod common;

use dotenvy::*;
use std::{env, error::Error, result::Result};

use crate::common::*;
use crate::common::make_test_dotenv;
use dotenvy::from_path_iter;
use std::{env, error};

#[test]
fn test_from_path_iter() -> Result<(), Box<dyn Error>> {
fn test_from_path_iter() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

let mut path = env::current_dir()?;
Expand Down
10 changes: 6 additions & 4 deletions dotenv/tests/test-from-path-override.rs
@@ -1,11 +1,13 @@
mod common;

use crate::common::*;
use dotenvy::*;
use std::{env, error::Error, result::Result};
use std::{env, error};

use dotenvy::from_path_override;

use crate::common::make_test_dotenv;

#[test]
fn test_from_path_override() -> Result<(), Box<dyn Error>> {
fn test_from_path_override() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

let mut path = env::current_dir()?;
Expand Down
9 changes: 4 additions & 5 deletions dotenv/tests/test-from-path.rs
@@ -1,17 +1,16 @@
mod common;

use crate::common::*;
use dotenvy::*;
use std::{env, error::Error, result::Result};
use crate::common::make_test_dotenv;
use std::{env, error};

#[test]
fn test_from_path() -> Result<(), Box<dyn Error>> {
fn test_from_path() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

let mut path = env::current_dir()?;
path.push(".env");

from_path(&path)?;
dotenvy::from_path(&path)?;

assert_eq!(env::var("TESTKEY")?, "test_val");
assert_eq!(env::var("EXISTING")?, "from_env");
Expand Down
10 changes: 4 additions & 6 deletions dotenv/tests/test-from-read-override.rs
@@ -1,15 +1,13 @@
mod common;

use dotenvy::*;
use std::{env, error::Error, fs::File, result::Result};

use crate::common::*;
use crate::common::make_test_dotenv;
use std::{env, error, fs::File};

#[test]
fn test_from_read_override() -> Result<(), Box<dyn Error>> {
fn test_from_read_override() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

from_read_override(File::open(".env")?)?;
dotenvy::from_read_override(File::open(".env")?)?;

assert_eq!(env::var("TESTKEY")?, "test_val_overridden");
assert_eq!(env::var("EXISTING")?, "from_file");
Expand Down
10 changes: 4 additions & 6 deletions dotenv/tests/test-from-read.rs
@@ -1,15 +1,13 @@
mod common;

use dotenvy::*;
use std::{env, error::Error, fs::File, result::Result};

use crate::common::*;
use crate::common::make_test_dotenv;
use std::{env, error, fs::File};

#[test]
fn test_from_read() -> Result<(), Box<dyn Error>> {
fn test_from_read() -> Result<(), Box<dyn error::Error>> {
let dir = make_test_dotenv()?;

from_read(File::open(".env")?)?;
dotenvy::from_read(File::open(".env")?)?;

assert_eq!(env::var("TESTKEY")?, "test_val");
assert_eq!(env::var("EXISTING")?, "from_env");
Expand Down
9 changes: 4 additions & 5 deletions dotenv/tests/test-ignore-bom.rs
@@ -1,18 +1,17 @@
mod common;

use crate::common::*;
use dotenvy::*;
use std::{env, error::Error, result::Result};
use crate::common::tempdir_with_dotenv;
use std::{env, error};

#[test]
fn test_ignore_bom() -> Result<(), Box<dyn Error>> {
fn test_ignore_bom() -> Result<(), Box<dyn error::Error>> {
let bom = "\u{feff}";
let dir = tempdir_with_dotenv(&format!("{}TESTKEY=test_val", bom))?;

let mut path = env::current_dir()?;
path.push(".env");

from_path(&path)?;
dotenvy::from_path(&path)?;

assert_eq!(env::var("TESTKEY")?, "test_val");

Expand Down
3 changes: 1 addition & 2 deletions dotenv/tests/test-multiline-comment.rs
Expand Up @@ -2,7 +2,6 @@ mod common;
use std::env;

use common::tempdir_with_dotenv;
use dotenvy::dotenv;

#[test]
fn test_issue_12() {
Expand All @@ -27,7 +26,7 @@ Line 6
)
.expect("should write test env");

dotenv().expect("should succeed");
dotenvy::dotenv().expect("should succeed");
assert_eq!(
env::var("TESTKEY1").expect("testkey1 env key not set"),
"test_val"
Expand Down

0 comments on commit 405689a

Please sign in to comment.