2022-06-19 07:56:31 +03:00
|
|
|
use super::*;
|
2020-07-19 15:01:46 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dotenv() {
|
2023-01-04 09:31:56 +03:00
|
|
|
Test::new()
|
|
|
|
.write(".env", "KEY=ROOT")
|
|
|
|
.write("sub/.env", "KEY=SUB")
|
|
|
|
.write("sub/justfile", "default:\n\techo KEY=${KEY:-unset}")
|
|
|
|
.args(["sub/default"])
|
|
|
|
.stdout("KEY=unset\n")
|
|
|
|
.stderr("echo KEY=${KEY:-unset}\n")
|
|
|
|
.run();
|
2020-07-19 15:01:46 +03:00
|
|
|
}
|
2021-03-29 08:38:07 +03:00
|
|
|
|
|
|
|
test! {
|
|
|
|
name: set_false,
|
|
|
|
justfile: r#"
|
|
|
|
set dotenv-load := false
|
|
|
|
|
|
|
|
foo:
|
|
|
|
if [ -n "${DOTENV_KEY+1}" ]; then echo defined; else echo undefined; fi
|
|
|
|
"#,
|
|
|
|
stdout: "undefined\n",
|
|
|
|
stderr: "if [ -n \"${DOTENV_KEY+1}\" ]; then echo defined; else echo undefined; fi\n",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: set_implicit,
|
|
|
|
justfile: r#"
|
|
|
|
set dotenv-load
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo $DOTENV_KEY
|
|
|
|
"#,
|
|
|
|
stdout: "dotenv-value\n",
|
|
|
|
stderr: "echo $DOTENV_KEY\n",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: set_true,
|
|
|
|
justfile: r#"
|
|
|
|
set dotenv-load := true
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo $DOTENV_KEY
|
|
|
|
"#,
|
|
|
|
stdout: "dotenv-value\n",
|
|
|
|
stderr: "echo $DOTENV_KEY\n",
|
2021-03-31 03:30:32 +03:00
|
|
|
}
|
|
|
|
|
2021-07-28 10:33:44 +03:00
|
|
|
#[test]
|
2022-02-02 06:16:35 +03:00
|
|
|
fn no_warning() {
|
2021-07-28 10:33:44 +03:00
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
2022-02-02 06:16:35 +03:00
|
|
|
echo ${DOTENV_KEY:-unset}
|
2021-07-28 10:33:44 +03:00
|
|
|
",
|
|
|
|
)
|
2022-02-02 06:16:35 +03:00
|
|
|
.stdout("unset\n")
|
|
|
|
.stderr("echo ${DOTENV_KEY:-unset}\n")
|
2021-07-28 10:33:44 +03:00
|
|
|
.run();
|
|
|
|
}
|
2021-08-09 08:37:35 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn path_not_found() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo $NAME
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["--dotenv-path", ".env.prod"])
|
2021-08-09 08:37:35 +03:00
|
|
|
.stderr(if cfg!(windows) {
|
|
|
|
"error: Failed to load environment file: The system cannot find the file specified. (os \
|
|
|
|
error 2)\n"
|
|
|
|
} else {
|
|
|
|
"error: Failed to load environment file: No such file or directory (os error 2)\n"
|
|
|
|
})
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn path_resolves() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
@echo $NAME
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.tree(tree! {
|
|
|
|
subdir: {
|
|
|
|
".env": "NAME=bar"
|
|
|
|
}
|
|
|
|
})
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["--dotenv-path", "subdir/.env"])
|
2021-08-09 08:37:35 +03:00
|
|
|
.stdout("bar\n")
|
|
|
|
.status(EXIT_SUCCESS)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filename_resolves() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
@echo $NAME
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.tree(tree! {
|
|
|
|
".env.special": "NAME=bar"
|
|
|
|
})
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["--dotenv-filename", ".env.special"])
|
2021-08-09 08:37:35 +03:00
|
|
|
.stdout("bar\n")
|
|
|
|
.status(EXIT_SUCCESS)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filename_flag_overwrites_no_load() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
set dotenv-load := false
|
|
|
|
|
|
|
|
foo:
|
|
|
|
@echo $NAME
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.tree(tree! {
|
|
|
|
".env.special": "NAME=bar"
|
|
|
|
})
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["--dotenv-filename", ".env.special"])
|
2021-08-09 08:37:35 +03:00
|
|
|
.stdout("bar\n")
|
|
|
|
.status(EXIT_SUCCESS)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn path_flag_overwrites_no_load() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
set dotenv-load := false
|
|
|
|
|
|
|
|
foo:
|
|
|
|
@echo $NAME
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.tree(tree! {
|
|
|
|
subdir: {
|
|
|
|
".env": "NAME=bar"
|
|
|
|
}
|
|
|
|
})
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["--dotenv-path", "subdir/.env"])
|
2021-08-09 08:37:35 +03:00
|
|
|
.stdout("bar\n")
|
|
|
|
.status(EXIT_SUCCESS)
|
|
|
|
.run();
|
|
|
|
}
|