Skip to content

Commit

Permalink
test: helpers: Add profile command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Gorny committed Sep 20, 2021
1 parent 9656b56 commit 7b7892d
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/fixtures/bash_it/profiles/test-bad-component.bash_it
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# plugins
plugins alias-completion
plugins base

# completion
completion bash-it
completion system

# aliases
aliases general
# Bad component
aliases bla
12 changes: 12 additions & 0 deletions test/fixtures/bash_it/profiles/test-bad-type.bash_it
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# plugins
plugins alias-completion
plugins base
# Bad type
pluugins alias-completion

# completion
completion bash-it
completion system

# aliases
aliases general
108 changes: 108 additions & 0 deletions test/lib/helpers.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@ load ../../lib/helpers

function local_setup {
setup_test_fixture

# Copy the test fixture to the Bash-it folder
if command -v rsync &> /dev/null; then
rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/"
else
find "$BASH_IT/test/fixtures/bash_it" \
-mindepth 1 -maxdepth 1 \
-exec cp -r {} "$BASH_IT/" \;
fi
}

# TODO Create global __is_enabled function
# TODO Create global __get_base_name function
# TODO Create global __get_enabled_name function
@test "bash-it: verify that the test fixture is available" {
assert_file_exist "$BASH_IT/profiles/test-bad-component.bash_it"
assert_file_exist "$BASH_IT/profiles/test-bad-type.bash_it"
}

@test "helpers: _command_exists function exists" {
run type -a _command_exists &> /dev/null
Expand Down Expand Up @@ -283,6 +296,101 @@ function local_setup {
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
}

@test "helper: profile load command sanity" {
run _bash-it-profile-load "default"

assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
assert_link_exist "$BASH_IT/enabled/350---system.completion.bash"
}

@test "helper: profile save command sanity" {
run _enable-plugin "nvm"

run _bash-it-profile-save "test"
assert_line -n 0 "Saving plugins configuration..."
assert_line -n 1 "Saving completion configuration..."
assert_line -n 2 "Saving aliases configuration..."
assert_line -n 3 "All done!"
}

@test "helper: profile save creates valid file with only plugin enabled" {
run _enable-plugin "nvm"

run _bash-it-profile-save "test"
run cat "$BASH_IT/profiles/test.bash_it"
assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!"
assert_line -n 1 "# plugins"
assert_line -n 2 "plugins nvm"
}

@test "helper: profile save creates valid file with only completion enabled" {
run _enable-completion "bash-it"

run _bash-it-profile-save "test"
run cat "$BASH_IT/profiles/test.bash_it"
assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!"
assert_line -n 1 "# completion"
assert_line -n 2 "completion bash-it"
}

@test "helper: profile save creates valid file with only aliases enabled" {
run _enable-alias "general"

run _bash-it-profile-save "test"
run cat "$BASH_IT/profiles/test.bash_it"
assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!"
assert_line -n 1 "# aliases"
assert_line -n 2 "aliases general"
}

@test "helper: profile edge case, empty configuration" {
run _bash-it-profile-save "test"
assert_line -n 3 "It seems like no configuration was enabled.."
assert_line -n 4 "Make sure to double check that this is the wanted behavior."

run _enable-alias "general"
run _enable-plugin "base"
run _enable-plugin "alias-completion"
run _enable-completion "bash-it"
run _enable-completion "system"

run _bash-it-profile-load "test"
assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash"
assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash"
assert_link_not_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
assert_link_not_exist "$BASH_IT/enabled/350---system.completion.bash"
}

@test "helper: profile save and load" {
run _enable-alias "general"
run _enable-plugin "base"
run _enable-plugin "alias-completion"
run _enable-completion "bash-it"
run _enable-completion "system"

run _bash-it-profile-save "test"
assert_success

run _disable-alias "general"
assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash"
run _bash-it-profile-load "test"
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
}

@test "helper: profile load corrupted profile file: bad component" {
run _bash-it-profile-load "test-bad-component"
assert_line -n 1 -p "Bad line(#12) in profile, aborting load..."
}

@test "helper: profile load corrupted profile file: bad subdirectory" {
run _bash-it-profile-load "test-bad-type"
assert_line -n 1 -p "Bad line(#5) in profile, aborting load..."
}

@test "helpers: migrate plugins and completions that share the same name" {
ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash
assert_link_exist "$BASH_IT/completion/enabled/350---dirs.completion.bash"
Expand Down

0 comments on commit 7b7892d

Please sign in to comment.