pull/2032/merge
John D Pell 2022-03-05 20:05:52 +00:00 committed by GitHub
commit 967338efeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 1739 additions and 1692 deletions

1
.gitattributes vendored
View File

@ -1,5 +1,6 @@
*.sh text eol=lf *.sh text eol=lf
*.bash text eol=lf *.bash text eol=lf
*.bats text eol=lf
# Docs allow trailing whitespaces # Docs allow trailing whitespaces
*.md whitespace=-blank-at-eol *.md whitespace=-blank-at-eol

View File

@ -19,9 +19,7 @@ repos:
hooks: hooks:
- id: git-check # Configure in .gitattributes - id: git-check # Configure in .gitattributes
- id: shellcheck - id: shellcheck
exclude: ".bats$"
- id: shfmt - id: shfmt
exclude: ".bats$"
- repo: https://github.com/Lucas-C/pre-commit-hooks - repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.7 rev: v1.1.7
hooks: hooks:
@ -38,10 +36,9 @@ repos:
types: [file] types: [file]
- id: dot-bash - id: dot-bash
name: Check .bash files against bash-it requirements name: Check .bash files against bash-it requirements
exclude: "test/test_helper.bash"
entry: ./hooks/dot-bash.sh entry: ./hooks/dot-bash.sh
language: system language: system
files: "\\.bash$" files: "\\.ba[ts][sh]$"
types: [file] types: [file]
- id: clean-files-txt - id: clean-files-txt
name: Check that clean_files.txt is sorted alphabetically. name: Check that clean_files.txt is sorted alphabetically.

View File

@ -20,6 +20,7 @@ aliases/
docs/ docs/
hooks/ hooks/
scripts/ scripts/
test/
# root files # root files
# #
@ -134,12 +135,6 @@ plugins/available/todo.plugin.bash
plugins/available/xterm.plugin.bash plugins/available/xterm.plugin.bash
plugins/available/zoxide.plugin.bash plugins/available/zoxide.plugin.bash
# tests
#
test/plugins/alias-completion.plugin.bats
test/run
test/test_helper.bash
# themes # themes
# #
themes/90210 themes/90210

View File

@ -12,7 +12,8 @@ for file in "$@"; do
# Confirm expected schellcheck header # Confirm expected schellcheck header
# #
LINE1="$(head -n 1 "${file}")" LINE1="$(head -n 1 "${file}")"
if [[ "${LINE1}" != "# shellcheck shell=bash" ]]; then SCSH="${file##*.}"
if [[ "${LINE1}" != "# shellcheck shell=${SCSH}" ]]; then
echo "Bash include file \`${file}\` has bad/missing shellcheck header" echo "Bash include file \`${file}\` has bad/missing shellcheck header"
exit_code=1 exit_code=1
fi fi

View File

