Skip to content

Commit

Permalink
Make test env more robust
Browse files Browse the repository at this point in the history
I.e., don't use user cache and temp dirs
  • Loading branch information
kubouch committed Jan 28, 2024
1 parent 51b608f commit 6921c33
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions tests/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ use ../nupm
const TEST_REGISTRY_PATH = ([tests packages registry.nuon] | path join)


def with-nupm-home [closure: closure]: nothing -> nothing {
let dir = tmp-dir test --ensure
with-env { NUPM_HOME: $dir } $closure
rm --recursive $dir
def with-test-env [closure: closure]: nothing -> nothing {
let home = tmp-dir nupm_test --ensure
let cache = tmp-dir 'nupm_test/cache' --ensure
let temp = tmp-dir 'nupm_test/temp' --ensure

with-env {
NUPM_HOME: $home
NUPM_CACHE: $cache
NUPM_TEMP: $temp
} $closure

rm --recursive $temp
rm --recursive $cache
rm --recursive $home
}

# Examples:
Expand All @@ -20,7 +30,7 @@ def "assert installed" [path_tokens: list<string>] {
}

export def install-script [] {
with-nupm-home {
with-test-env {
nupm install --path tests/packages/spam_script

assert installed [scripts spam_script.nu]
Expand All @@ -29,7 +39,7 @@ export def install-script [] {
}

export def install-module [] {
with-nupm-home {
with-test-env {
nupm install --path tests/packages/spam_module

assert installed [scripts script.nu]
Expand All @@ -39,7 +49,7 @@ export def install-module [] {
}

export def install-custom [] {
with-nupm-home {
with-test-env {
nupm install --path tests/packages/spam_custom

assert installed [plugins nu_plugin_test]
Expand All @@ -52,19 +62,19 @@ export def install-from-local-registry [] {
assert ($contents | str contains '0.2.0')
}

with-nupm-home {
with-test-env {
$env.NUPM_REGISTRIES = {}
nupm install --registry $TEST_REGISTRY_PATH spam_script
check-file
}

with-nupm-home {
with-test-env {
$env.NUPM_REGISTRIES = { test: $TEST_REGISTRY_PATH }
nupm install --registry test spam_script
check-file
}

with-nupm-home {
with-test-env {
$env.NUPM_REGISTRIES = { test: $TEST_REGISTRY_PATH }
nupm install spam_script
check-file
Expand Down

0 comments on commit 6921c33

Please sign in to comment.