-
Notifications
You must be signed in to change notification settings - Fork 18
Add nupm test
#19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add nupm test
#19
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
47bffb5
Add main `nupm` command; Start `dirs` module
kubouch df65a3a
Add some comments; Remove tmp path (unused for now)
kubouch 607d5a3
Use $env.NUPM_HOME directly in `nupm install`
kubouch 0a52295
Remove currently unused dirs creation
kubouch 2a9d939
Fix sentence
kubouch 27889f9
Adjust comment
kubouch 32ecbab
Unspan errors; Simplify env check
kubouch 6be3671
Fix empty env var error
kubouch beeef3c
Remove print
kubouch a5ab5ff
Add NUPM_HOME prompt to `nupm install`
kubouch bd3ce39
Make args more generic
kubouch 5c0167b
Don't require description and license
kubouch 9f6f3e7
Fix module install; Refactor
kubouch b14e091
Pass package.nuon filename to build.nu; Format
kubouch 26809f8
Add missing default
kubouch ddfed56
Build custom package in temporary directory
kubouch b4ffee5
Format command to reduce super-long lines
kubouch 11c5989
Merge branch 'main' into nupm-install
kubouch 2145928
Remove merge leftover line
kubouch 49c4cf5
Add some type annotations
kubouch 983a645
Add newline to error
kubouch 0ae5405
Use implicit return from tmp buid dir
kubouch f4a5e42
Simplify flag propagation
kubouch fe71822
Add type annotation
kubouch deaa426
Start `nupm test` command
kubouch 00e2d35
Allow running `nupm test` from any directory
kubouch 085fc35
Fix nupm install error message
kubouch cf37eea
Add basic tests for nupm install
kubouch a05f6dc
Change test prefix to "test-"; Improve test glob
kubouch ec51c81
Abstract away setting $env.NUPM_HOME in tests
kubouch b70f59c
Allow showing test stdout; Fix nupm install scripts
kubouch ae38099
Add output type to nupm test
kubouch 1b6c1b9
Allow filtering tests
kubouch 4843f51
Add test packages
kubouch ba8c489
Treat tests directory as a module
kubouch 46ab2ad
Merge branch 'main' into nupm-test
kubouch a963169
Add newlines
kubouch 3325de8
Remove unnecessary file
kubouch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use utils/dirs.nu [ tmp-dir find-root ] | ||
use utils/log.nu throw-error | ||
|
||
# Experimental test runner | ||
export def main [ | ||
filter?: string = '' # Run only tests containing this substring | ||
--dir: path # Directory where to run tests (default: $env.PWD) | ||
--show-stdout # Show standard output of each test | ||
]: nothing -> nothing { | ||
let dir = ($dir | default $env.PWD | path expand -s) | ||
let pkg_root = find-root $dir | ||
|
||
if $pkg_root == null { | ||
throw-error ($'Could not find "package.nuon" in ($dir)' | ||
+ ' or any parent directory.') | ||
} | ||
|
||
print $'Testing package ($pkg_root)' | ||
cd $pkg_root | ||
|
||
let tests = nu [ | ||
--no-config-file | ||
--commands | ||
'use tests/ | ||
kubouch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
scope commands | ||
| where ($it.name | str starts-with tests) | ||
kubouch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| get name | ||
| to nuon' | ||
] | ||
| from nuon | ||
|
||
let out = $tests | ||
| where ($filter in $it) | ||
| par-each {|test| | ||
let res = do { | ||
nu [ | ||
--no-config-file | ||
--commands | ||
$'use tests/; ($test)' | ||
] | ||
} | ||
| complete | ||
|
||
if $res.exit_code == 0 { | ||
print $'($test) ... (ansi gb)SUCCESS(ansi reset)' | ||
} else { | ||
print $'($test) ... (ansi rb)FAILURE(ansi reset)' | ||
} | ||
|
||
if $show_stdout { | ||
print 'stdout:' | ||
print $res.stdout | ||
} | ||
|
||
{ | ||
name: $test | ||
stdout: $res.stdout | ||
stderr: $res.stderr | ||
exit_code: $res.exit_code | ||
} | ||
} | ||
|
||
let successes = $out | where exit_code == 0 | ||
let failures = $out | where exit_code != 0 | ||
|
||
$failures | each {|fail| | ||
print ($'(char nl)Test "($fail.name)" failed with exit code' | ||
+ $' ($fail.exit_code):(char nl)' | ||
+ ($fail.stderr | str trim)) | ||
} | ||
|
||
if ($failures | length) != 0 { | ||
print '' | ||
} | ||
|
||
print ($'Ran ($out | length) tests.' | ||
+ $' ($successes | length) succeeded,' | ||
+ $' ($failures | length) failed.') | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
export def throw-error [ | ||
error: string | ||
text?: string | ||
--span: record<start: int, end: int> | ||
] { | ||
let error = $"(ansi red_bold)($error)(ansi reset)" | ||
|
||
if $span == null { | ||
error make --unspanned { msg: $error } | ||
} | ||
|
||
error make { | ||
msg: $error | ||
label: { | ||
text: ($text | default "this caused an internal error") | ||
start: $span.start | ||
end: $span.end | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
name: nupm | ||
type: module | ||
version: "0.1.0" | ||
description: "Nushell package manager" | ||
license: "LICENSE" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std assert | ||
|
||
use ../nupm/utils/dirs.nu tmp-dir | ||
use ../nupm | ||
|
||
|
||
def with-nupm-home [closure: closure]: nothing -> nothing { | ||
let dir = tmp-dir test --ensure | ||
with-env { NUPM_HOME: $dir } $closure | ||
rm -r $dir | ||
} | ||
|
||
export def install-script [] { | ||
with-nupm-home { | ||
cd tests/packages/spam_script | ||
|
||
nupm install --path . | ||
assert ([$env.NUPM_HOME scripts spam_script.nu] | ||
| path join | ||
| path exists) | ||
assert ([$env.NUPM_HOME scripts spam_bar.nu] | ||
| path join | ||
| path exists) | ||
} | ||
} | ||
|
||
export def install-module [] { | ||
with-nupm-home { | ||
cd tests/packages/spam_module | ||
|
||
nupm install --path . | ||
assert ([$env.NUPM_HOME scripts script.nu] | path join | path exists) | ||
assert ([$env.NUPM_HOME modules spam_module] | path join | path exists) | ||
assert ([$env.NUPM_HOME modules spam_module mod.nu] | ||
| path join | ||
| path exists) | ||
} | ||
} | ||
|
||
export def install-custom [] { | ||
with-nupm-home { | ||
cd tests/packages/spam_custom | ||
|
||
nupm install --path . | ||
assert ([$env.NUPM_HOME plugins nu_plugin_test] | ||
| path join | ||
| path exists) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def main [package_file: path] { | ||
let package = open $package_file | ||
print $"Installing ($package.name) to ($env.NUPM_HOME) inside ($env.PWD)" | ||
mkdir ($env.NUPM_HOME | path join plugins) | ||
touch ($env.NUPM_HOME | path join plugins nu_plugin_test) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
name: spam_custom, | ||
type: custom, | ||
version: "0.1.0" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
name: spam_module, | ||
type: module, | ||
version: "0.1.0" | ||
scripts: script.nu | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print 'scriptscript' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export def main [] { | ||
"Hello world!" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
name: spam_script, | ||
type: script, | ||
version: "0.1.0", | ||
scripts: ['spam_bar.nu'] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export def main [] { | ||
'Hello bar!' | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env nu | ||
def main [] { | ||
"Hello world!" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.