@ -8,28 +8,29 @@ function local_setup_file() {
# don't load any libraries as the tests here test the *whole* kit # don't load any libraries as the tests here test the *whole* kit
} }
function local_setup() {
: "${PROMPT_COMMAND:=}" "${BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE:=}"
}
@test "bash-it: verify that the test fixture is available" { @test "bash-it: verify that the test fixture is available" {
assert_file_exist "$BASH_IT/aliases/available/a.aliases.bash" assert_file_exist "${BASH_IT?}/aliases/available/a.aliases.bash"
assert_file_exist "$BASH_IT/aliases/available/b.aliases.bash" assert_file_exist "${BASH_IT?}/aliases/available/b.aliases.bash"
} }
@test "bash-it: load aliases in order" { @test "bash-it: load aliases in order" {
mkdir -p $BASH_IT/aliases/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
mkdir -p $BASH_IT/plugins/enabled assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -37,22 +38,19 @@ function local_setup_file() {
} }
@test "bash-it: load aliases in priority order" { @test "bash-it: load aliases in priority order" {
mkdir -p $BASH_IT/aliases/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
mkdir -p $BASH_IT/plugins/enabled assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/175---a.aliases.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/175---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/175---a.aliases.bash assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/175---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -60,24 +58,21 @@ function local_setup_file() {
} }
@test "bash-it: load aliases and plugins in priority order" { @test "bash-it: load aliases and plugins in priority order" {
mkdir -p $BASH_IT/aliases/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
mkdir -p $BASH_IT/plugins/enabled assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -85,25 +80,21 @@ function local_setup_file() {
} }
@test "bash-it: load aliases, plugins and completions in priority order" { @test "bash-it: load aliases, plugins and completions in priority order" {
mkdir -p $BASH_IT/aliases/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
mkdir -p $BASH_IT/plugins/enabled assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
mkdir -p $BASH_IT/completion/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash"
assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -112,25 +103,21 @@ function local_setup_file() {
} }
@test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" { @test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" {
mkdir -p $BASH_IT/aliases/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
mkdir -p $BASH_IT/plugins/enabled assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
mkdir -p $BASH_IT/completion/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/450---a.aliases.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/450---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/450---a.aliases.bash assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash"
assert_link_exist "$BASH_IT/aliases/enabled/450---a.aliases.bash" ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/950---c.plugin.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash assert_link_exist "${BASH_IT?}/plugins/enabled/950---c.plugin.bash"
assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/950---c.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/950---c.plugin.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -139,24 +126,21 @@ function local_setup_file() {
} }
@test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" { @test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" {
mkdir -p $BASH_IT/aliases/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
mkdir -p $BASH_IT/plugins/enabled assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/350---a.aliases.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/350---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/350---a.aliases.bash assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/350---a.aliases.bash" ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -166,21 +150,19 @@ function local_setup_file() {
} }
@test "bash-it: load global aliases in order" { @test "bash-it: load global aliases in order" {
mkdir -p $BASH_IT/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash"
assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -188,21 +170,19 @@ function local_setup_file() {
} }
@test "bash-it: load global aliases in priority order" { @test "bash-it: load global aliases in priority order" {
mkdir -p $BASH_IT/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash"
assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/175---a.aliases.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/175---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/175---a.aliases.bash assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/enabled/175---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -210,23 +190,21 @@ function local_setup_file() {
} }
@test "bash-it: load global aliases and plugins in priority order" { @test "bash-it: load global aliases and plugins in priority order" {
mkdir -p $BASH_IT/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash"
assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash" ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash"
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -234,23 +212,21 @@ function local_setup_file() {
} }
@test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" { @test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" {
mkdir -p $BASH_IT/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash"
assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash"
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -260,27 +236,24 @@ function local_setup_file() {
} }
@test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" { @test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" {
mkdir -p $BASH_IT/enabled ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash"
mkdir -p $BASH_IT/aliases/enabled assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash"
ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash"
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash"
# Add one file in the old directory structure # Add one file in the old directory structure
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist # The `test_alias` alias should not exist
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias test_alias &> /dev/null run alias test_alias &> /dev/null
assert_success assert_success
@ -290,53 +263,48 @@ function local_setup_file() {
} }
@test "bash-it: load enabled aliases from new structure, priority-based" { @test "bash-it: load enabled aliases from new structure, priority-based" {
mkdir -p $BASH_IT/enabled ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/enabled/150---atom.aliases.bash"
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash assert_link_exist "${BASH_IT?}/enabled/150---atom.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
# The `ah` alias should not exist # The `ah` alias should not exist
run alias ah &> /dev/null run alias ah &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias ah &> /dev/null run alias ah &> /dev/null
assert_success assert_success
} }
@test "bash-it: load enabled aliases from old structure, priority-based" { @test "bash-it: load enabled aliases from old structure, priority-based" {
mkdir -p $BASH_IT/aliases/enabled ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash"
mkdir -p $BASH_IT/plugins/enabled assert_link_exist "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash"
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash"
# The `ah` alias should not exist # The `ah` alias should not exist
run alias ah &> /dev/null run alias ah &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias ah &> /dev/null run alias ah &> /dev/null
assert_success assert_success
} }
@test "bash-it: load enabled aliases from old structure, without priorities" { @test "bash-it: load enabled aliases from old structure, without priorities" {
mkdir -p $BASH_IT/aliases/enabled ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/atom.aliases.bash"
mkdir -p $BASH_IT/plugins/enabled assert_link_exist "${BASH_IT?}/aliases/enabled/atom.aliases.bash"
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/base.plugin.bash"
assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/base.plugin.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/base.plugin.bash"
# The `ah` alias should not exist # The `ah` alias should not exist
run alias ah &> /dev/null run alias ah &> /dev/null
assert_failure assert_failure
load "$BASH_IT/bash_it.sh" load "${BASH_IT?}/bash_it.sh"
run alias ah &> /dev/null run alias ah &> /dev/null
assert_success assert_success

View File

@ -26,5 +26,5 @@ function local_setup_file() {
alias rm='rm -v' alias rm='rm -v'
run load "${BASH_IT?}/completion/available/aliases.completion.bash" run load "${BASH_IT?}/completion/available/aliases.completion.bash"
refute_output assert_output ""
} }

View File

@ -13,11 +13,12 @@ function local_setup_file() {
assert_output "function" assert_output "function"
} }
function __check_completion () { function __check_completion() {
# Get the parameters as a single value # Get the parameters as a single value
COMP_LINE=$* COMP_LINE=$*
# Get the parameters as an array # Get the parameters as an array
# shellcheck disable=SC2294
eval set -- "$@" eval set -- "$@"
COMP_WORDS=("$@") COMP_WORDS=("$@")
@ -25,7 +26,7 @@ function __check_completion () {
COMP_POINT=${#COMP_LINE} COMP_POINT=${#COMP_LINE}
# Get the last character of the line that was entered # Get the last character of the line that was entered
COMP_LAST=$((${COMP_POINT} - 1)) COMP_LAST=$((COMP_POINT - 1))
# If the last character was a space... # If the last character was a space...
if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then
@ -34,7 +35,8 @@ function __check_completion () {
fi fi
# Word index of the last word # Word index of the last word
COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 )) COMP_CWORD=$((${#COMP_WORDS[@]} - 1))
COMP_WORDS+=('') # arg
# Run the Bash-it completion function # Run the Bash-it completion function
_bash-it _bash-it
@ -45,315 +47,318 @@ function __check_completion () {
@test "completion bash-it: doctor - show options" { @test "completion bash-it: doctor - show options" {
run __check_completion 'bash-it doctor ' run __check_completion 'bash-it doctor '
assert_line -n 0 "errors warnings all" assert_output "errors warnings all"
} }
@test "completion bash-it: help - show options" { @test "completion bash-it: help - show options" {
run __check_completion 'bash-it help ' run __check_completion 'bash-it help '
assert_line -n 0 "aliases completions migrate plugins update" assert_output "aliases completions migrate plugins update"
} }
@test "completion bash-it: help - aliases v" { @test "completion bash-it: help - aliases v" {
run __check_completion 'bash-it help aliases v' run __check_completion 'bash-it help aliases v'
assert_line -n 0 "vagrant vault vim" assert_output "vagrant vault vim"
} }
@test "completion bash-it: update - show options" { @test "completion bash-it: update - show options" {
run __check_completion 'bash-it update ' run __check_completion 'bash-it update '
assert_line -n 0 "stable dev" assert_output "stable dev"
} }
@test "completion bash-it: update - show optional flags" { @test "completion bash-it: update - show optional flags" {
run __check_completion 'bash-it update -' run __check_completion 'bash-it update -'
assert_line -n 0 "-s --silent" assert_output "-s --silent"
} }
@test "completion bash-it: search - show no options" { @test "completion bash-it: search - show no options" {
run __check_completion 'bash-it search ' run __check_completion 'bash-it search '
assert_line -n 0 "" assert_output ""
} }
@test "completion bash-it: migrate - show no options" { @test "completion bash-it: migrate - show no options" {
run __check_completion 'bash-it migrate ' run __check_completion 'bash-it migrate '
assert_line -n 0 "" assert_output ""
} }
@test "completion bash-it: show options" { @test "completion bash-it: show options" {
run __check_completion 'bash-it ' run __check_completion 'bash-it '
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" assert_output "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: bash-ti - show options" { @test "completion bash-it: bash-ti - show options" {
run __check_completion 'bash-ti ' run __check_completion 'bash-ti '
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" assert_output "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: shit - show options" { @test "completion bash-it: shit - show options" {
run __check_completion 'shit ' run __check_completion 'shit '
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" assert_output "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: bashit - show options" { @test "completion bash-it: bashit - show options" {
run __check_completion 'bashit ' run __check_completion 'bashit '
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" assert_output "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: batshit - show options" { @test "completion bash-it: batshit - show options" {
run __check_completion 'batshit ' run __check_completion 'batshit '
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" assert_output "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: bash_it - show options" { @test "completion bash-it: bash_it - show options" {
run __check_completion 'bash_it ' run __check_completion 'bash_it '
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" assert_output "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: profile - show options" { @test "completion bash-it: profile - show options" {
run __check_completion 'bash-it profile ' run __check_completion 'bash-it profile '
assert_line -n 0 "load save list rm" assert_output "load save list rm"
} }
@test "completion bash-it: profile load - show options" { @test "completion bash-it: profile load - show options" {
run __check_completion 'bash-it profile load ' run __check_completion 'bash-it profile load '
assert_line -n 0 "default" assert_output "default"
} }
@test "completion bash-it: show - show options" { @test "completion bash-it: show - show options" {
run __check_completion 'bash-it show ' run __check_completion 'bash-it show '
assert_line -n 0 "aliases completions plugins" assert_output "aliases completions plugins"
} }
@test "completion bash-it: enable - show options" { @test "completion bash-it: enable - show options" {
run __check_completion 'bash-it enable ' run __check_completion 'bash-it enable '
assert_line -n 0 "alias completion plugin" assert_output "alias completion plugin"
} }
@test "completion bash-it: enable - show options a" { @test "completion bash-it: enable - show options a" {
run __check_completion 'bash-it enable a' run __check_completion 'bash-it enable a'
assert_line -n 0 "alias" assert_output "alias"
} }
@test "completion bash-it: disable - show options" { @test "completion bash-it: disable - show options" {
run __check_completion 'bash-it disable ' run __check_completion 'bash-it disable '
assert_line -n 0 "alias completion plugin" assert_output "alias completion plugin"
} }
@test "completion bash-it: disable - show options a" { @test "completion bash-it: disable - show options a" {
run __check_completion 'bash-it disable a' run __check_completion 'bash-it disable a'
assert_line -n 0 "alias" assert_output "alias"
} }
@test "completion bash-it: disable - provide nothing when atom is not enabled" { @test "completion bash-it: disable - provide nothing when atom is not enabled" {
run __check_completion 'bash-it disable alias ato' run __check_completion 'bash-it disable alias ato'
assert_line -n 0 "" assert_output ""
} }
@test "completion bash-it: disable - provide all when atom is not enabled" { @test "completion bash-it: disable - provide 'all' when atom is not enabled" {
run __check_completion 'bash-it disable alias a' run __check_completion 'bash-it disable alias a'
assert_line -n 0 "all" assert_output "all"
} }
@test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" { @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" {
ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash"
ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash" run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash"
assert_link_exist "$BASH_IT/completion/enabled/apm.completion.bash" assert_link_exist "$BASH_IT/completion/enabled/apm.completion.bash"
run _bash-it-component-item-is-enabled "alias" "atom"
assert_success
run __check_completion 'bash-it disable alias a' run __check_completion 'bash-it disable alias a'
assert_line -n 0 "all atom" assert_output "all atom"
} }
@test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" { @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" {
ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash"
ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash"
assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash"
run __check_completion 'bash-it disable alias a' run __check_completion 'bash-it disable alias a'
assert_line -n 0 "all atom" assert_output "all atom"
} }
@test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" { @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" {
ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash"
ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash"
assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash"
run __check_completion 'bash-it disable alias a' run __check_completion 'bash-it disable alias a'
assert_line -n 0 "all atom" assert_output "all atom"
} }
@test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" { @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" {
ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash"
ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/docker-machine.plugin.bash"
run __check_completion 'bash-it disable plugin docker' run __check_completion 'bash-it disable plugin docker'
assert_line -n 0 "docker-machine" assert_output "docker-machine"
} }
@test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" { @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" {
ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash"
run __check_completion 'bash-it disable plugin docker' run __check_completion 'bash-it disable plugin docker'
assert_line -n 0 "docker-machine" assert_output "docker-machine"
} }
@test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" { @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" {
ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash"
ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash"
assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash"
run __check_completion 'bash-it disable plugin docker' run __check_completion 'bash-it disable plugin docker'
assert_line -n 0 "docker-machine" assert_output "docker-machine"
} }
@test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" {
ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash"
ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash"
run __check_completion 'bash-it disable alias to' run __check_completion 'bash-it disable alias to'
assert_line -n 0 "todo.txt-cli" assert_output "todo.txt-cli"
} }
@test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" {
ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash"
ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash"
run __check_completion 'bash-it disable alias to' run __check_completion 'bash-it disable alias to'
assert_line -n 0 "todo.txt-cli" assert_output "todo.txt-cli"
} }
@test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" {
ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash"
assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash"
run __check_completion 'bash-it disable alias to' run __check_completion 'bash-it disable alias to'
assert_line -n 0 "todo.txt-cli" assert_output "todo.txt-cli"
} }
@test "completion bash-it: enable - provide the atom aliases when not enabled" { @test "completion bash-it: enable - provide the atom aliases when not enabled" {
run __check_completion 'bash-it enable alias ato' run __check_completion 'bash-it enable alias ato'
assert_line -n 0 "atom" assert_output "atom"
} }
@test "completion bash-it: enable - provide the a* aliases when not enabled" { @test "completion bash-it: enable - provide the a* aliases when not enabled" {
run __check_completion 'bash-it enable alias a' run __check_completion 'bash-it enable alias a'
assert_line -n 0 "all ag ansible apt atom" assert_output "all ag ansible apt atom"
} }
@test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" { @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" {
ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash"
run __check_completion 'bash-it enable alias a' run __check_completion 'bash-it enable alias a'
assert_line -n 0 "all ag ansible apt" assert_output "all ag ansible apt"
} }
@test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" { @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" {
ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash"
run __check_completion 'bash-it enable alias a' run __check_completion 'bash-it enable alias a'
assert_line -n 0 "all ag ansible apt" assert_output "all ag ansible apt"
} }
@test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" { @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" {
ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash"
run __check_completion 'bash-it enable alias a' run __check_completion 'bash-it enable alias a'
assert_line -n 0 "all ag ansible apt" assert_output "all ag ansible apt"
} }
@test "completion bash-it: enable - provide the docker* plugins when docker-compose is enabled with the old location and name" { @test "completion bash-it: enable - provide the docker* plugins when docker-compose is enabled with the old location and name" {
ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash"
run __check_completion 'bash-it enable plugin docker' run __check_completion 'bash-it enable plugin docker'
assert_line -n 0 "docker docker-compose docker-machine" assert_output "docker docker-compose docker-machine"
} }
@test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the old location and priority-based name" { @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the old location and priority-based name" {
ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
run __check_completion 'bash-it enable plugin docker' run __check_completion 'bash-it enable plugin docker'
assert_line -n 0 "docker docker-compose docker-machine" assert_output "docker docker-compose docker-machine"
} }
@test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the new location and priority-based name" { @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the new location and priority-based name" {
ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash"
run __check_completion 'bash-it enable plugin docker' run __check_completion 'bash-it enable plugin docker'
assert_line -n 0 "docker docker-compose docker-machine" assert_output "docker docker-compose docker-machine"
} }
@test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and name" { @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and name" {
ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash"
run __check_completion 'bash-it enable completion docker' run __check_completion 'bash-it enable completion docker'
assert_line -n 0 "docker docker-compose docker-machine" assert_output "docker docker-compose docker-machine"
} }
@test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and priority-based name" { @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and priority-based name" {
ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
run __check_completion 'bash-it enable completion docker' run __check_completion 'bash-it enable completion docker'
assert_line -n 0 "docker docker-compose docker-machine" assert_output "docker docker-compose docker-machine"
} }
@test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the new location and priority-based name" { @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the new location and priority-based name" {
ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash"
run __check_completion 'bash-it enable completion docker' run __check_completion 'bash-it enable completion docker'
assert_line -n 0 "docker docker-compose docker-machine" assert_output "docker docker-compose docker-machine"
} }
@test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" {
ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash"
run __check_completion 'bash-it enable alias to' run __check_completion 'bash-it enable alias to'
assert_line -n 0 "todo.txt-cli" assert_output "todo.txt-cli"
} }
@test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" {
ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash"
run __check_completion 'bash-it enable alias to' run __check_completion 'bash-it enable alias to'
assert_line -n 0 "todo.txt-cli" assert_output "todo.txt-cli"
} }
@test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" {
ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash"
assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash"
run __check_completion 'bash-it enable alias to' run __check_completion 'bash-it enable alias to'
assert_line -n 0 "todo.txt-cli" assert_output "todo.txt-cli"
} }

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash # shellcheck shell=bash
alias test_alias="a" alias test_alias="a"

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash # shellcheck shell=bash
alias test_alias="b" alias test_alias="b"

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash # shellcheck shell=bash
alias test_alias="c" alias test_alias="c"

View File

