asdf
1#!/usr/bin/env bats
2
3load test_helpers
4
5# Helper function to handle sourcing of asdf.sh
6source_asdf_sh() {7. "$(dirname "$BATS_TEST_DIRNAME")/asdf.sh"8}
9
10cleaned_path() {11echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ':'12}
13
14@test "exports ASDF_DIR" {15output=$(16unset -f asdf17unset ASDF_DIR18PATH=$(cleaned_path)19
20source_asdf_sh
21echo "$ASDF_DIR"22)23
24result=$(echo "$output" | grep "asdf")25[ "$result" != "" ]26}
27
28@test "does not error if nounset is enabled" {29output=$(30unset -f asdf31unset ASDF_DIR32PATH=$(cleaned_path)33set -o nounset34
35source_asdf_sh
36echo "$ASDF_DIR"37)38
39result=$(echo "$output" | grep "asdf")40[ "$result" != "" ]41}
42
43@test "adds asdf dirs to PATH" {44output=$(45unset -f asdf46unset ASDF_DIR47PATH=$(cleaned_path)48
49source_asdf_sh
50echo "$PATH"51)52
53result=$(echo "$output" | grep "asdf")54[ "$result" != "" ]55}
56
57@test "does not add paths to PATH more than once" {58output=$(59unset -f asdf60unset ASDF_DIR61PATH=$(cleaned_path)62
63source_asdf_sh
64source_asdf_sh
65echo "$PATH"66)67
68result=$(echo "$output" | tr ':' '\n' | grep "asdf" | sort | uniq -d)69[ "$result" = "" ]70}
71
72@test "defines the asdf function" {73output=$(74unset -f asdf75unset ASDF_DIR76PATH=$(cleaned_path)77
78source_asdf_sh
79type asdf80)81
82[[ "$output" =~ "is a function" ]]83}
84
85@test "function calls asdf command" {86result=$(87unset -f asdf88ASDF_DIR=$PWD89PATH=$(cleaned_path)90
91source_asdf_sh
92asdf info
93)94
95output=$(echo "$result" | grep "ASDF INSTALLED PLUGINS:")96[ "$output" != "" ]97}
98