diff --git a/README.md b/README.md index 727ad14..5285ab7 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The script uses `jq` for heavy lifting. ### Simple Usage ``` -> bash-env examples/simple.env +> bash-env tests/simple.env ╭───┬───╮ │ B │ b │ │ A │ a │ @@ -50,7 +50,7 @@ Error: nu::shell::name_not_found × Name not found -> bash-env examples/simple.env | load-env +> bash-env tests/simple.env | load-env > echo $env.A a @@ -58,7 +58,7 @@ a b -> bash-env examples/simple.env +> bash-env tests/simple.env ╭──────────────╮ │ empty record │ ╰──────────────╯ @@ -110,14 +110,14 @@ The plugin supports `--export` for exporting shell variables into the environmen Care has been taken to escape any special characters. ``` -> bash-env `examples/Ming's "menu" of (merciless) monstrosities.env` +> bash-env `tests/Ming's "menu" of (merciless) monstrosities.env` ╭───────────┬──────────────────────────────────────────────────────╮ │ QUOTE │ "Well done!" is better than "Well said!" │ │ SPACEMAN │ One small step for a man ... │ │ MIXED_BAG │ Did the sixth sheik's sixth sheep say "baa", or not? │ ╰───────────┴──────────────────────────────────────────────────────╯ -> bash-env `examples/Ming's "menu" of (merciless) monstrosities.env` | load-env +> bash-env `tests/Ming's "menu" of (merciless) monstrosities.env` | load-env > echo $env.QUOTE "Well done!" is better than "Well said!" ``` diff --git a/run-tests.nu b/run-tests.nu new file mode 100644 index 0000000..1849909 --- /dev/null +++ b/run-tests.nu @@ -0,0 +1,105 @@ +use std assert + +# TODO use testing.nu testing module, +# which wasn't working at the time I wrote these tests + +#[before-all] +def add_and_use_plugin [] { + plugin add nu_plugin_bash_env + plugin use bash_env +} + +#[test] +def test_echo [] { + let actual = echo "export A=123" | bash-env + let expected = { A: "123" } + assert equal $actual $expected +} + +#[test] +def test_not_exported [] { + let actual = echo "A=123" | bash-env + let expected = { } + assert equal $actual $expected +} + +#[test] +def test_export_shell_variables [] { + let actual = echo "A=123" | bash-env --export [A] + let expected = { A: "123" } + assert equal $actual $expected +} + +#[test] +def test_export_shell_variables_missing [] { + let actual = echo "A=123" | bash-env --export [A B] + let expected = { A: "123" B: "" } + assert equal $actual $expected +} + +#[test] +def test_shell_variables_from_file [] { + let actual = bash-env tests/shell-variables.env + let expected = { B: "exported" } + assert equal $actual $expected +} + +#[test] +def test_export_shell_variables_from_file [] { + let actual = bash-env --export [A] tests/shell-variables.env + let expected = { A: "not exported" B: "exported" } + assert equal $actual $expected +} + +#[test] +def test_empty_value [] { + let actual = echo "export A=\"\"" | bash-env + let expected = { A: "" } + assert equal $actual $expected +} + +#[test] +def test_simple_file [] { + let actual = bash-env tests/simple.env + let expected = { A: "a" B: "b" } + assert equal $actual $expected +} + +#[test] +def test_cat_simple_file [] { + let actual = cat tests/simple.env | bash-env + let expected = { A: "a" B: "b" } + assert equal $actual $expected +} + +#[test] +def test_nasty_values_from_file [] { + let actual = bash-env "tests/Ming's menu of (merciless) monstrosities.env" + let expected = { + SPACEMAN: "One small step for a man ..." + QUOTE: "\"Well done!\" is better than \"Well said!\"" + MIXED_BAG: "Did the sixth sheik's sixth sheep say \"baa\", or not?" + } + assert equal $actual $expected +} + +#[test] +def test_mixed [] { + let actual = echo "export A=override-a C=sea" | bash-env tests/simple.env + let expected = { A: "override-a" B: "b" C: "sea" } + assert equal $actual $expected +} + +add_and_use_plugin + +test_echo +test_not_exported +test_export_shell_variables +test_export_shell_variables_missing +test_shell_variables_from_file +test_export_shell_variables_from_file +test_empty_value +test_simple_file +test_cat_simple_file +test_nasty_values_from_file +test_mixed diff --git a/examples/Ming's menu of (merciless) monstrosities.env b/tests/Ming's menu of (merciless) monstrosities.env similarity index 100% rename from examples/Ming's menu of (merciless) monstrosities.env rename to tests/Ming's menu of (merciless) monstrosities.env diff --git a/examples/empty.env b/tests/empty.env similarity index 100% rename from examples/empty.env rename to tests/empty.env diff --git a/examples/error.env b/tests/error.env similarity index 100% rename from examples/error.env rename to tests/error.env diff --git a/tests/shell-variables.env b/tests/shell-variables.env new file mode 100644 index 0000000..eb0f798 --- /dev/null +++ b/tests/shell-variables.env @@ -0,0 +1,2 @@ +A="not exported" +export B="exported" diff --git a/examples/simple.env b/tests/simple.env similarity index 100% rename from examples/simple.env rename to tests/simple.env diff --git a/examples/single.env b/tests/single.env similarity index 100% rename from examples/single.env rename to tests/single.env