@ -3,7 +3,7 @@
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
function local_setup() { function local_setup() {
export HOME="$BATS_TEST_TMPDIR" export HOME="${BATS_TEST_TMPDIR?}"
} }
function local_setup_file() { function local_setup_file() {
@ -20,7 +20,7 @@ function local_setup_file() {
} }
@test "install: verify that the install script exists" { @test "install: verify that the install script exists" {
assert_file_exist "$BASH_IT/install.sh" assert_file_exist "${BASH_IT?}/install.sh"
} }
@test "install: run the install script silently" { @test "install: run the install script silently" {
@ -30,26 +30,27 @@ function local_setup_file() {
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" 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/250---base.plugin.bash"
assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash"
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash"
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash"
} }
@test "install: verify that a backup file is created" { @test "install: verify that a backup file is created" {
cd "$BASH_IT" local md5_orig md5_bak
cd "${BASH_IT?}"
touch "$HOME/$BASH_IT_CONFIG_FILE" touch "$HOME/$BASH_IT_CONFIG_FILE"
echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE"
local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
./install.sh --silent ./install.sh --silent
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
assert_equal "$md5_orig" "$md5_bak" assert_equal "$md5_orig" "$md5_bak"
} }

View File

@ -3,7 +3,7 @@
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
function local_setup() { function local_setup() {
export HOME="$BATS_TEST_TMPDIR" export HOME="${BATS_TEST_TMPDIR?}"
} }
function local_setup_file() { function local_setup_file() {
@ -20,15 +20,16 @@ function local_setup_file() {
} }
@test "uninstall: verify that the uninstall script exists" { @test "uninstall: verify that the uninstall script exists" {
assert_file_exist "$BASH_IT/uninstall.sh" assert_file_exist "${BASH_IT?}/uninstall.sh"
} }
@test "uninstall: run the uninstall script with an existing backup file" { @test "uninstall: run the uninstall script with an existing backup file" {
cd "$BASH_IT" local md5_bak md5_conf
cd "${BASH_IT?}"
echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak" echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak"
echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
run ./uninstall.sh run ./uninstall.sh
assert_success assert_success
@ -37,16 +38,17 @@ function local_setup_file() {
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
assert_equal "$md5_bak" "$md5_conf" assert_equal "$md5_bak" "$md5_conf"
} }
@test "uninstall: run the uninstall script without an existing backup file" { @test "uninstall: run the uninstall script without an existing backup file" {
cd "$BASH_IT" local md5_orig md5_uninstall
cd "${BASH_IT?}"
echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
run ./uninstall.sh run ./uninstall.sh
assert_success assert_success
@ -55,7 +57,7 @@ function local_setup_file() {
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE"
local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
assert_equal "$md5_orig" "$md5_uninstall" assert_equal "$md5_orig" "$md5_uninstall"
} }

View File

@ -4,25 +4,26 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
function local_setup_file() { function local_setup_file() {
setup_libs "colors" setup_libs "colors"
load "${BASH_IT?}/plugins/available/base.plugin.bash"
} }
function local_setup() { function local_setup() {
: "${BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE:=}"
# Copy the test fixture to the Bash-it folder # Copy the test fixture to the Bash-it folder
cp -RP "$BASH_IT/test/fixtures/bash_it"/* "$BASH_IT/" cp -RP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/"
} }
# TODO Create global __is_enabled function # TODO Create global __is_enabled function
# TODO Create global __get_base_name function # TODO Create global __get_base_name function
# TODO Create global __get_enabled_name function # TODO Create global __get_enabled_name function
@test "bash-it: verify that the test fixture is available" { @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-component.bash_it"
assert_file_exist "$BASH_IT/profiles/test-bad-type.bash_it" assert_file_exist "${BASH_IT?}/profiles/test-bad-type.bash_it"
} }
@test "helpers: _command_exists function exists" { @test "helpers: _command_exists function exists" {
run type -a _command_exists &> /dev/null run type -t _command_exists
assert_success assert_success
assert_output "function"
} }
@test "helpers: _command_exists function positive test ls" { @test "helpers: _command_exists function positive test ls" {
@ -41,8 +42,9 @@ function local_setup() {
} }
@test "helpers: _binary_exists function exists" { @test "helpers: _binary_exists function exists" {
run type -a _binary_exists &> /dev/null run type -t _binary_exists
assert_success assert_success
assert_output "function"
} }
@test "helpers: _binary_exists function positive test ls" { @test "helpers: _binary_exists function positive test ls" {
@ -67,54 +69,54 @@ function local_setup() {
@test "helpers: bash-it help aliases without any aliases enabled" { @test "helpers: bash-it help aliases without any aliases enabled" {
run bash-it help aliases run bash-it help aliases
assert_line -n 0 "" assert_output ""
} }
@test "helpers: bash-it help plugins" { @test "helpers: bash-it help plugins" {
run bash-it help plugins run bash-it help plugins
assert_line -n 1 "base:" assert_line -n 1 "composure:"
} }
@test "helpers: bash-it help list aliases without any aliases enabled" { @test "helpers: bash-it help list aliases without any aliases enabled" {
run _help-list-aliases "$BASH_IT/aliases/available/ag.aliases.bash" run _help-list-aliases "${BASH_IT?}/aliases/available/ag.aliases.bash"
assert_line -n 0 "ag:" assert_line -n 0 "ag:"
} }
@test "helpers: bash-it help list aliases with ag aliases enabled" { @test "helpers: bash-it help list aliases with ag aliases enabled" {
ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash"
run _help-list-aliases "$BASH_IT/aliases/enabled/150---ag.aliases.bash" run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash"
assert_line -n 0 "ag:" assert_line -n 0 "ag:"
} }
@test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" { @test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" {
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash"
run _help-list-aliases "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash"
assert_line -n 0 "todo.txt-cli:" assert_line -n 0 "todo.txt-cli:"
} }
@test "helpers: bash-it help list aliases with docker-compose aliases enabled" { @test "helpers: bash-it help list aliases with docker-compose aliases enabled" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash ln -s "${BASH_IT?}/aliases/available/docker-compose.aliases.bash" "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash"
run _help-list-aliases "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash"
assert_line -n 0 "docker-compose:" assert_line -n 0 "docker-compose:"
} }
@test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { @test "helpers: bash-it help list aliases with ag aliases enabled in global directory" {
ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/enabled/150---ag.aliases.bash ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/enabled/150---ag.aliases.bash"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
run _help-list-aliases "$BASH_IT/enabled/150---ag.aliases.bash" run _help-list-aliases "${BASH_IT?}/enabled/150---ag.aliases.bash"
assert_line -n 0 "ag:" assert_line -n 0 "ag:"
} }
@test "helpers: bash-it help aliases one alias enabled in the old directory" { @test "helpers: bash-it help aliases one alias enabled in the old directory" {
ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash"
run bash-it help aliases run bash-it help aliases
assert_line -n 0 "ag:" assert_line -n 0 "ag:"
@ -123,11 +125,11 @@ function local_setup() {
@test "helpers: bash-it help aliases one alias enabled in global directory" { @test "helpers: bash-it help aliases one alias enabled in global directory" {
run bash-it enable alias "ag" run bash-it enable alias "ag"
assert_line -n 0 'ag enabled with priority 150.' assert_line -n 0 'ag enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
run bash-it enable plugin "aws" run bash-it enable plugin "aws"
assert_line -n 0 'aws enabled with priority 250.' assert_line -n 0 'aws enabled with priority 250.'
assert_link_exist "$BASH_IT/enabled/250---aws.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---aws.plugin.bash"
run bash-it help aliases run bash-it help aliases
assert_line -n 0 "ag:" assert_line -n 0 "ag:"
@ -137,58 +139,58 @@ function local_setup() {
@test "helpers: enable the todo.txt-cli aliases through the bash-it function" { @test "helpers: enable the todo.txt-cli aliases through the bash-it function" {
run bash-it enable alias "todo.txt-cli" run bash-it enable alias "todo.txt-cli"
assert_line -n 0 'todo.txt-cli enabled with priority 150.' assert_line -n 0 'todo.txt-cli enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash"
} }
@test "helpers: enable the curl aliases" { @test "helpers: enable the curl aliases" {
run _enable-alias "curl" run _enable-alias "curl"
assert_line -n 0 'curl enabled with priority 150.' assert_line -n 0 'curl enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/150---curl.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---curl.aliases.bash"
} }
@test "helpers: enable the apm completion through the bash-it function" { @test "helpers: enable the apm completion through the bash-it function" {
run bash-it enable completion "apm" run bash-it enable completion "apm"
assert_line -n 0 'apm enabled with priority 350.' assert_line -n 0 'apm enabled with priority 350.'
assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" assert_link_exist "${BASH_IT?}/enabled/350---apm.completion.bash"
} }
@test "helpers: enable the brew completion" { @test "helpers: enable the brew completion" {
run _enable-completion "brew" run _enable-completion "brew"
assert_line -n 0 'brew enabled with priority 375.' assert_line -n 0 'brew enabled with priority 375.'
assert_link_exist "$BASH_IT/enabled/375---brew.completion.bash" assert_link_exist "${BASH_IT?}/enabled/375---brew.completion.bash"
} }
@test "helpers: enable the node plugin" { @test "helpers: enable the node plugin" {
run _enable-plugin "node" run _enable-plugin "node"
assert_line -n 0 'node enabled with priority 250.' assert_line -n 0 'node enabled with priority 250.'
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash"
} }
@test "helpers: enable the node plugin through the bash-it function" { @test "helpers: enable the node plugin through the bash-it function" {
run bash-it enable plugin "node" run bash-it enable plugin "node"
assert_line -n 0 'node enabled with priority 250.' assert_line -n 0 'node enabled with priority 250.'
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash"
} }
@test "helpers: enable the node and nvm plugins through the bash-it function" { @test "helpers: enable the node and nvm plugins through the bash-it function" {
run bash-it enable plugin "node" "nvm" run bash-it enable plugin "node" "nvm"
assert_line -n 0 'node enabled with priority 250.' assert_line -n 0 'node enabled with priority 250.'
assert_line -n 1 'nvm enabled with priority 225.' assert_line -n 1 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
} }
@test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" { @test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" {
run bash-it enable plugin "foo-unknown" "nvm" run bash-it enable plugin "foo-unknown" "nvm"
assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.' assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.'
assert_line -n 1 'nvm enabled with priority 225.' assert_line -n 1 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
} }
@test "helpers: enable the nvm plugin" { @test "helpers: enable the nvm plugin" {
run _enable-plugin "nvm" run _enable-plugin "nvm"
assert_line -n 0 'nvm enabled with priority 225.' assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
} }
@test "helpers: enable an unknown plugin" { @test "helpers: enable an unknown plugin" {
@ -196,11 +198,11 @@ function local_setup() {
assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.'
# Check for both old an new structure # Check for both old an new structure
assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ]
} }
@test "helpers: enable an unknown plugin through the bash-it function" { @test "helpers: enable an unknown plugin through the bash-it function" {
@ -209,11 +211,11 @@ function local_setup() {
assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.'
# Check for both old an new structure # Check for both old an new structure
assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ]
} }
@test "helpers: disable a plugin that is not enabled" { @test "helpers: disable a plugin that is not enabled" {
@ -224,75 +226,75 @@ function local_setup() {
@test "helpers: enable and disable the nvm plugin" { @test "helpers: enable and disable the nvm plugin" {
run _enable-plugin "nvm" run _enable-plugin "nvm"
assert_line -n 0 'nvm enabled with priority 225.' assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ]
run _disable-plugin "nvm" run _disable-plugin "nvm"
assert_line -n 0 'nvm disabled.' assert_line -n 0 'nvm disabled.'
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ]
} }
@test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { @test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ]
run _disable-plugin "nvm" run _disable-plugin "nvm"
assert_line -n 0 'nvm disabled.' assert_line -n 0 'nvm disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ]
} }
@test "helpers: disable the nvm plugin if it was enabled without a priority" { @test "helpers: disable the nvm plugin if it was enabled without a priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
run _disable-plugin "nvm" run _disable-plugin "nvm"
assert_line -n 0 'nvm disabled.' assert_line -n 0 'nvm disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ]
} }
@test "helpers: enable the nvm plugin if it was enabled without a priority" { @test "helpers: enable the nvm plugin if it was enabled without a priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
run _enable-plugin "nvm" run _enable-plugin "nvm"
assert_line -n 0 'nvm is already enabled.' assert_line -n 0 'nvm is already enabled.'
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ]
} }
@test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { @test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash"
run _enable-plugin "nvm" run _enable-plugin "nvm"
assert_line -n 0 'nvm is already enabled.' assert_line -n 0 'nvm is already enabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ]
} }
@test "helpers: enable the nvm plugin twice" { @test "helpers: enable the nvm plugin twice" {
run _enable-plugin "nvm" run _enable-plugin "nvm"
assert_line -n 0 'nvm enabled with priority 225.' assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
run _enable-plugin "nvm" run _enable-plugin "nvm"
assert_line -n 0 'nvm is already enabled.' assert_line -n 0 'nvm is already enabled.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
} }
@test "helpers: profile load command sanity" { @test "helpers: profile load command sanity" {
run _bash-it-profile-load "default" run _bash-it-profile-load "default"
assert_success assert_success
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" 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/250---base.plugin.bash"
assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash"
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash"
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash"
} }
@test "helpers: profile save command sanity" { @test "helpers: profile save command sanity" {
@ -303,14 +305,14 @@ function local_setup() {
assert_line -n 1 "Saving completion configuration..." assert_line -n 1 "Saving completion configuration..."
assert_line -n 2 "Saving aliases configuration..." assert_line -n 2 "Saving aliases configuration..."
assert_line -n 3 "All done!" assert_line -n 3 "All done!"
assert_file_exist "$BASH_IT/profiles/test.bash_it" assert_file_exist "${BASH_IT?}/profiles/test.bash_it"
} }
@test "helpers: profile save creates valid file with only plugin enabled" { @test "helpers: profile save creates valid file with only plugin enabled" {
run _enable-plugin "nvm" run _enable-plugin "nvm"
run _bash-it-profile-save "test" run _bash-it-profile-save "test"
run cat "$BASH_IT/profiles/test.bash_it" 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 0 "# This file is auto generated by Bash-it. Do not edit manually!"
assert_line -n 1 "# plugins" assert_line -n 1 "# plugins"
assert_line -n 2 "plugins nvm" assert_line -n 2 "plugins nvm"
@ -320,7 +322,7 @@ function local_setup() {
run _enable-completion "bash-it" run _enable-completion "bash-it"
run _bash-it-profile-save "test" run _bash-it-profile-save "test"
run cat "$BASH_IT/profiles/test.bash_it" 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 0 "# This file is auto generated by Bash-it. Do not edit manually!"
assert_line -n 1 "# completion" assert_line -n 1 "# completion"
assert_line -n 2 "completion bash-it" assert_line -n 2 "completion bash-it"
@ -330,7 +332,7 @@ function local_setup() {
run _enable-alias "general" run _enable-alias "general"
run _bash-it-profile-save "test" run _bash-it-profile-save "test"
run cat "$BASH_IT/profiles/test.bash_it" 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 0 "# This file is auto generated by Bash-it. Do not edit manually!"
assert_line -n 1 "# aliases" assert_line -n 1 "# aliases"
assert_line -n 2 "aliases general" assert_line -n 2 "aliases general"
@ -338,37 +340,53 @@ function local_setup() {
@test "helpers: profile edge case, empty configuration" { @test "helpers: profile edge case, empty configuration" {
run _bash-it-profile-save "test" run _bash-it-profile-save "test"
assert_success
assert_line -n 3 "It seems like no configuration was enabled.." 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." assert_line -n 4 "Make sure to double check that this is the wanted behavior."
run _enable-alias "general" run _enable-alias "general"
assert_success
run _enable-plugin "base" run _enable-plugin "base"
run _enable-plugin "alias-completion" assert_success
run _enable-completion "aliases"
assert_success
run _enable-completion "bash-it" run _enable-completion "bash-it"
assert_success
run _enable-completion "system" run _enable-completion "system"
assert_success
run _bash-it-profile-load "test" run _bash-it-profile-load "test"
assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_success
assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash" assert_line -n 0 "Trying to parse profile 'test'..."
assert_link_not_exist "$BASH_IT/enabled/800---aliases.completion.bash" assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash"
assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash" assert_link_not_exist "${BASH_IT?}/enabled/250---base.plugin.bash"
assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash" assert_link_not_exist "${BASH_IT?}/enabled/800---aliases.completion.bash"
assert_link_not_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash"
assert_link_not_exist "${BASH_IT?}/enabled/325---system.completion.bash"
} }
@test "helpers: profile save and load" { @test "helpers: profile save and load" {
run _enable-alias "general" run _enable-alias "general"
assert_success
run _enable-plugin "base" run _enable-plugin "base"
assert_success
run _enable-plugin "alias-completion" run _enable-plugin "alias-completion"
assert_success
run _enable-completion "bash-it" run _enable-completion "bash-it"
assert_success
run _enable-completion "system" run _enable-completion "system"
assert_success
run _bash-it-profile-save "test" run _bash-it-profile-save "test"
assert_success assert_success
run _disable-alias "general" run _disable-alias "general"
assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_success
assert_output "general disabled."
assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash"
run _bash-it-profile-load "test" run _bash-it-profile-load "test"
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_success
assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash"
} }
@test "helpers: profile load corrupted profile file: bad component" { @test "helpers: profile load corrupted profile file: bad component" {
@ -383,10 +401,10 @@ function local_setup() {
@test "helpers: profile rm sanity" { @test "helpers: profile rm sanity" {
run _bash-it-profile-save "test" run _bash-it-profile-save "test"
assert_file_exist "$BASH_IT/profiles/test.bash_it" assert_file_exist "${BASH_IT?}/profiles/test.bash_it"
run _bash-it-profile-rm "test" run _bash-it-profile-rm "test"
assert_line -n 0 "Removed profile 'test' successfully!" assert_line -n 0 "Removed profile 'test' successfully!"
assert_file_not_exist "$BASH_IT/profiles/test.bash_it" assert_file_not_exist "${BASH_IT?}/profiles/test.bash_it"
} }
@test "helpers: profile rm no params" { @test "helpers: profile rm no params" {
@ -402,7 +420,7 @@ function local_setup() {
@test "helpers: profile rm default" { @test "helpers: profile rm default" {
run _bash-it-profile-rm "default" run _bash-it-profile-rm "default"
assert_line -n 0 -p "Can not remove the default profile..." assert_line -n 0 -p "Can not remove the default profile..."
assert_file_exist "$BASH_IT/profiles/default.bash_it" assert_file_exist "${BASH_IT?}/profiles/default.bash_it"
} }
@test "helpers: profile rm bad profile name" { @test "helpers: profile rm bad profile name" {
@ -429,11 +447,11 @@ function local_setup() {
} }
@test "helpers: migrate plugins and completions that share the same name" { @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 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" assert_link_exist "${BASH_IT?}/completion/enabled/350---dirs.completion.bash"
ln -s $BASH_IT/plugins/available/dirs.plugin.bash $BASH_IT/plugins/enabled/250---dirs.plugin.bash ln -s "${BASH_IT?}/plugins/available/dirs.plugin.bash" "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---dirs.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash"
run _bash-it-migrate run _bash-it-migrate
assert_line -n 0 'Migrating plugin dirs.' assert_line -n 0 'Migrating plugin dirs.'
@ -444,60 +462,60 @@ function local_setup() {
assert_line -n 5 'dirs enabled with priority 350.' assert_line -n 5 'dirs enabled with priority 350.'
assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate'
assert_link_exist "$BASH_IT/enabled/350---dirs.completion.bash" assert_link_exist "${BASH_IT?}/enabled/350---dirs.completion.bash"
assert_link_exist "$BASH_IT/enabled/250---dirs.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---dirs.plugin.bash"
assert [ ! -L "$BASH_IT/completion/enabled/350----dirs.completion.bash" ] assert [ ! -L "${BASH_IT?}/completion/enabled/350----dirs.completion.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/250----dirs.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/250----dirs.plugin.bash" ]
} }
@test "helpers: migrate enabled plugins that don't use the new priority-based configuration" { @test "helpers: migrate enabled plugins that don't use the new priority-based configuration" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash"
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash"
run _enable-plugin "ssh" run _enable-plugin "ssh"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash"
run _bash-it-migrate run _bash-it-migrate
assert_line -n 0 'Migrating alias todo.txt-cli.' assert_line -n 0 'Migrating alias todo.txt-cli.'
assert_line -n 1 'todo.txt-cli disabled.' assert_line -n 1 'todo.txt-cli disabled.'
assert_line -n 2 'todo.txt-cli enabled with priority 150.' assert_line -n 2 'todo.txt-cli enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash"
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/node.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] assert [ ! -L "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" ]
} }
@test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" { @test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash"
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash"
assert_link_exist "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash"
run _enable-plugin "ssh" run _enable-plugin "ssh"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash"
run _bash-it-migrate run _bash-it-migrate
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash"
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/225----node.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/250----nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ] assert [ ! -L "${BASH_IT?}/aliases/enabled/250----todo.txt-cli.aliases.bash" ]
} }
@test "helpers: run the migrate command without anything to migrate and nothing enabled" { @test "helpers: run the migrate command without anything to migrate and nothing enabled" {
@ -506,28 +524,27 @@ function local_setup() {
@test "helpers: run the migrate command without anything to migrate" { @test "helpers: run the migrate command without anything to migrate" {
run _enable-plugin "ssh" run _enable-plugin "ssh"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash"
run _bash-it-migrate run _bash-it-migrate
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash"
} }
function __migrate_all_components() { function __migrate_all_components() {
subdirectory="$1" subdirectory="${1:-}"
one_type="$2" one_type="${2:-}"
priority="$3" priority="${3:-}"
for f in "${BASH_IT}/$subdirectory/available/"*.bash for f in "${BASH_IT}/$subdirectory/available/"*.bash; do
do to_enable=$(basename "$f")
to_enable=$(basename $f) if [[ -z "$priority" ]]; then
if [ -z "$priority" ]; then
ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable" ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable"
else else
ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$priority---$to_enable" ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$priority---$to_enable"
fi fi
done done
ls ${BASH_IT}/${subdirectory}/enabled ls "${BASH_IT?}/${subdirectory}/enabled"
all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l | xargs) all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l | xargs)
all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs)
@ -547,47 +564,53 @@ function __migrate_all_components() {
subdirectory="plugins" subdirectory="plugins"
one_type="plugin" one_type="plugin"
__migrate_all_components "$subdirectory" "$one_type" run __migrate_all_components "$subdirectory" "$one_type"
assert_success
} }
@test "helpers: migrate all aliases" { @test "helpers: migrate all aliases" {
subdirectory="aliases" subdirectory="aliases"
one_type="aliases" one_type="aliases"
__migrate_all_components "$subdirectory" "$one_type" run __migrate_all_components "$subdirectory" "$one_type"
assert_success
} }
@test "helpers: migrate all completions" { @test "helpers: migrate all completions" {
subdirectory="completion" subdirectory="completion"
one_type="completion" one_type="completion"
__migrate_all_components "$subdirectory" "$one_type" run __migrate_all_components "$subdirectory" "$one_type"
assert_success
} }
@test "helpers: migrate all plugins with previous priority" { @test "helpers: migrate all plugins with previous priority" {
subdirectory="plugins" subdirectory="plugins"
one_type="plugin" one_type="plugin"
__migrate_all_components "$subdirectory" "$one_type" "100" run __migrate_all_components "$subdirectory" "$one_type" "100"
assert_success
} }
@test "helpers: migrate all aliases with previous priority" { @test "helpers: migrate all aliases with previous priority" {
subdirectory="aliases" subdirectory="aliases"
one_type="aliases" one_type="aliases"
__migrate_all_components "$subdirectory" "$one_type" "100" run __migrate_all_components "$subdirectory" "$one_type" "100"
assert_success
} }
@test "helpers: migrate all completions with previous priority" { @test "helpers: migrate all completions with previous priority" {
subdirectory="completion" subdirectory="completion"
one_type="completion" one_type="completion"
__migrate_all_components "$subdirectory" "$one_type" "100" run __migrate_all_components "$subdirectory" "$one_type" "100"
assert_success
} }
@test "helpers: verify that existing components are automatically migrated when something is enabled" { @test "helpers: verify that existing components are automatically migrated when something is enabled" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
run bash-it enable plugin "node" run bash-it enable plugin "node"
assert_line -n 0 'Migrating plugin nvm.' assert_line -n 0 'Migrating plugin nvm.'
@ -595,16 +618,16 @@ function __migrate_all_components() {
assert_line -n 2 'nvm enabled with priority 225.' assert_line -n 2 'nvm enabled with priority 225.'
assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate'
assert_line -n 4 'node enabled with priority 250.' assert_line -n 4 'node enabled with priority 250.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash"
} }
@test "helpers: verify that existing components are automatically migrated when something is disabled" { @test "helpers: verify that existing components are automatically migrated when something is disabled" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash"
run bash-it disable plugin "node" run bash-it disable plugin "node"
assert_line -n 0 'Migrating plugin node.' assert_line -n 0 'Migrating plugin node.'
@ -615,89 +638,94 @@ function __migrate_all_components() {
assert_line -n 5 'nvm enabled with priority 225.' assert_line -n 5 'nvm enabled with priority 225.'
assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate'
assert_line -n 7 'node disabled.' assert_line -n 7 'node disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ] assert [ ! -L "${BASH_IT?}/enabled/250---node.plugin.bash" ]
} }
@test "helpers: enable all plugins" { @test "helpers: enable all plugins" {
local available enabled
run _enable-plugin "all" run _enable-plugin "all"
local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs)
local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs)
assert_equal "$available" "$enabled" assert_equal "$available" "$enabled"
} }
@test "helpers: disable all plugins" { @test "helpers: disable all plugins" {
local available enabled enabled2
run _enable-plugin "all" run _enable-plugin "all"
local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs)
local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs)
assert_equal "$available" "$enabled" assert_equal "$available" "$enabled"
run _enable-alias "ag" run _enable-alias "ag"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
run _disable-plugin "all" run _disable-plugin "all"
local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs)
assert_equal "0" "$enabled2" assert_equal "0" "$enabled2"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
} }
@test "helpers: disable all plugins in the old directory structure" { @test "helpers: disable all plugins in the old directory structure" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash local enabled enabled2
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash"
local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs)
assert_equal "2" "$enabled" assert_equal "2" "$enabled"
run _enable-alias "ag" run _enable-alias "ag"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
run _disable-plugin "all" run _disable-plugin "all"
local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs)
assert_equal "0" "$enabled2" assert_equal "0" "$enabled2"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
} }
@test "helpers: disable all plugins in the old directory structure with priority" { @test "helpers: disable all plugins in the old directory structure with priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/250---nvm.plugin.bash local enabled enabled2
assert_link_exist "$BASH_IT/plugins/enabled/250---nvm.plugin.bash" ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash"
assert_link_exist "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash"
local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs)
assert_equal "2" "$enabled" assert_equal "2" "$enabled"
run _enable-alias "ag" run _enable-alias "ag"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
run _disable-plugin "all" run _disable-plugin "all"
local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs)
assert_equal "0" "$enabled2" assert_equal "0" "$enabled2"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
} }
@test "helpers: disable all plugins without anything enabled" { @test "helpers: disable all plugins without anything enabled" {
local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) local enabled enabled2
enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs)
assert_equal "0" "$enabled" assert_equal "0" "$enabled"
run _enable-alias "ag" run _enable-alias "ag"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
run _disable-plugin "all" run _disable-plugin "all"
local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs)
assert_equal "0" "$enabled2" assert_equal "0" "$enabled2"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash"
} }
@test "helpers: enable the ansible aliases through the bash-it function" { @test "helpers: enable the ansible aliases through the bash-it function" {
run bash-it enable alias "ansible" run bash-it enable alias "ansible"
assert_line -n 0 'ansible enabled with priority 150.' assert_line -n 0 'ansible enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/150---ansible.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---ansible.aliases.bash"
} }
@test "helpers: describe the nvm plugin without enabling it" { @test "helpers: describe the nvm plugin without enabling it" {
@ -707,21 +735,21 @@ function __migrate_all_components() {
@test "helpers: describe the nvm plugin after enabling it" { @test "helpers: describe the nvm plugin after enabling it" {
run _enable-plugin "nvm" run _enable-plugin "nvm"
assert_line -n 0 'nvm enabled with priority 225.' assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash"
_bash-it-plugins | grep "nvm" | grep "\[x\]" _bash-it-plugins | grep "nvm" | grep "\[x\]"
} }
@test "helpers: describe the nvm plugin after enabling it in the old directory" { @test "helpers: describe the nvm plugin after enabling it in the old directory" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash"
_bash-it-plugins | grep "nvm" | grep "\[x\]" _bash-it-plugins | grep "nvm" | grep "\[x\]"
} }
@test "helpers: describe the nvm plugin after enabling it in the old directory with priority" { @test "helpers: describe the nvm plugin after enabling it in the old directory with priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash"
_bash-it-plugins | grep "nvm" | grep "\[x\]" _bash-it-plugins | grep "nvm" | grep "\[x\]"
} }

View File

@ -1,4 +1,5 @@
# shellcheck shell=bats # shellcheck shell=bats
# shellcheck disable=SC2034
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
@ -7,77 +8,76 @@ function local_setup_file() {
} }
@test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?}
run _log_debug "test test test" run _log_debug "test test test"
assert_output "DEBUG: default: test test test" assert_output "DEBUG: default: test test test"
} }
@test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ALL" { @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ALL" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?}
run _log_warning "test test test" run _log_warning "test test test"
assert_output " WARN: default: test test test" assert_output " WARN: default: test test test"
} }
@test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ALL" { @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ALL" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?}
run _log_error "test test test" run _log_error "test test test"
assert_output "ERROR: default: test test test" assert_output "ERROR: default: test test test"
} }
@test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" { @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?}
run _log_debug "test test test" run _log_debug "test test test"
refute_output assert_output ""
} }
@test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" { @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?}
run _log_warning "test test test" run _log_warning "test test test"
assert_output " WARN: default: test test test" assert_output " WARN: default: test test test"
} }
@test "lib log: basic error logging with BASH_IT_LOG_LEVEL_WARNING" { @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_WARNING" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?}
run _log_error "test test test" run _log_error "test test test"
assert_output "ERROR: default: test test test" assert_output "ERROR: default: test test test"
} }
@test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ERROR" { @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ERROR" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?}
run _log_debug "test test test" run _log_debug "test test test"
refute_output assert_output ""
} }
@test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ERROR" { @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ERROR" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?}
run _log_warning "test test test" run _log_warning "test test test"
refute_output assert_output ""
} }
@test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" { @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?}
run _log_error "test test test" run _log_error "test test test"
assert_output "ERROR: default: test test test" assert_output "ERROR: default: test test test"
} }
@test "lib log: basic debug silent logging" { @test "lib log: basic debug silent logging" {
run _log_debug "test test test" run _log_debug "test test test"
refute_output assert_output ""
} }
@test "lib log: basic warning silent logging" { @test "lib log: basic warning silent logging" {
run _log_warning "test test test" run _log_warning "test test test"
refute_output assert_output ""
} }
@test "lib log: basic error silent logging" { @test "lib log: basic error silent logging" {
run _log_error "test test test" run _log_error "test test test"
refute_output assert_output ""
} }
@test "lib log: logging with prefix" { @test "lib log: logging with prefix" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?}
BASH_IT_LOG_PREFIX="nice: prefix: " BASH_IT_LOG_PREFIX="nice: prefix: "
run _log_debug "test test test" run _log_debug "test test test"
assert_output "DEBUG: nice: prefix: test test test" assert_output "DEBUG: nice: prefix: test test test"

View File

@ -1,18 +1,21 @@
# shellcheck shell=bats # shellcheck shell=bats
# shellcheck disable=SC2030 disable=SC2031
load ../test_helper load ../test_helper
function local_setup { function local_setup {
setup_test_fixture setup_test_fixture
export __bp_enable_subshells=yas export __bp_enable_subshells=yas
export HISTCONTROL=""
} }
@test "vendor preexec: __bp_install_after_session_init() without existing" { @test "vendor preexec: __bp_install_after_session_init() without existing" {
test_prompt_string="" test_prompt_string=""
export PROMPT_COMMAND="$test_prompt_string" export PROMPT_COMMAND="$test_prompt_string"
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_equal "${PROMPT_COMMAND}" $'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install' assert_equal "${PROMPT_COMMAND}" $'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'
} }
@ -21,8 +24,9 @@ function local_setup {
test_prompt_string="nah" test_prompt_string="nah"
export PROMPT_COMMAND="$test_prompt_string" export PROMPT_COMMAND="$test_prompt_string"
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_equal "${PROMPT_COMMAND}" "$test_prompt_string"$'\n__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install' assert_equal "${PROMPT_COMMAND}" "$test_prompt_string"$'\n__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'
} }
@ -32,8 +36,9 @@ function local_setup {
export PROMPT_COMMAND="$test_prompt_string" export PROMPT_COMMAND="$test_prompt_string"
export __bp_delay_install="blarg" export __bp_delay_install="blarg"
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_equal "${PROMPT_COMMAND}" "$test_prompt_string" assert_equal "${PROMPT_COMMAND}" "$test_prompt_string"
@ -48,8 +53,9 @@ function local_setup {
test_prompt_string="" test_prompt_string=""
export PROMPT_COMMAND="$test_prompt_string" export PROMPT_COMMAND="$test_prompt_string"
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
run __bp_install run __bp_install
assert_success assert_success
@ -62,8 +68,9 @@ function local_setup {
test_prompt_string="nah" test_prompt_string="nah"
export PROMPT_COMMAND="$test_prompt_string" export PROMPT_COMMAND="$test_prompt_string"
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
run __bp_install run __bp_install
assert_success assert_success

View File

@ -12,25 +12,28 @@ function local_setup() {
} }
@test "search: plugin base" { @test "search: plugin base" {
export BASH_IT_SEARCH_USE_COLOR=false
run _bash-it-search-component 'plugins' 'base' run _bash-it-search-component 'plugins' 'base'
assert_success
assert_line -n 0 ' plugins: base ' assert_line -n 0 ' plugins: base '
} }
@test "search: git" { @test "search: git" {
local plugin completion
run _bash-it-search 'git' --no-color run _bash-it-search 'git' --no-color
assert_success
assert_line -n 0 ' aliases: git gitsvn ' assert_line -n 0 ' aliases: git gitsvn '
assert_line -n 1 -p ' plugins:' assert_line -n 1 -p ' plugins:'
for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump" for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump"; do
do assert_line -n 1 -p "$plugin"
echo $plugin done
assert_line -n 1 -p $plugin for completion in "git" "git_flow" "git_flow_avh" "github-cli"; do
assert_line -n 2 -p "$completion"
done done
assert_line -n 2 ' completions: git git_flow git_flow_avh github-cli '
} }
@test "search: ruby gem bundle rake rails" { @test "search: ruby gem bundle rake rails" {
run _bash-it-search rails ruby gem bundler rake --no-color run _bash-it-search rails ruby gem bundler rake --no-color
assert_success
assert_line -n 0 ' aliases: bundler rails ' assert_line -n 0 ' aliases: bundler rails '
assert_line -n 1 ' plugins: chruby chruby-auto rails ruby ' assert_line -n 1 ' plugins: chruby chruby-auto rails ruby '
@ -39,6 +42,7 @@ function local_setup() {
@test "search: rails ruby gem bundler rake -chruby" { @test "search: rails ruby gem bundler rake -chruby" {
run _bash-it-search rails ruby gem bundler rake -chruby --no-color run _bash-it-search rails ruby gem bundler rake -chruby --no-color
assert_success
assert_line -n 0 ' aliases: bundler rails ' assert_line -n 0 ' aliases: bundler rails '
assert_line -n 1 ' plugins: rails ruby ' assert_line -n 1 ' plugins: rails ruby '
@ -47,22 +51,42 @@ function local_setup() {
@test "search: @git" { @test "search: @git" {
run _bash-it-search '@git' --no-color run _bash-it-search '@git' --no-color
assert_success
assert_line -n 0 ' aliases: git ' assert_line -n 0 ' aliases: git '
assert_line -n 1 ' plugins: git ' assert_line -n 1 ' plugins: git '
assert_line -n 2 ' completions: git ' assert_line -n 2 ' completions: git '
} }
@test "search: @git --enable / --disable" { @test "search: @git --enable / --disable" {
set -e
run _bash-it-search '@git' --enable --no-color run _bash-it-search '@git' --enable --no-color
assert_success
run _bash-it-search '@git' --no-color run _bash-it-search '@git' --no-color
assert_success
[[ "${lines[0]}" =~ '✓' ]] assert_line -n 0 -p '✓'
run _bash-it-search '@git' --disable --no-color run _bash-it-search '@git' --disable --no-color
assert_success
run _bash-it-search '@git' --no-color run _bash-it-search '@git' --no-color
assert_success
assert_line -n 0 ' aliases: git ' assert_line -n 0 ' aliases: git '
assert_line -n 1 ' plugins: git ' assert_line -n 1 ' plugins: git '
assert_line -n 2 ' completions: git ' assert_line -n 2 ' completions: git '
} }
@test "search: @git --disable / --enable" {
run _bash-it-search '@git' --disable --no-color
assert_success
run _bash-it-search '@git' --no-color
assert_success
assert_line -n 0 ' aliases: git '
assert_line -n 1 ' plugins: git '
assert_line -n 2 ' completions: git '
run _bash-it-search '@git' --enable --no-color
assert_success
run _bash-it-search '@git' --no-color
assert_success
assert_line -n 0 -p '✓'
}

View File

@ -4,6 +4,8 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
function local_setup_file() { function local_setup_file() {
setup_libs "helpers" setup_libs "helpers"
# shellcheck disable=SC2034
BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=""
} }
@test "_bash-it-component-item-is-enabled() - for a disabled item" { @test "_bash-it-component-item-is-enabled() - for a disabled item" {

View File

@ -8,37 +8,39 @@ function local_setup_file() {
} }
@test 'plugins base: ips()' { @test 'plugins base: ips()' {
declare -r localhost='127.0.0.1' readonly localhost='127.0.0.1'
run ips run ips
assert_success assert_success
assert_line $localhost assert_line "$localhost"
} }
@test 'plugins base: myip()' { @test 'plugins base: myip()' {
local mask_ip
run myip run myip
assert_success assert_success
declare -r mask_ip=$(echo $output | tr -s '[0-9]' '?') shopt -s extglob
[[ $mask_ip == 'Your public IP is:'*'?.?.?.?'* ]] mask_ip="${output//+([[:digit:]]|[[:digit:]][[:digit:]]|[[:digit:]][[:digit:]][[:digit:]])/?}" #$(echo "$output" | tr -s '0-9' '?')
[[ $mask_ip == 'Your public IP is: ?.?.?.? ' ]]
} }
@test 'plugins base: pickfrom()' { @test 'plugins base: pickfrom()' {
stub_file="${BATS_TEST_TMPDIR}/stub_file" stub_file="${BATS_TEST_TMPDIR?}/stub_file"
printf "l1\nl2\nl3" > $stub_file printf "l1\nl2\nl3" > "$stub_file"
run pickfrom $stub_file run pickfrom "$stub_file"
assert_success assert_success
[[ $output == l? ]] [[ $output == l? ]]
} }
@test 'plugins base: mkcd()' { @test 'plugins base: mkcd()' {
cd "${BATS_TEST_TMPDIR}" cd "${BATS_TEST_TMPDIR?}"
declare -r dir_name="-dir_with_dash" declare -r dir_name="-dir_with_dash"
# Make sure that the directory does not exist prior to the test # Make sure that the directory does not exist prior to the test
rm -rf "${BATS_TEST_TMPDIR}/${dir_name}" rm -rf "${BATS_TEST_TMPDIR:?}/${dir_name}"
run mkcd "${dir_name}" run mkcd "${dir_name}"
assert_success assert_success
assert_dir_exist "${BATS_TEST_TMPDIR}/${dir_name}" assert_dir_exist "${BATS_TEST_TMPDIR?}/${dir_name}"
mkcd "${dir_name}" mkcd "${dir_name}"
assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}" assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}"
@ -46,20 +48,20 @@ function local_setup_file() {
@test 'plugins base: lsgrep()' { @test 'plugins base: lsgrep()' {
for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done
cd $BASH_IT cd "${BASH_IT?}"
run lsgrep 2 run lsgrep 2
assert_success assert_success
assert_equal $output 2 assert_equal "$output" 2
} }
@test 'plugins base: buf()' { @test 'plugins base: buf()' {
declare -r file="${BATS_TEST_TMPDIR}/file" declare -r file="${BATS_TEST_TMPDIR?}/file"
touch $file touch "$file"
# Take one timestamp before running the `buf` function # Take one timestamp before running the `buf` function
declare -r stamp1=$(date +%Y%m%d_%H%M%S) declare -r stamp1=$(date +%Y%m%d_%H%M%S)
run buf $file run buf "$file"
# Take another timestamp after running `buf`. # Take another timestamp after running `buf`.
declare -r stamp2=$(date +%Y%m%d_%H%M%S) declare -r stamp2=$(date +%Y%m%d_%H%M%S)

View File

@ -200,12 +200,11 @@ function setup_upower {
function upower { function upower {
case $1 in case $1 in
'-e'|'--enumerate') '-e' | '--enumerate')
printf '%s\n' "$BAT0" "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery" printf '%s\n' "$BAT0" "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery"
;; ;;
'-i'|'--show-info') '-i' | '--show-info')
if [[ $2 == "$BAT0" ]] if [[ $2 == "$BAT0" ]]; then
then
printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}" printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}"
else else
false false

View File

@ -1,4 +1,5 @@
# shellcheck shell=bats # shellcheck shell=bats
# shellcheck disable=SC2034
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
@ -8,8 +9,8 @@ function local_setup_file() {
} }
@test "plugins cmd-returned-notify: notify after elapsed time" { @test "plugins cmd-returned-notify: notify after elapsed time" {
export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 NOTIFY_IF_COMMAND_RETURNS_AFTER=0
export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
sleep 1 sleep 1
run precmd_return_notification run precmd_return_notification
assert_success assert_success
@ -17,8 +18,8 @@ function local_setup_file() {
} }
@test "plugins cmd-returned-notify: do not notify before elapsed time" { @test "plugins cmd-returned-notify: do not notify before elapsed time" {
export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 NOTIFY_IF_COMMAND_RETURNS_AFTER=10
export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
sleep 1 sleep 1
run precmd_return_notification run precmd_return_notification
assert_success assert_success
@ -26,13 +27,13 @@ function local_setup_file() {
} }
@test "lib command_duration: preexec no output" { @test "lib command_duration: preexec no output" {
export COMMAND_DURATION_START_SECONDS= COMMAND_DURATION_START_SECONDS=
run _command_duration_pre_exec run _command_duration_pre_exec
assert_success assert_success
assert_output "" assert_output ""
} }
@test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" { @test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" {
export COMMAND_DURATION_START_SECONDS= COMMAND_DURATION_START_SECONDS=
assert_equal "${COMMAND_DURATION_START_SECONDS}" "" assert_equal "${COMMAND_DURATION_START_SECONDS}" ""
NOW="${EPOCHREALTIME:-$SECONDS}" NOW="${EPOCHREALTIME:-$SECONDS}"
_command_duration_pre_exec _command_duration_pre_exec

View File

@ -1,4 +1,5 @@
# shellcheck shell=bats # shellcheck shell=bats
# shellcheck disable=SC2034
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
@ -6,8 +7,7 @@ function local_setup_file() {
setup_libs "helpers" setup_libs "helpers"
} }
function setup_go_path() function setup_go_path() {
{
local go_path="$1" local go_path="$1"
# Make sure that the requested GO folder is available # Make sure that the requested GO folder is available
@ -20,55 +20,55 @@ function setup_go_path()
# We test `go version` in each test to account for users with goenv and no system go. # We test `go version` in each test to account for users with goenv and no system go.
@test 'ensure _bash-it-gopath-pathmunge is defined' { @test 'ensure _bash-it-gopath-pathmunge is defined' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found' { _command_exists go && go version &> /dev/null; } || skip 'golang not found'
load ../../plugins/available/go.plugin load "${BASH_IT?}/plugins/available/go.plugin.bash"
run type -t _bash-it-gopath-pathmunge run type -t _bash-it-gopath-pathmunge
assert_line 'function' assert_line 'function'
} }
@test 'plugins go: single entry in GOPATH' { @test 'plugins go: single entry in GOPATH' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found' { _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/gopath"
load ../../plugins/available/go.plugin load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath/bin" assert_equal "$(cut -d':' -f1 <<< "$PATH")" "$BASH_IT/test/fixtures/go/gopath/bin"
} }
@test 'plugins go: single entry in GOPATH, with space' { @test 'plugins go: single entry in GOPATH, with space' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found' { _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/go path" setup_go_path "$BASH_IT/test/fixtures/go/go path"
load ../../plugins/available/go.plugin load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin" assert_equal "$(cut -d':' -f1 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go path/bin"
} }
@test 'plugins go: single entry in GOPATH, with escaped space' { @test 'plugins go: single entry in GOPATH, with escaped space' {
skip 'huh?' skip 'huh?'
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found' { _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/go\ path" setup_go_path "$BASH_IT/test/fixtures/go/go\ path"
load ../../plugins/available/go.plugin load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin" assert_equal "$(cut -d':' -f1 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin"
} }
@test 'plugins go: multiple entries in GOPATH' { @test 'plugins go: multiple entries in GOPATH' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found' { _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/gopath"
setup_go_path "$BASH_IT/test/fixtures/go/gopath2" setup_go_path "$BASH_IT/test/fixtures/go/gopath2"
load ../../plugins/available/go.plugin load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin" assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin"
} }
@test 'plugins go: multiple entries in GOPATH, with space' { @test 'plugins go: multiple entries in GOPATH, with space' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found' { _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/gopath"
setup_go_path "$BASH_IT/test/fixtures/go/go path" setup_go_path "$BASH_IT/test/fixtures/go/go path"
load ../../plugins/available/go.plugin load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin" assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
} }
@test 'plugins go: multiple entries in GOPATH, with escaped space' { @test 'plugins go: multiple entries in GOPATH, with escaped space' {
skip 'huh?' skip 'huh?'
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found' { _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/gopath"
setup_go_path "$BASH_IT/test/fixtures/go/go path" setup_go_path "$BASH_IT/test/fixtures/go/go path"
load ../../plugins/available/go.plugin load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin" assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
} }

View File

@ -16,7 +16,8 @@ function local_setup_file() {
} }
@test "plugins ruby: PATH includes ~/.gem/ruby/bin" { @test "plugins ruby: PATH includes ~/.gem/ruby/bin" {
if ! type ruby >/dev/null; then local last_path_entry
if ! type ruby > /dev/null; then
skip 'ruby not installed' skip 'ruby not installed'
fi fi
@ -26,6 +27,6 @@ function local_setup_file() {
assert_success assert_success
load "${BASH_IT?}/plugins/available/ruby.plugin.bash" load "${BASH_IT?}/plugins/available/ruby.plugin.bash"
local last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" last_path_entry="$(tail -1 <<< "${PATH//:/$'\n'}")"
[[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]] [[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]]
} }

View File

@ -1,4 +1,5 @@
# shellcheck shell=bats # shellcheck shell=bats
# shellcheck disable=SC2034
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
@ -8,28 +9,28 @@ function local_setup_file() {
} }
@test "plugins xterm: shorten command output" { @test "plugins xterm: shorten command output" {
export SHORT_TERM_LINE=true SHORT_TERM_LINE=true
run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/*
assert_success assert_success
assert_output "${BASH_IT}/test/fixtures/plugin/xterm/files/arg0" assert_output "${BASH_IT}/test/fixtures/plugin/xterm/files/arg0"
} }
@test "plugins xterm: full command output" { @test "plugins xterm: full command output" {
export SHORT_TERM_LINE=false SHORT_TERM_LINE=false
run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/*
assert_success assert_success
assert_output "$(echo "${BASH_IT}/test/fixtures/plugin/xterm/files"/*)" assert_output "$(echo "${BASH_IT}/test/fixtures/plugin/xterm/files"/*)"
} }
@test "plugins xterm: shorten dirname output" { @test "plugins xterm: shorten dirname output" {
export SHORT_TERM_LINE=true SHORT_TERM_LINE=true
run _short-dirname run _short-dirname
assert_success assert_success
assert_output "$(basename "${PWD}")" assert_output "$(basename "${PWD}")"
} }
@test "plugins xterm: full dirname output" { @test "plugins xterm: full dirname output" {
export SHORT_TERM_LINE=false SHORT_TERM_LINE=false
run _short-dirname run _short-dirname
assert_success assert_success
assert_output "${PWD}" assert_output "${PWD}"

View File

@ -57,7 +57,7 @@ function common_setup_file() {
function setup_libs() { function setup_libs() {
local lib local lib
# Use a loop to allow convenient short-circuiting for some test files # Use a loop to allow convenient short-circuiting for some test files
for lib in "log" "utilities" "helpers" "search" "preexec" "colors" "command_duration"; do for lib in "log" "utilities" "helpers" "search" "colors" "preview" "preexec" "history" "command_duration"; do
load "${BASH_IT?}/lib/${lib}.bash" || return load "${BASH_IT?}/lib/${lib}.bash" || return
# shellcheck disable=SC2015 # short-circuit if we've reached the requested library # shellcheck disable=SC2015 # short-circuit if we've reached the requested library
[[ "${lib}" == "${1:-}" ]] && return 0 || true [[ "${lib}" == "${1:-}" ]] && return 0 || true
@ -66,7 +66,7 @@ function setup_libs() {
} }
function local_setup_file() { function local_setup_file() {
true setup_libs "colors" # overridable default
} }
function local_setup() { function local_setup() {
@ -101,6 +101,7 @@ function setup() {
BASH_IT_CONFIG="${BASH_IT?}" #"${BATS_TEST_TMPDIR//\/\///}" BASH_IT_CONFIG="${BASH_IT?}" #"${BATS_TEST_TMPDIR//\/\///}"
export XDG_CACHE_HOME="${BATS_TEST_TMPDIR?}" export XDG_CACHE_HOME="${BATS_TEST_TMPDIR?}"
set -Eeuo pipefail # Bash Unofficial Strict Mode
setup_test_fixture setup_test_fixture
local_setup local_setup
} }
@ -109,6 +110,7 @@ function teardown() {
unset GIT_CONFIG_NOSYSTEM unset GIT_CONFIG_NOSYSTEM
local_teardown local_teardown
clean_test_fixture clean_test_fixture
set +Eeuo pipefail # Bash Unofficial Strict Mode
} }
function teardown_file() { function teardown_file() {

View File

@ -25,7 +25,7 @@ function local_setup_file() {
assert_line "function" assert_line "function"
run battery_char run battery_char
assert_line -n 0 "" assert_output ""
} }
@test 'themes base: battery_char should exist if battery plugin loaded' { @test 'themes base: battery_char should exist if battery plugin loaded' {

View File

@ -20,12 +20,12 @@ add_commit() {
enter_new_git_repo() { enter_new_git_repo() {
repo="$(setup_repo)" repo="$(setup_repo)"
pushd "${repo}" pushd "${repo}" || return
} }
setup_repo() { setup_repo() {
upstream="$(mktemp -d)" upstream="$(mktemp -d)"
pushd "$upstream" > /dev/null pushd "$upstream" > /dev/null || return
git init . > /dev/null git init . > /dev/null
echo "$upstream" echo "$upstream"
@ -33,83 +33,83 @@ setup_repo() {
setup_repo_with_upstream() { setup_repo_with_upstream() {
upstream="$(setup_repo)" upstream="$(setup_repo)"
pushd "$upstream" > /dev/null pushd "$upstream" > /dev/null || return
add_commit > /dev/null add_commit > /dev/null
git checkout -b branch-two git checkout -b branch-two
git checkout -b gone-branch git checkout -b gone-branch
git checkout master git checkout master
popd > /dev/null popd > /dev/null || return
downstream="$(setup_repo)" downstream="$(setup_repo)"
pushd "$downstream" > /dev/null pushd "$downstream" > /dev/null || return
add_commit > /dev/null add_commit > /dev/null
git remote add my-remote "$upstream" git remote add my-remote "$upstream"
git fetch my-remote git fetch my-remote
git branch -u my-remote/master > /dev/null git branch -u my-remote/master > /dev/null
popd > /dev/null popd > /dev/null || return
pushd "$upstream" > /dev/null pushd "$upstream" > /dev/null || return
git branch -d gone-branch > /dev/null git branch -d gone-branch > /dev/null
popd > /dev/null popd > /dev/null || return
pushd "$downstream" > /dev/null pushd "$downstream" > /dev/null || return
git fetch my-remote git fetch my-remote
popd > /dev/null popd > /dev/null || return
echo "$downstream" echo "$downstream"
} }
@test 'themes base: Git: when tracking a remote branch: it shows the commits ahead and behind' { @test 'themes base: Git: when tracking a remote branch: it shows the commits ahead and behind' {
pre="\$(_git-friendly-ref)" pre='$(_git-friendly-ref)'
remote="$(setup_repo)" remote="$(setup_repo)"
pushd "$remote" pushd "$remote" || return
add_commit add_commit
add_commit add_commit
popd popd || return
clone="$(mktemp -d)" clone="$(mktemp -d)"
pushd "$clone" pushd "$clone" || return
git clone "$remote" clone git clone "$remote" clone
cd clone cd clone
SCM_GIT_SHOW_COMMIT_COUNT=true SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}" assert_equal "${SCM_BRANCH?}" "${pre}"
add_commit add_commit
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↑1" assert_equal "${SCM_BRANCH?}" "${pre} ↑1"
add_commit add_commit
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↑2" assert_equal "${SCM_BRANCH?}" "${pre} ↑2"
popd popd || return
pushd "$remote" pushd "$remote" || return
add_commit add_commit
add_commit add_commit
add_commit add_commit
popd popd || return
pushd "$clone/clone" pushd "$clone/clone" || return
git fetch git fetch
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↑2 ↓3" assert_equal "${SCM_BRANCH?}" "${pre} ↑2 ↓3"
git reset HEAD~2 --hard git reset HEAD~2 --hard
SCM_GIT_BEHIND_CHAR="↓" SCM_GIT_BEHIND_CHAR="↓"
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↓3" assert_equal "${SCM_BRANCH?}" "${pre} ↓3"
} }
@test 'themes base: Git: when stashes exist: it shows the number of stashes' { @test 'themes base: Git: when stashes exist: it shows the number of stashes' {
pre="\$(_git-friendly-ref)" pre='$(_git-friendly-ref)'
enter_new_git_repo enter_new_git_repo
add_commit add_commit
@ -121,90 +121,90 @@ setup_repo_with_upstream() {
SCM_GIT_SHOW_STASH_INFO=true SCM_GIT_SHOW_STASH_INFO=true
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} {1}" assert_equal "${SCM_BRANCH?}" "${pre} {1}"
touch file2 touch file2
git add file2 git add file2
git stash git stash
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} {2}" assert_equal "${SCM_BRANCH?}" "${pre} {2}"
} }
@test 'themes base: Git: remote info: when there is no upstream remote: is empty' { @test 'themes base: Git: remote info: when there is no upstream remote: is empty' {
pre="\$(_git-friendly-ref)" pre='$(_git-friendly-ref)'
post=" ↑1 ↓1" post=" ↑1 ↓1"
enter_new_git_repo enter_new_git_repo
add_commit add_commit
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}" assert_equal "${SCM_BRANCH?}" "${pre}"
} }
@test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is true: includes the remote' { @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is true: includes the remote' {
pre="\$(_git-friendly-ref) → " pre='$(_git-friendly-ref) → '
eval_pre="master → " eval_pre="master → "
post=" ↑1 ↓1" post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)" repo="$(setup_repo_with_upstream)"
pushd "${repo}" pushd "${repo}" || return
SCM_GIT_SHOW_REMOTE_INFO=true SCM_GIT_SHOW_REMOTE_INFO=true
SCM_GIT_SHOW_COMMIT_COUNT=true SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}"
git branch -u my-remote/branch-two git branch -u my-remote/branch-two
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}" assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}"
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}"
} }
@test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is auto: includes the remote when more than one remote' { @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is auto: includes the remote when more than one remote' {
pre="\$(_git-friendly-ref)" pre='$(_git-friendly-ref)'
eval_pre="master" eval_pre="master"
post=" ↑1 ↓1" post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)" repo="$(setup_repo_with_upstream)"
pushd "${repo}" pushd "${repo}" || return
SCM_GIT_SHOW_REMOTE_INFO=auto SCM_GIT_SHOW_REMOTE_INFO=auto
SCM_GIT_SHOW_COMMIT_COUNT=true SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}${post}" assert_equal "${SCM_BRANCH?}" "${pre}${post}"
pre="${pre} → " pre="${pre} → "
eval_pre="${eval_pre} → " eval_pre="${eval_pre} → "
git branch -u my-remote/branch-two git branch -u my-remote/branch-two
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}" assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}"
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}"
git remote add second-remote "$(mktemp -d)" git remote add second-remote "$(mktemp -d)"
git branch -u my-remote/master git branch -u my-remote/master
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}"
git branch -u my-remote/branch-two git branch -u my-remote/branch-two
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}" assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}"
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}"
} }
@test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is false: never include the remote' { @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is false: never include the remote' {
pre="\$(_git-friendly-ref)" pre='$(_git-friendly-ref)'
eval_pre="master" eval_pre="master"
post=" ↑1 ↓1" post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)" repo="$(setup_repo_with_upstream)"
pushd "${repo}" pushd "${repo}" || return
git remote add second-remote "$(mktemp -d)" git remote add second-remote "$(mktemp -d)"
git remote add third-remote "$(mktemp -d)" git remote add third-remote "$(mktemp -d)"
@ -212,59 +212,59 @@ setup_repo_with_upstream() {
SCM_GIT_SHOW_COMMIT_COUNT=true SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}${post}" assert_equal "${SCM_BRANCH?}" "${pre}${post}"
pre="${pre} → " pre="${pre} → "
eval_pre="${eval_pre} → " eval_pre="${eval_pre} → "
git branch -u my-remote/branch-two git branch -u my-remote/branch-two
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}" assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}"
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}"
} }
@test 'themes base: Git: remote info: when showing remote info: show if upstream branch is gone' { @test 'themes base: Git: remote info: when showing remote info: show if upstream branch is gone' {
pre="\$(_git-friendly-ref)" pre='$(_git-friendly-ref)'
post=" ↑1 ↓1" post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)" repo="$(setup_repo_with_upstream)"
pushd "${repo}" pushd "${repo}" || return
SCM_GIT_SHOW_REMOTE_INFO=true SCM_GIT_SHOW_REMOTE_INFO=true
SCM_GIT_SHOW_COMMIT_COUNT=true SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} → my-remote${post}" assert_equal "${SCM_BRANCH?}" "${pre} → my-remote${post}"
git checkout gone-branch git checkout gone-branch
git fetch --prune --all git fetch --prune --all
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ⇢ my-remote" assert_equal "${SCM_BRANCH?}" "${pre} ⇢ my-remote"
} }
@test 'themes base: Git: git friendly ref: when a branch is checked out: shows that branch' { @test 'themes base: Git: git friendly ref: when a branch is checked out: shows that branch' {
enter_new_git_repo enter_new_git_repo
git_prompt_vars git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master"
git checkout -b second-branch git checkout -b second-branch
git_prompt_vars git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch"
} }
@test 'themes base: Git: git friendly ref: when a branch is not checked out: shows that branch' { @test 'themes base: Git: git friendly ref: when a branch is not checked out: shows that branch' {
enter_new_git_repo enter_new_git_repo
git_prompt_vars git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master"
git checkout -b second-branch git checkout -b second-branch
git_prompt_vars git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch"
} }
@test 'themes base: Git: git friendly ref: when detached: commit has branch and tag: show a tag' { @test 'themes base: Git: git friendly ref: when detached: commit has branch and tag: show a tag' {
@ -276,7 +276,7 @@ setup_repo_with_upstream() {
git checkout HEAD~1 git checkout HEAD~1
git_prompt_vars git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "tag:first-tag" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "tag:first-tag"
} }
@test 'themes base: Git: git friendly ref: when detached: commit has branch and no tag: show a branch' { @test 'themes base: Git: git friendly ref: when detached: commit has branch and no tag: show a branch' {
@ -287,7 +287,7 @@ setup_repo_with_upstream() {
git checkout HEAD~1 git checkout HEAD~1
git_prompt_vars git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master"
} }
@test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is parent to a named ref: show relative name' { @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is parent to a named ref: show relative name' {
@ -297,7 +297,7 @@ setup_repo_with_upstream() {
git checkout HEAD~1 git checkout HEAD~1
git_prompt_vars git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master~1" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master~1"
} }
@test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is not parent to a named ref: show short sha' { @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is not parent to a named ref: show short sha' {
@ -309,11 +309,11 @@ setup_repo_with_upstream() {
git checkout "$sha" git checkout "$sha"
git_prompt_vars git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:$sha" assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:$sha"
} }
@test 'themes base: Git: git friendly ref: shows staged, unstaged, and untracked file counts' { @test 'themes base: Git: git friendly ref: shows staged, unstaged, and untracked file counts' {
pre="\$(_git-friendly-ref)" pre='$(_git-friendly-ref)'
enter_new_git_repo enter_new_git_repo
echo "line1" > file1 echo "line1" > file1
@ -324,7 +324,7 @@ setup_repo_with_upstream() {
git commit -m"commit1" git commit -m"commit1"
git_prompt_vars git_prompt_vars
assert_equal "$SCM_STATE" " ✓" assert_equal "${SCM_STATE?}" " ✓"
echo "line2" >> file1 echo "line2" >> file1
git add file1 git add file1
@ -332,56 +332,56 @@ setup_repo_with_upstream() {
SCM_GIT_SHOW_DETAILS=true SCM_GIT_SHOW_DETAILS=true
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1" assert_equal "${SCM_BRANCH?}" "${pre} S:1"
assert_equal "$SCM_STATE" " ✗" assert_equal "${SCM_STATE?}" " ✗"
assert_equal "$SCM_DIRTY" "3" assert_equal "${SCM_DIRTY?}" "3"
echo "line2" >> file2 echo "line2" >> file2
echo "line2" >> file3 echo "line2" >> file3
echo "line2" >> file4 echo "line2" >> file4
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1 U:3" assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3"
assert_equal "$SCM_DIRTY" "2" assert_equal "${SCM_DIRTY?}" "2"
echo "line1" > newfile5 echo "line1" > newfile5
echo "line1" > newfile6 echo "line1" > newfile6
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1 U:3 ?:2" assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3 ?:2"
assert_equal "$SCM_DIRTY" "1" assert_equal "${SCM_DIRTY?}" "1"
git config bash-it.hide-status 1 git config bash-it.hide-status 1
SCM_DIRTY='nope' SCM_DIRTY='nope'
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}" assert_equal "${SCM_BRANCH?}" "${pre}"
assert_equal "$SCM_DIRTY" "nope" assert_equal "${SCM_DIRTY?}" "nope"
} }
@test 'themes base: Git: git user info: shows user initials' { @test 'themes base: Git: git user info: shows user initials' {
pre="\$(_git-friendly-ref)" pre='$(_git-friendly-ref)'
enter_new_git_repo enter_new_git_repo
git config user.name "Cool User" git config user.name "Cool User"
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}" assert_equal "${SCM_BRANCH?}" "${pre}"
SCM_GIT_SHOW_CURRENT_USER=true SCM_GIT_SHOW_CURRENT_USER=true
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ☺︎ cu" assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ cu"
git config user.name "Çool Üser" git config user.name "Çool Üser"
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ☺︎ çü" assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ çü"
# show initials set by `git pair` # show initials set by `git pair`
git config user.initials "ab cd" git config user.initials "ab cd"
git_prompt_vars git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ☺︎ ab+cd" assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ ab+cd"
} }

View File

@ -9,7 +9,7 @@ function local_setup_file() {
function setup_repo { function setup_repo {
upstream="$(mktemp -d)" upstream="$(mktemp -d)"
pushd "$upstream" > /dev/null pushd "$upstream" > /dev/null || return
# Create a dummy SVN folder - this will not work with an actual `svn` command, # Create a dummy SVN folder - this will not work with an actual `svn` command,
# but will be enough to trigger the SVN check in the base theme. # but will be enough to trigger the SVN check in the base theme.
mkdir .svn mkdir .svn
@ -24,83 +24,93 @@ function setup_svn_path {
assert_file_exist "$svn_path/svn" assert_file_exist "$svn_path/svn"
# Make sure that the requested SVN script is on the path # Make sure that the requested SVN script is on the path
export PATH="$svn_path:/usr/bin:/bin:/usr/sbin" export PATH="$svn_path:$PATH"
} }
@test 'themes base: SVN: detect SVN repo' { @test 'themes base: SVN: detect SVN repo' {
repo="$(setup_repo)" repo="$(setup_repo)"
pushd "$repo" pushd "$repo" || return
setup_svn_path "$BASH_IT/test/fixtures/svn/working" setup_svn_path "$BASH_IT/test/fixtures/svn/working"
# Init the base theme again so that the working SVN script is detected # Init the base theme again so that the working SVN script is detected
run _bash_it_appearance_scm_init
assert_success
_bash_it_appearance_scm_init _bash_it_appearance_scm_init
scm scm
# Make sure that the SVN command is used # Make sure that the SVN command is used
assert_equal "$SCM" "$SCM_SVN" assert_equal "${SCM?}" "${SCM_SVN?}"
} }
@test 'themes base: SVN: detect SVN repo even from a subfolder' { @test 'themes base: SVN: detect SVN repo even from a subfolder' {
repo="$(setup_repo)" repo="$(setup_repo)"
pushd "$repo" pushd "$repo" || return
mkdir foo mkdir foo
pushd foo pushd foo || return
setup_svn_path "$BASH_IT/test/fixtures/svn/working" setup_svn_path "$BASH_IT/test/fixtures/svn/working"
# init the base theme again so that the working SVN script is detected # Init the base theme again so that the working SVN script is detected
run _bash_it_appearance_scm_init
assert_success
_bash_it_appearance_scm_init _bash_it_appearance_scm_init
scm scm
# Make sure that the SVN command is used # Make sure that the SVN command is used
assert_equal "$SCM" "$SCM_SVN" assert_equal "${SCM?}" "${SCM_SVN?}"
} }
@test 'themes base: SVN: no SCM if no .svn folder can be found' { @test 'themes base: SVN: no SCM if no .svn folder can be found' {
repo="$(setup_repo)" repo="$(setup_repo)"
pushd "$repo" pushd "$repo" || return
rm -rf .svn rm -rf .svn
setup_svn_path "$BASH_IT/test/fixtures/svn/working" setup_svn_path "$BASH_IT/test/fixtures/svn/working"
# Init the base theme again so that the working SVN script is detected # Init the base theme again so that the working SVN script is detected
run _bash_it_appearance_scm_init
assert_success
_bash_it_appearance_scm_init _bash_it_appearance_scm_init
scm scm
# Make sure that no SVN command is used # Make sure that no SVN command is used
assert_equal "$SCM" "$SCM_NONE" assert_equal "${SCM?}" "${SCM_NONE?}"
} }
@test 'themes base: SVN: ignore SVN repo when using broken SVN command' { @test 'themes base: SVN: ignore SVN repo when using broken SVN command' {
repo="$(setup_repo)" repo="$(setup_repo)"
pushd "$repo" pushd "$repo" || return
setup_svn_path "$BASH_IT/test/fixtures/svn/broken" setup_svn_path "$BASH_IT/test/fixtures/svn/broken"
# Init the base theme again so that the broken SVN script is detected # Init the base theme again so that the working SVN script is detected
run _bash_it_appearance_scm_init
assert_success
_bash_it_appearance_scm_init _bash_it_appearance_scm_init
scm scm
# Make sure that no SVN command is not used # Make sure that no SVN command is not used
assert_equal "$SCM" "$SCM_NONE" assert_equal "${SCM?}" "${SCM_NONE?}"
} }
@test 'themes base: SVN: ignore SVN repo even from a subfolder when using a broken SVN' { @test 'themes base: SVN: ignore SVN repo even from a subfolder when using a broken SVN' {
repo="$(setup_repo)" repo="$(setup_repo)"
pushd "$repo" pushd "$repo" || return
mkdir foo mkdir foo
pushd foo pushd foo || return
setup_svn_path "$BASH_IT/test/fixtures/svn/broken" setup_svn_path "$BASH_IT/test/fixtures/svn/broken"
# Init the base theme again so that the broken SVN script is detected # Init the base theme again so that the working SVN script is detected
run _bash_it_appearance_scm_init
assert_success
_bash_it_appearance_scm_init _bash_it_appearance_scm_init
scm scm
# Make sure that no SVN command is used # Make sure that no SVN command is used
assert_equal "$SCM" "$SCM_NONE" assert_equal "${SCM?}" "${SCM_NONE?}"
} }