fix: Add test for nushell integration and fix some bugs (#1415)

* Add test for nushell integration
* Add nushell to CI
* Fix brew installation search
* Fix to get current dir when ASDF_DIR is empty
* Remove complexity of asdf.nu
* Try a different approach to get info about function definition of asdf for MacOS 10.15
* Fix shims dir and fix test assertions to check path
* Add setup nushell to CI and remove rust compilation of nushell
* Add gh token to get a higher rate limit
* Change to use binary distribution of nushell instead compile it
* Skip test for older ubuntu
* Use single skipping check
* Remove unneeded condition in SKIP_NUSHELL_TESTS env var
This commit is contained in:
Fer 2023-01-04 17:42:34 -03:00 committed by GitHub
parent 38b269fd09
commit 60d4494d5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 138 additions and 22 deletions

View File

@ -8,6 +8,7 @@ on:
env:
ELVISH_VERSION: v0.18.0
NUSHELL_VERSION: 0.73.0
jobs:
nix:
@ -30,7 +31,7 @@ jobs:
- name: Install test dependencies
if: runner.os == 'macos'
run: brew install coreutils fish elvish
run: brew install coreutils fish elvish nushell
- name: Install test dependencies
if: runner.os == 'linux'
@ -39,12 +40,22 @@ jobs:
sudo apt-get update
sudo apt-get -y install fish curl
# Create $HOME/bin
mkdir -p "$HOME/bin"
# Download elvish binary and add to path
curl https://dl.elv.sh/linux-amd64/elvish-${{ env.ELVISH_VERSION }}.tar.gz -o elvish-${{ env.ELVISH_VERSION }}.tar.gz
tar xzf elvish-${{ env.ELVISH_VERSION }}.tar.gz
rm elvish-${{ env.ELVISH_VERSION }}.tar.gz
mkdir -p "$HOME/bin"
mv elvish-${{ env.ELVISH_VERSION }} "$HOME/bin/elvish"
# Download nushell binary and add to path
curl -L https://github.com/nushell/nushell/releases/download/${{ env.NUSHELL_VERSION }}/nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz -o nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz
tar xzf nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz
rm nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz
mv nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu/* "$HOME/bin"
# Add $HOME/bin to path
echo "$HOME/bin" >>"$GITHUB_PATH"
- name: Install bats
@ -56,3 +67,4 @@ jobs:
run: bats test
env:
GITHUB_API_TOKEN: ${{ github.token }}
SKIP_NUSHELL_TESTS: "${{ matrix.os == 'ubuntu-18.04' && 'YES' }}"

26
asdf.nu
View File

@ -1,26 +1,18 @@
let possible_dirs = [
($env | get --ignore-errors ASDF_DIR | default '' | first) ,
'/opt/asdf-vm/asdf.nu',
($env.HOME | path join '.asdf/asdf.nu')
]
def-env configure-asdf [] {
let is_brew_installed = (which 'brew' | get --ignore-errors path | default '' | str trim | str length | into bool | first )
let-env ASDF_DIR = ( if ( $env | get --ignore-errors ASDF_DIR | is-empty ) { $env.ASDF_NU_DIR } else { $env.ASDF_DIR } )
let possible_dirs = ( $possible_dirs | append (if $is_brew_installed { (brew --prefix asdf | into string | path join 'libexec/asdf.nu') } else { '' }) )
let shims_dir = ( if ( $env | get --ignore-errors ASDF_DATA_DIR | is-empty ) { $env.HOME | path join '.asdf' } else { $env.ASDF_DIR } | path join 'shims' )
let filtered_dirs = ( $possible_dirs |
where { |it| not ($it | is-empty) } )
let asdf_bin_dir = ( $env.ASDF_DIR | path join 'bin' )
let asdf_dir = ( $filtered_dirs |
where {|it| $it | path exists } |
first |
path dirname |
path join 'bin' )
let shims_dir = ( if ($asdf_dir | path join 'shims' | path exists) { $asdf_dir | path join 'shims' } else { $env.HOME | path join '.asdf/shims' } )
let-env PATH = ( $env.PATH | where { |p| $p != $shims_dir } | append $shims_dir )
let-env PATH = ( $env.PATH | where { |p| $p != $asdf_bin_dir } | append $asdf_bin_dir )
let-env PATH = ( $env.PATH | append $asdf_dir )
let-env PATH = ( $env.PATH | append $shims_dir)
}
configure-asdf
## Completions

View File

@ -263,7 +263,7 @@ Completions are placed in a ZSH friendly location, but [ZSH must be configured t
Add `asdf.nu` to your `~/.config/nushell/config.nu` with:
```shell
"\nsource " + ($env.HOME | path join '.asdf/asdf.nu') | save --append $nu.config-path
"\nlet-env ASDF_NU_DIR = ($env.HOME | path join '.asdf')\n source " + ($env.HOME | path join '.asdf/asdf.nu') | save --append $nu.config-path
```
Completions are automatically configured
@ -274,7 +274,7 @@ Completions are automatically configured
Add `asdf.nu` to your `~/.config/nushell/config.nu` with:
```shell:no-line-numbers
"\nsource " + (brew --prefix asdf | into string | path join 'libexec/asdf.nu') | save --append $nu.config-path
"\nlet-env ASDF_NU_DIR = (brew --prefix asdf | into string | path join 'libexec')\n source " + (brew --prefix asdf | into string | path join 'libexec/asdf.nu') | save --append $nu.config-path
```
Completions are automatically configured
@ -285,7 +285,7 @@ Completions are automatically configured
Add `asdf.nu` to your `~/.config/nushell/config.nu` with:
```shell
"\nsource /opt/asdf-vm/asdf.nu" | save --append $nu.config-path
"\nlet-env ASDF_NU_DIR = '/opt/asdf-vm/'\n source /opt/asdf-vm/asdf.nu" | save --append $nu.config-path
```
Completions are automatically configured.

112
test/asdf_nu.bats Normal file
View File

@ -0,0 +1,112 @@
#!/usr/bin/env bats
load test_helpers
setup() {
if [ "${SKIP_NUSHELL_TESTS}" = 'YES' ]; then
skip "skipping nushell tests"
fi
cd $(dirname "$BATS_TEST_DIRNAME")
}
cleaned_path() {
echo $PATH | tr ':' '\n' | grep -v "asdf" | tr '\n' ':'
}
@test "exports ASDF_DIR" {
result=$(nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
let-env ASDF_NU_DIR = '$PWD'
source asdf.nu
echo \$env.ASDF_DIR
")
[ "$?" -eq 0 ]
output=$(echo "$result" | grep "asdf")
[ "$output" == $PWD ]
}
@test "adds asdf dirs to PATH" {
result=$(nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
let-env ASDF_NU_DIR = '$PWD'
source asdf.nu
\$env.PATH | to text
")
[ "$?" -eq 0 ]
output_bin=$(echo "$result" | grep "asdf/bin")
[ "$output_bin" == "$PWD/bin" ]
output_shims=$(echo "$result" | grep "/shims")
[ "$output_shims" == "$HOME/.asdf/shims" ]
}
@test "does not add paths to PATH more than once" {
result=$(nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
let-env ASDF_NU_DIR = '$PWD'
source asdf.nu
source asdf.nu
echo \$env.PATH
")
[ "$?" -eq 0 ]
output=$(echo $result | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$output" = "" ]
}
@test "retains ASDF_DIR" {
output=$(nu -c "
hide-env -i asdf
let-env ASDF_DIR = ( pwd )
let-env PATH = ( '$(cleaned_path)' | split row ':' )
let-env ASDF_NU_DIR = '$PWD'
source asdf.nu
echo \$env.ASDF_DIR
")
[ "$?" -eq 0 ]
[ "$output" = "$PWD" ]
}
@test "defines the asdf function" {
output=$(nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
let-env ASDF_NU_DIR = '$PWD'
source asdf.nu
which asdf | get path | to text
")
[ "$?" -eq 0 ]
[[ "$output" =~ "command" ]]
}
@test "function calls asdf command" {
result=$(nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
let-env ASDF_NU_DIR = '$PWD'
source asdf.nu
asdf info
")
[ "$?" -eq 0 ]
output=$(echo "$result" | grep "ASDF INSTALLED PLUGINS:")
[ "$output" != "" ]
}