Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip .env items which are set in environment #656

Merged
merged 3 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'src> Justfile<'src> {
while let Some((argument, mut tail)) = rest.split_first() {
if let Some(recipe) = self.get_recipe(argument) {
if recipe.parameters.is_empty() {
grouped.push((recipe, &tail[0..0]));
grouped.push((recipe, &[][..]));
} else {
let argument_range = recipe.argument_range();
let argument_count = cmp::min(tail.len(), recipe.max_arguments());
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl<'src> Lexer<'src> {
match self.next {
Some('\'') => break,
None => return Err(self.error(UnterminatedString)),
_ => {},
Some(_) => {},
}

self.advance()?;
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@
clippy::comparison_chain,
clippy::else_if_without_else,
clippy::enum_glob_use,
clippy::expect_used,
clippy::filter_map,
clippy::if_not_else,
clippy::implicit_return,
clippy::indexing_slicing,
clippy::integer_arithmetic,
clippy::let_underscore_must_use,
clippy::map_unwrap_or,
clippy::match_same_arms,
clippy::missing_docs_in_private_items,
clippy::missing_errors_doc,
clippy::missing_inline_in_public_items,
clippy::needless_pass_by_value,
clippy::non_ascii_literal,
clippy::option_expect_used,
clippy::option_map_unwrap_or,
clippy::option_unwrap_used,
clippy::panic,
clippy::print_stdout,
clippy::result_expect_used,
clippy::shadow_unrelated,
clippy::string_add,
clippy::struct_excessive_bools,
clippy::too_many_lines,
clippy::unreachable,
clippy::unwrap_used,
clippy::use_debug,
clippy::wildcard_enum_match_arm,
clippy::wildcard_imports
Expand Down
10 changes: 8 additions & 2 deletions src/load_dotenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ pub(crate) fn load_dotenv() -> RunResult<'static, BTreeMap<String, String>> {
#![allow(deprecated)]
match dotenv::dotenv_iter() {
Ok(iter) => {
let result: dotenv::Result<BTreeMap<String, String>> = iter.collect();
result.map_err(|dotenv_error| RuntimeError::Dotenv { dotenv_error })
let mut dotenv = BTreeMap::new();
for result in iter {
let (key, value) = result.map_err(|dotenv_error| RuntimeError::Dotenv { dotenv_error })?;
if env::var_os(&key).is_none() {
dotenv.insert(key, value);
}
}
Ok(dotenv)
},
Err(dotenv_error) =>
if dotenv_error.not_found() {
Expand Down
3 changes: 1 addition & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ impl<'text> Tree<'text> {

/// Like `push`, but modify self in-place
pub(crate) fn push_mut(&mut self, tree: impl Into<Tree<'text>>) {
let tree = mem::replace(self, Tree::List(Vec::new())).push(tree.into());
mem::replace(self, tree);
*self = mem::replace(self, Tree::List(Vec::new())).push(tree.into());
}
}

Expand Down
25 changes: 25 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
collections::BTreeMap,
env, fs,
io::Write,
path::Path,
Expand All @@ -16,6 +17,9 @@ macro_rules! test {
name: $name:ident,
justfile: $justfile:expr,
$(args: ($($arg:tt)*),)?
$(env: {
$($env_key:literal : $env_value:literal,)*
},)?
$(stdin: $stdin:expr,)?
$(stdout: $stdout:expr,)?
$(stderr: $stderr:expr,)?
Expand All @@ -24,6 +28,11 @@ macro_rules! test {
) => {
#[test]
fn $name() {
#[allow(unused_mut)]
let mut env = BTreeMap::new();

$($(env.insert($env_key.to_string(), $env_value.to_string());)*)?

Test {
justfile: $justfile,
$(args: &[$($arg)*],)?
Expand All @@ -32,6 +41,7 @@ macro_rules! test {
$(stderr: $stderr,)?
$(status: $status,)?
$(shell: $shell,)?
env,
..Test::default()
}.run();
}
Expand All @@ -41,6 +51,7 @@ macro_rules! test {
struct Test<'a> {
justfile: &'a str,
args: &'a [&'a str],
env: BTreeMap<String, String>,
stdin: &'a str,
stdout: &'a str,
stderr: &'a str,
Expand All @@ -53,6 +64,7 @@ impl<'a> Default for Test<'a> {
Test {
justfile: "",
args: &[],
env: BTreeMap::new(),
stdin: "",
stdout: "",
stderr: "",
Expand Down Expand Up @@ -86,6 +98,7 @@ impl<'a> Test<'a> {

let mut child = command
.args(self.args)
.envs(self.env)
.current_dir(tmp.path())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
Expand Down Expand Up @@ -2070,6 +2083,18 @@ echo:
stderr: "echo DEFAULT\n",
}

test! {
name: dotenv_env_var_override,
justfile: "
#
echo:
echo $DOTENV_KEY
",
env: {"DOTENV_KEY": "not-the-dotenv-value",},
stdout: "not-the-dotenv-value\n",
stderr: "echo $DOTENV_KEY\n",
}

test! {
name: invalid_escape_sequence_message,
justfile: r#"
Expand Down