Skip to content

Commit

Permalink
test imports exactly (#126)
Browse files Browse the repository at this point in the history
this PR ensures that the import tests are _strong_.

by _strong_, i mean that now, they compare the list of commands in scope
before and after the `use` of a given module.
the diff, i.e. the new commands in scope, should be exactly the commands
from the module.
the import tests don't rely on a prefix anymore.
  • Loading branch information
amtoine authored Dec 4, 2023
1 parent e28d9cd commit f91b743
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
17 changes: 11 additions & 6 deletions tests/common/import.nu
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
export def "assert imports" [
module: string, submodule: string, expected: list<string>, --prefix: string = "gm "
module: string, submodule: string, expected: list<string>
] {
let src = $"
let before = ^$nu.current-exe --no-config-file --commands "
scope commands | get name
| to nuon
" | from nuon
let after = ^$nu.current-exe --no-config-file --commands $"
use ./src/($module)/ ($submodule) *
scope commands | get name | where \($it | str starts-with '($prefix)'\) | to nuon
"
scope commands | get name
| to nuon" | from nuon

let actual = ^$nu.current-exe --no-config-file --commands $src | from nuon
assert equal $actual $expected
let imported = $after | where $it not-in $before

assert equal $imported $expected
}
1 change: 1 addition & 0 deletions tests/gm.nu
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export def store-cleaning [] {

export def user-import [] {
assert imports "nu-git-manager" "" [
"gm",
"gm clean",
"gm clone",
"gm list",
Expand Down
5 changes: 1 addition & 4 deletions tests/sugar/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ use ../common/import.nu ["assert imports"]
const MODULE = "nu-git-manager-sugar"

export module imports {
export def main [] {
assert imports $MODULE "" []
}

export def extra [] {
assert imports $MODULE "extra" [ "gm report" ]
}
Expand All @@ -26,6 +22,7 @@ export module imports {
"gm repo ls",
"gm repo remote list",
"gm repo switch",
"prompt setup",
]
}

Expand Down

0 comments on commit f91b743

Please sign in to comment.