Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tesujimath committed May 24, 2024
1 parent 36aaab3 commit 38761ef
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 │
Expand All @@ -50,15 +50,15 @@ 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
> echo $env.B
b
> bash-env examples/simple.env
> bash-env tests/simple.env
╭──────────────╮
│ empty record │
╰──────────────╯
Expand Down Expand Up @@ -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!"
```
Expand Down
105 changes: 105 additions & 0 deletions run-tests.nu
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/shell-variables.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A="not exported"
export B="exported"
File renamed without changes.
File renamed without changes.

0 comments on commit 38761ef

Please sign in to comment.