From 9787f1542c2578a148db22db5d232182a1bd3686 Mon Sep 17 00:00:00 2001 From: Hasan-Alrimawi Date: Tue, 21 May 2024 15:09:59 +0300 Subject: [PATCH 1/3] Solved --env flag missing file/wrong syntax of file content issue --- cli/args/mod.rs | 18 +++++++++++------- tests/integration/eval_tests.rs | 5 +++++ tests/integration/run_tests.rs | 5 +++++ tests/testdata/env_unparsable | 4 ++++ tests/testdata/eval/env_file_missing.out | 2 +- tests/testdata/eval/env_unparsable_file.out | 2 ++ tests/testdata/run/env_file_missing.out | 2 +- tests/testdata/run/env_unparsable_file.out | 4 ++++ 8 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 tests/testdata/env_unparsable create mode 100644 tests/testdata/eval/env_unparsable_file.out create mode 100644 tests/testdata/run/env_unparsable_file.out diff --git a/cli/args/mod.rs b/cli/args/mod.rs index b3d508e18a236a..2479da5798a89b 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -776,13 +776,17 @@ impl CliOptions { }; if let Some(env_file_name) = &flags.env_file { - if (from_filename(env_file_name)).is_err() { - log::info!( - "{} The `--env` flag was used, but the dotenv file '{}' was not found.", - colors::yellow("Warning"), - env_file_name - ); - } + match from_filename(env_file_name) { + Ok(_) => (), + Err(error) => { + match error { + dotenvy::Error::LineParse(line, index)=> log::info!("{} Parsing failed within the specified environment file: {} at index: {} of the value: {}",colors::yellow("Warning"), env_file_name, index, line), + dotenvy::Error::Io(_)=> log::info!("{} The `--env` flag was used, but the environment file specified '{}' was not found.",colors::yellow("Warning"),env_file_name), + dotenvy::Error::EnvVar(_)=>log::info!("{} One or more of the environment variables isn't present or not unicode within the specified environment file: {}",colors::yellow("Warning"),env_file_name), + _ => log::info!("{} Unknown failure occurred with the specified environment file: {}", colors::yellow("Warning"), env_file_name), + } + } + } } let disable_deprecated_api_warning = flags.log_level diff --git a/tests/integration/eval_tests.rs b/tests/integration/eval_tests.rs index 3f4c6a3a6d2b66..cb805895970081 100644 --- a/tests/integration/eval_tests.rs +++ b/tests/integration/eval_tests.rs @@ -88,3 +88,8 @@ itest!(env_file_missing { args: "eval --env=missing console.log(Deno.env.get(\"ANOTHER_FOO\"))", output: "eval/env_file_missing.out", }); + +itest!(env_unparsable_file { + args: "eval --env=env_unparsable console.log(Deno.env.get(\"Another_FOO\"))", + output: "eval/env_unparsable_file.out", +}); \ No newline at end of file diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index f3fc18fee25d9d..abcf7e62ef9684 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -754,6 +754,11 @@ itest!(env_file_missing { output: "run/env_file_missing.out", }); +itest!(env_unparsable_file { + args: "run --env=env_unparsable --allow-env run/env_file.ts", + output: "run/env_unparsable_file.out", +}); + itest!(_091_use_define_for_class_fields { args: "run --check run/091_use_define_for_class_fields.ts", output: "run/091_use_define_for_class_fields.ts.out", diff --git a/tests/testdata/env_unparsable b/tests/testdata/env_unparsable new file mode 100644 index 00000000000000..5542b80bc3b355 --- /dev/null +++ b/tests/testdata/env_unparsable @@ -0,0 +1,4 @@ +FOO=valid +ANOTHER_FOO=c:\path +MULTILINE="First Line +Second Line" \ No newline at end of file diff --git a/tests/testdata/eval/env_file_missing.out b/tests/testdata/eval/env_file_missing.out index 221acab9348d9e..2ec371438ab6bd 100644 --- a/tests/testdata/eval/env_file_missing.out +++ b/tests/testdata/eval/env_file_missing.out @@ -1,2 +1,2 @@ -Warning The `--env` flag was used, but the dotenv file 'missing' was not found. +Warning The `--env` flag was used, but the environment file specified 'missing' was not found. undefined diff --git a/tests/testdata/eval/env_unparsable_file.out b/tests/testdata/eval/env_unparsable_file.out new file mode 100644 index 00000000000000..1b3f7047a77f1f --- /dev/null +++ b/tests/testdata/eval/env_unparsable_file.out @@ -0,0 +1,2 @@ +Warning Parsing failed within the specified environment file: env_unparsable at index: 3 of the value: c:\path +undefined diff --git a/tests/testdata/run/env_file_missing.out b/tests/testdata/run/env_file_missing.out index ae1f8f595d32e0..6ec9b298fc6ff2 100644 --- a/tests/testdata/run/env_file_missing.out +++ b/tests/testdata/run/env_file_missing.out @@ -1,4 +1,4 @@ -Warning The `--env` flag was used, but the dotenv file 'missing' was not found. +Warning The `--env` flag was used, but the environment file specified 'missing' was not found. undefined undefined undefined diff --git a/tests/testdata/run/env_unparsable_file.out b/tests/testdata/run/env_unparsable_file.out new file mode 100644 index 00000000000000..751ed2842ff20e --- /dev/null +++ b/tests/testdata/run/env_unparsable_file.out @@ -0,0 +1,4 @@ +Warning Parsing failed within the specified environment file: env_unparsable at index: 3 of the value: c:\path +valid +undefined +undefined From e921ff7a932c298daa40cc3225a571155a7cf213 Mon Sep 17 00:00:00 2001 From: Hasan-Alrimawi Date: Wed, 22 May 2024 10:31:23 +0300 Subject: [PATCH 2/3] updated code formatting --- cli/args/mod.rs | 2 +- tests/integration/eval_tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 2479da5798a89b..6fabb07e31e7cd 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -776,7 +776,7 @@ impl CliOptions { }; if let Some(env_file_name) = &flags.env_file { - match from_filename(env_file_name) { + match from_filename(env_file_name) { Ok(_) => (), Err(error) => { match error { diff --git a/tests/integration/eval_tests.rs b/tests/integration/eval_tests.rs index cb805895970081..e09557ef98d27e 100644 --- a/tests/integration/eval_tests.rs +++ b/tests/integration/eval_tests.rs @@ -92,4 +92,4 @@ itest!(env_file_missing { itest!(env_unparsable_file { args: "eval --env=env_unparsable console.log(Deno.env.get(\"Another_FOO\"))", output: "eval/env_unparsable_file.out", -}); \ No newline at end of file +}); From 2b39b9e8847ff406ffd292dce0c6e9893322c5ec Mon Sep 17 00:00:00 2001 From: Hasan-Alrimawi Date: Thu, 23 May 2024 11:22:31 +0300 Subject: [PATCH 3/3] fix: moved two new added tests to specs folder rather than using itest macro within integration folder --- tests/integration/eval_tests.rs | 5 ----- tests/integration/run_tests.rs | 5 ----- tests/specs/eval/env_unparsable_file/__test__.jsonc | 4 ++++ tests/specs/eval/env_unparsable_file/main.out | 2 ++ tests/specs/run/env_unparsable_file/__test__.jsonc | 4 ++++ tests/specs/run/env_unparsable_file/main.js | 3 +++ tests/specs/run/env_unparsable_file/main.out | 4 ++++ tests/testdata/eval/env_unparsable_file.out | 2 -- tests/testdata/run/env_unparsable_file.out | 4 ---- 9 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 tests/specs/eval/env_unparsable_file/__test__.jsonc create mode 100644 tests/specs/eval/env_unparsable_file/main.out create mode 100644 tests/specs/run/env_unparsable_file/__test__.jsonc create mode 100644 tests/specs/run/env_unparsable_file/main.js create mode 100644 tests/specs/run/env_unparsable_file/main.out delete mode 100644 tests/testdata/eval/env_unparsable_file.out delete mode 100644 tests/testdata/run/env_unparsable_file.out diff --git a/tests/integration/eval_tests.rs b/tests/integration/eval_tests.rs index e09557ef98d27e..3f4c6a3a6d2b66 100644 --- a/tests/integration/eval_tests.rs +++ b/tests/integration/eval_tests.rs @@ -88,8 +88,3 @@ itest!(env_file_missing { args: "eval --env=missing console.log(Deno.env.get(\"ANOTHER_FOO\"))", output: "eval/env_file_missing.out", }); - -itest!(env_unparsable_file { - args: "eval --env=env_unparsable console.log(Deno.env.get(\"Another_FOO\"))", - output: "eval/env_unparsable_file.out", -}); diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index abcf7e62ef9684..f3fc18fee25d9d 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -754,11 +754,6 @@ itest!(env_file_missing { output: "run/env_file_missing.out", }); -itest!(env_unparsable_file { - args: "run --env=env_unparsable --allow-env run/env_file.ts", - output: "run/env_unparsable_file.out", -}); - itest!(_091_use_define_for_class_fields { args: "run --check run/091_use_define_for_class_fields.ts", output: "run/091_use_define_for_class_fields.ts.out", diff --git a/tests/specs/eval/env_unparsable_file/__test__.jsonc b/tests/specs/eval/env_unparsable_file/__test__.jsonc new file mode 100644 index 00000000000000..cf5e9a99b2ae9b --- /dev/null +++ b/tests/specs/eval/env_unparsable_file/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "eval --env=../../../testdata/env_unparsable console.log(Deno.env.get(\"Another_FOO\"))", + "output": "main.out" +} diff --git a/tests/specs/eval/env_unparsable_file/main.out b/tests/specs/eval/env_unparsable_file/main.out new file mode 100644 index 00000000000000..18d7856b45b0c9 --- /dev/null +++ b/tests/specs/eval/env_unparsable_file/main.out @@ -0,0 +1,2 @@ +Warning Parsing failed within the specified environment file: ../../../testdata/env_unparsable at index: 3 of the value: c:\path +undefined diff --git a/tests/specs/run/env_unparsable_file/__test__.jsonc b/tests/specs/run/env_unparsable_file/__test__.jsonc new file mode 100644 index 00000000000000..bed15063565792 --- /dev/null +++ b/tests/specs/run/env_unparsable_file/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run --env=../../../testdata/env_unparsable --allow-env main.js", + "output": "main.out" +} diff --git a/tests/specs/run/env_unparsable_file/main.js b/tests/specs/run/env_unparsable_file/main.js new file mode 100644 index 00000000000000..48488ce72105bc --- /dev/null +++ b/tests/specs/run/env_unparsable_file/main.js @@ -0,0 +1,3 @@ +console.log(Deno.env.get("FOO")); +console.log(Deno.env.get("ANOTHER_FOO")); +console.log(Deno.env.get("MULTILINE")); diff --git a/tests/specs/run/env_unparsable_file/main.out b/tests/specs/run/env_unparsable_file/main.out new file mode 100644 index 00000000000000..a19ff4dd6c98c4 --- /dev/null +++ b/tests/specs/run/env_unparsable_file/main.out @@ -0,0 +1,4 @@ +Warning Parsing failed within the specified environment file: ../../../testdata/env_unparsable at index: 3 of the value: c:\path +valid +undefined +undefined diff --git a/tests/testdata/eval/env_unparsable_file.out b/tests/testdata/eval/env_unparsable_file.out deleted file mode 100644 index 1b3f7047a77f1f..00000000000000 --- a/tests/testdata/eval/env_unparsable_file.out +++ /dev/null @@ -1,2 +0,0 @@ -Warning Parsing failed within the specified environment file: env_unparsable at index: 3 of the value: c:\path -undefined diff --git a/tests/testdata/run/env_unparsable_file.out b/tests/testdata/run/env_unparsable_file.out deleted file mode 100644 index 751ed2842ff20e..00000000000000 --- a/tests/testdata/run/env_unparsable_file.out +++ /dev/null @@ -1,4 +0,0 @@ -Warning Parsing failed within the specified environment file: env_unparsable at index: 3 of the value: c:\path -valid -undefined -undefined