diff --git a/dotenv/tests/test-child-dir.rs b/dotenv/tests/test-child-dir.rs index 1db61e8d..1deddb8d 100644 --- a/dotenv/tests/test-child-dir.rs +++ b/dotenv/tests/test-child-dir.rs @@ -1,21 +1,22 @@ mod common; use dotenvy::*; -use std::{env, fs}; +use std::{env, error::Error, fs, result::Result}; use crate::common::*; #[test] -fn test_child_dir() { - let dir = make_test_dotenv().unwrap(); +fn test_child_dir() -> Result<(), Box> { + let dir = make_test_dotenv()?; - fs::create_dir("child").unwrap(); + fs::create_dir("child")?; - env::set_current_dir("child").unwrap(); + env::set_current_dir("child")?; - dotenv().ok(); - assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); + dotenv()?; + assert_eq!(env::var("TESTKEY")?, "test_val"); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-default-location.rs b/dotenv/tests/test-default-location.rs index 65e35ffa..7941fe15 100644 --- a/dotenv/tests/test-default-location.rs +++ b/dotenv/tests/test-default-location.rs @@ -1,17 +1,19 @@ mod common; use dotenvy::*; -use std::env; + +use std::{env, error::Error, result::Result}; use crate::common::*; #[test] -fn test_default_location() { - let dir = make_test_dotenv().unwrap(); +fn test_default_location() -> Result<(), Box> { + let dir = make_test_dotenv()?; - dotenv().ok(); - assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); + dotenv()?; + assert_eq!(env::var("TESTKEY")?, "test_val"); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-dotenv-iter.rs b/dotenv/tests/test-dotenv-iter.rs index 49e5a4c1..a41fadd9 100644 --- a/dotenv/tests/test-dotenv-iter.rs +++ b/dotenv/tests/test-dotenv-iter.rs @@ -1,22 +1,21 @@ mod common; use dotenvy::*; -use std::env; +use std::{env, error::Error, result::Result}; use crate::common::*; #[test] -fn test_dotenv_iter() { - let dir = make_test_dotenv().unwrap(); - - let iter = dotenv_iter().unwrap(); +fn test_dotenv_iter() -> Result<(), Box> { + let dir = make_test_dotenv()?; + let iter = dotenv_iter()?; assert!(env::var("TESTKEY").is_err()); - iter.load().ok(); - - assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); + iter.load()?; + assert_eq!(env::var("TESTKEY")?, "test_val"); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-from-filename-iter.rs b/dotenv/tests/test-from-filename-iter.rs index eaf42300..968480c4 100644 --- a/dotenv/tests/test-from-filename-iter.rs +++ b/dotenv/tests/test-from-filename-iter.rs @@ -1,22 +1,23 @@ mod common; use dotenvy::*; -use std::env; +use std::{env, error::Error, result::Result}; use crate::common::*; #[test] -fn test_from_filename_iter() { - let dir = make_test_dotenv().unwrap(); +fn test_from_filename_iter() -> Result<(), Box> { + let dir = make_test_dotenv()?; - let iter = from_filename_iter(".env").unwrap(); + let iter = from_filename_iter(".env")?; assert!(env::var("TESTKEY").is_err()); - iter.load().ok(); + iter.load()?; assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-from-filename.rs b/dotenv/tests/test-from-filename.rs index 1be87b00..75145eae 100644 --- a/dotenv/tests/test-from-filename.rs +++ b/dotenv/tests/test-from-filename.rs @@ -1,18 +1,19 @@ mod common; use dotenvy::*; -use std::env; +use std::{env, error::Error, result::Result}; use crate::common::*; #[test] -fn test_from_filename() { - let dir = make_test_dotenv().unwrap(); +fn test_from_filename() -> Result<(), Box> { + let dir = make_test_dotenv()?; - from_filename(".env").ok(); + from_filename(".env")?; - assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); + assert_eq!(env::var("TESTKEY")?, "test_val"); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-from-path-iter.rs b/dotenv/tests/test-from-path-iter.rs index 048654ec..211cd863 100644 --- a/dotenv/tests/test-from-path-iter.rs +++ b/dotenv/tests/test-from-path-iter.rs @@ -1,25 +1,26 @@ mod common; use dotenvy::*; -use std::env; +use std::{env, error::Error, result::Result}; use crate::common::*; #[test] -fn test_from_path_iter() { - let dir = make_test_dotenv().unwrap(); +fn test_from_path_iter() -> Result<(), Box> { + let dir = make_test_dotenv()?; - let mut path = env::current_dir().unwrap(); + let mut path = env::current_dir()?; path.push(".env"); - let iter = from_path_iter(&path).unwrap(); + let iter = from_path_iter(&path)?; assert!(env::var("TESTKEY").is_err()); - iter.load().ok(); + iter.load()?; - assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); + assert_eq!(env::var("TESTKEY")?, "test_val"); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-from-path.rs b/dotenv/tests/test-from-path.rs index 4354fc53..f7731666 100644 --- a/dotenv/tests/test-from-path.rs +++ b/dotenv/tests/test-from-path.rs @@ -1,21 +1,21 @@ mod common; -use dotenvy::*; -use std::env; - use crate::common::*; +use dotenvy::*; +use std::{env, error::Error, result::Result}; #[test] -fn test_from_path() { - let dir = make_test_dotenv().unwrap(); +fn test_from_path() -> Result<(), Box> { + let dir = make_test_dotenv()?; - let mut path = env::current_dir().unwrap(); + let mut path = env::current_dir()?; path.push(".env"); - from_path(&path).ok(); + from_path(&path)?; - assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); + assert_eq!(env::var("TESTKEY")?, "test_val"); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-multiline.rs b/dotenv/tests/test-multiline.rs index 35020c20..83776f40 100644 --- a/dotenv/tests/test-multiline.rs +++ b/dotenv/tests/test-multiline.rs @@ -2,10 +2,10 @@ mod common; use crate::common::*; use dotenvy::*; -use std::env; +use std::{env, error::Error, result::Result}; #[test] -fn test_multiline() { +fn test_multiline() -> Result<(), Box> { let value = "-----BEGIN PRIVATE KEY-----\n-----END PRIVATE KEY-----\\n\\\"QUOTED\\\""; let weak = "-----BEGIN PRIVATE KEY-----\n-----END PRIVATE KEY-----\n\"QUOTED\""; let dir = tempdir_with_dotenv(&format!( @@ -21,26 +21,26 @@ WEAK="{}" STRONG='{}' "#, value, value - )) - .unwrap(); + ))?; - dotenv().ok(); - assert_eq!(var("KEY").unwrap(), r#"my cool value"#); + dotenv()?; + assert_eq!(var("KEY")?, r#"my cool value"#); assert_eq!( - var("KEY3").unwrap(), + var("KEY3")?, r#"awesome "stuff" more on other lines"# ); assert_eq!( - var("KEY4").unwrap(), + var("KEY4")?, r#"hello 'world good ' 'morning"# ); - assert_eq!(var("WEAK").unwrap(), weak); - assert_eq!(var("STRONG").unwrap(), value); + assert_eq!(var("WEAK")?, weak); + assert_eq!(var("STRONG")?, value); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-var.rs b/dotenv/tests/test-var.rs index a14a3a44..71cc13d9 100644 --- a/dotenv/tests/test-var.rs +++ b/dotenv/tests/test-var.rs @@ -1,17 +1,17 @@ mod common; -use std::env; - use dotenvy::*; +use std::{env, error::Error, result::Result}; use crate::common::*; #[test] -fn test_var() { - let dir = make_test_dotenv().unwrap(); +fn test_var() -> Result<(), Box> { + let dir = make_test_dotenv()?; - assert_eq!(var("TESTKEY").unwrap(), "test_val"); + assert_eq!(var("TESTKEY")?, "test_val"); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-variable-substitution.rs b/dotenv/tests/test-variable-substitution.rs index 237825f2..ad481feb 100644 --- a/dotenv/tests/test-variable-substitution.rs +++ b/dotenv/tests/test-variable-substitution.rs @@ -1,12 +1,12 @@ mod common; use dotenvy::*; -use std::env; +use std::{env, error::Error, result::Result}; use crate::common::*; #[test] -fn test_variable_substitutions() { +fn test_variable_substitutions() -> Result<(), Box> { std::env::set_var("KEY", "value"); std::env::set_var("KEY1", "value1"); @@ -25,18 +25,14 @@ SUBSTITUTION_FOR_WEAK_QUOTES="{}" SUBSTITUTION_WITHOUT_QUOTES={} "#, common_string, common_string, common_string - )) - .unwrap(); + ))?; - assert_eq!(var("KEY").unwrap(), "value"); - assert_eq!(var("KEY1").unwrap(), "value1"); - assert_eq!(var("KEY_U").unwrap(), "value+valueU"); + assert_eq!(var("KEY")?, "value"); + assert_eq!(var("KEY1")?, "value1"); + assert_eq!(var("KEY_U")?, "value+valueU"); + assert_eq!(var("SUBSTITUTION_FOR_STRONG_QUOTES")?, common_string); assert_eq!( - var("SUBSTITUTION_FOR_STRONG_QUOTES").unwrap(), - common_string - ); - assert_eq!( - var("SUBSTITUTION_FOR_WEAK_QUOTES").unwrap(), + var("SUBSTITUTION_FOR_WEAK_QUOTES")?, [ "", "value", @@ -49,7 +45,7 @@ SUBSTITUTION_WITHOUT_QUOTES={} .join(">>") ); assert_eq!( - var("SUBSTITUTION_WITHOUT_QUOTES").unwrap(), + var("SUBSTITUTION_WITHOUT_QUOTES")?, [ "", "value", @@ -62,6 +58,7 @@ SUBSTITUTION_WITHOUT_QUOTES={} .join(">>") ); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) } diff --git a/dotenv/tests/test-vars.rs b/dotenv/tests/test-vars.rs index a5a781c9..4fb9c647 100644 --- a/dotenv/tests/test-vars.rs +++ b/dotenv/tests/test-vars.rs @@ -1,20 +1,20 @@ mod common; -use std::collections::HashMap; -use std::env; +use std::{collections::HashMap, env, error::Error, result::Result}; use dotenvy::*; use crate::common::*; #[test] -fn test_vars() { - let dir = make_test_dotenv().unwrap(); +fn test_vars() -> Result<(), Box> { + let dir = make_test_dotenv()?; let vars: HashMap = vars().collect(); assert_eq!(vars["TESTKEY"], "test_val"); - env::set_current_dir(dir.path().parent().unwrap()).unwrap(); - dir.close().unwrap(); + env::set_current_dir(dir.path().parent().unwrap())?; + dir.close()?; + Ok(()) }