add bash-it

This commit is contained in:
2022-05-05 22:20:02 +02:00
parent 6a62a35d0d
commit 43701f0590
490 changed files with 33047 additions and 0 deletions
+73
View File
@@ -0,0 +1,73 @@
# shellcheck shell=bats
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
function local_setup_file() {
setup_libs "colors" #"theme"
load "${BASH_IT?}/themes/base.theme.bash"
}
@test 'themes base: battery_percentage should not exist' {
run type -a battery_percentage &> /dev/null
assert_failure
}
@test 'themes base: battery_percentage should exist if battery plugin loaded' {
load "${BASH_IT?}/plugins/available/battery.plugin.bash"
run type -a battery_percentage &> /dev/null
assert_success
}
@test 'themes base: battery_char should exist' {
run type -t battery_char
assert_success
assert_line "function"
run battery_char
assert_line -n 0 ""
}
@test 'themes base: battery_char should exist if battery plugin loaded' {
unset -f battery_char
load "${BASH_IT?}/plugins/available/battery.plugin.bash"
run type -t battery_percentage
assert_success
assert_line "function"
load "${BASH_IT?}/themes/base.theme.bash"
run type -t battery_char
assert_success
assert_line "function"
run battery_char
assert_success
run type -a battery_char
assert_output --partial 'THEME_BATTERY_PERCENTAGE_CHECK'
}
@test 'themes base: battery_charge should exist' {
run type -a battery_charge &> /dev/null
assert_success
run battery_charge
assert_success
assert_output ""
}
@test 'themes base: battery_charge should exist if battery plugin loaded' {
unset -f battery_charge
load "${BASH_IT?}/plugins/available/battery.plugin.bash"
load "${BASH_IT?}/themes/base.theme.bash"
run type -a battery_charge &> /dev/null
assert_success
run battery_charge
assert_success
run type -a battery_charge
assert_line ' no)'
}
+387
View File
@@ -0,0 +1,387 @@
# shellcheck shell=bats
# shellcheck disable=SC2034
# shellcheck disable=SC2016
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
function local_setup_file() {
setup_libs "colors" #"theme"
load "${BASH_IT?}/themes/base.theme.bash"
load "${BASH_IT?}/themes/githelpers.theme.bash"
}
add_commit() {
local file_name="general-${RANDOM}"
touch "${file_name}"
echo "" >> "${file_name}"
git add "${file_name}"
git commit -m"message"
}
enter_new_git_repo() {
repo="$(setup_repo)"
pushd "${repo}"
}
setup_repo() {
upstream="$(mktemp -d)"
pushd "$upstream" > /dev/null
git init . > /dev/null
echo "$upstream"
}
setup_repo_with_upstream() {
upstream="$(setup_repo)"
pushd "$upstream" > /dev/null
add_commit > /dev/null
git checkout -b branch-two
git checkout -b gone-branch
git checkout master
popd > /dev/null
downstream="$(setup_repo)"
pushd "$downstream" > /dev/null
add_commit > /dev/null
git remote add my-remote "$upstream"
git fetch my-remote
git branch -u my-remote/master > /dev/null
popd > /dev/null
pushd "$upstream" > /dev/null
git branch -d gone-branch > /dev/null
popd > /dev/null
pushd "$downstream" > /dev/null
git fetch my-remote
popd > /dev/null
echo "$downstream"
}
@test 'themes base: Git: when tracking a remote branch: it shows the commits ahead and behind' {
pre="\$(_git-friendly-ref)"
remote="$(setup_repo)"
pushd "$remote"
add_commit
add_commit
popd
clone="$(mktemp -d)"
pushd "$clone"
git clone "$remote" clone
cd clone
SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}"
add_commit
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↑1"
add_commit
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↑2"
popd
pushd "$remote"
add_commit
add_commit
add_commit
popd
pushd "$clone/clone"
git fetch
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↑2 ↓3"
git reset HEAD~2 --hard
SCM_GIT_BEHIND_CHAR="↓"
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↓3"
}
@test 'themes base: Git: when stashes exist: it shows the number of stashes' {
pre="\$(_git-friendly-ref)"
enter_new_git_repo
add_commit
touch file
git add file
git stash
SCM_GIT_SHOW_STASH_INFO=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} {1}"
touch file2
git add file2
git stash
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} {2}"
}
@test 'themes base: Git: remote info: when there is no upstream remote: is empty' {
pre="\$(_git-friendly-ref)"
post=" ↑1 ↓1"
enter_new_git_repo
add_commit
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}"
}
@test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is true: includes the remote' {
pre="\$(_git-friendly-ref) → "
eval_pre="master → "
post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)"
pushd "${repo}"
SCM_GIT_SHOW_REMOTE_INFO=true
SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}my-remote${post}"
git branch -u my-remote/branch-two
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${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' {
pre="\$(_git-friendly-ref)"
eval_pre="master"
post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)"
pushd "${repo}"
SCM_GIT_SHOW_REMOTE_INFO=auto
SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}${post}"
pre="${pre} → "
eval_pre="${eval_pre} → "
git branch -u my-remote/branch-two
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}"
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}"
git remote add second-remote "$(mktemp -d)"
git branch -u my-remote/master
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}my-remote${post}"
git branch -u my-remote/branch-two
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${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' {
pre="\$(_git-friendly-ref)"
eval_pre="master"
post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)"
pushd "${repo}"
git remote add second-remote "$(mktemp -d)"
git remote add third-remote "$(mktemp -d)"
SCM_GIT_SHOW_REMOTE_INFO=false
SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}${post}"
pre="${pre} → "
eval_pre="${eval_pre} → "
git branch -u my-remote/branch-two
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${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' {
pre="\$(_git-friendly-ref)"
post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)"
pushd "${repo}"
SCM_GIT_SHOW_REMOTE_INFO=true
SCM_GIT_SHOW_COMMIT_COUNT=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} → my-remote${post}"
git checkout gone-branch
git fetch --prune --all
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ⇢ my-remote"
}
@test 'themes base: Git: git friendly ref: when a branch is checked out: shows that branch' {
enter_new_git_repo
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master"
git checkout -b second-branch
git_prompt_vars
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' {
enter_new_git_repo
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master"
git checkout -b second-branch
git_prompt_vars
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' {
enter_new_git_repo
add_commit
git tag first-tag
git checkout -b second-branch
add_commit
git checkout HEAD~1
git_prompt_vars
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' {
enter_new_git_repo
add_commit
git checkout -b second-branch
add_commit
git checkout HEAD~1
git_prompt_vars
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' {
enter_new_git_repo
add_commit
add_commit
git checkout HEAD~1
git_prompt_vars
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' {
enter_new_git_repo
add_commit
add_commit
sha="$(git rev-parse --short HEAD)"
git reset --hard HEAD~1
git checkout "$sha"
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:$sha"
}
@test 'themes base: Git: git friendly ref: shows staged, unstaged, and untracked file counts' {
pre="\$(_git-friendly-ref)"
enter_new_git_repo
echo "line1" > file1
echo "line1" > file2
echo "line1" > file3
echo "line1" > file4
git add .
git commit -m"commit1"
git_prompt_vars
assert_equal "$SCM_STATE" " ✓"
echo "line2" >> file1
git add file1
SCM_GIT_SHOW_DETAILS=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1"
assert_equal "$SCM_STATE" " ✗"
assert_equal "$SCM_DIRTY" "3"
echo "line2" >> file2
echo "line2" >> file3
echo "line2" >> file4
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1 U:3"
assert_equal "$SCM_DIRTY" "2"
echo "line1" > newfile5
echo "line1" > newfile6
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1 U:3 ?:2"
assert_equal "$SCM_DIRTY" "1"
git config bash-it.hide-status 1
SCM_DIRTY='nope'
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}"
assert_equal "$SCM_DIRTY" "nope"
}
@test 'themes base: Git: git user info: shows user initials' {
pre="\$(_git-friendly-ref)"
enter_new_git_repo
git config user.name "Cool User"
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}"
SCM_GIT_SHOW_CURRENT_USER=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ☺︎ cu"
git config user.name "Çool Üser"
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ☺︎ çü"
# show initials set by `git pair`
git config user.initials "ab cd"
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ☺︎ ab+cd"
}
+106
View File
@@ -0,0 +1,106 @@
# shellcheck shell=bats
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
function local_setup_file() {
setup_libs "colors" #"theme"
load "${BASH_IT?}/themes/base.theme.bash"
}
function setup_repo {
upstream="$(mktemp -d)"
pushd "$upstream" > /dev/null
# 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.
mkdir .svn
echo "$upstream"
}
function setup_svn_path {
local svn_path="$1"
# Make sure that the requested SVN script is available
assert_file_exist "$svn_path/svn"
# Make sure that the requested SVN script is on the path
export PATH="$svn_path:/usr/bin:/bin:/usr/sbin"
}
@test 'themes base: SVN: detect SVN repo' {
repo="$(setup_repo)"
pushd "$repo"
setup_svn_path "$BASH_IT/test/fixtures/svn/working"
# Init the base theme again so that the working SVN script is detected
_bash_it_appearance_scm_init
scm
# Make sure that the SVN command is used
assert_equal "$SCM" "$SCM_SVN"
}
@test 'themes base: SVN: detect SVN repo even from a subfolder' {
repo="$(setup_repo)"
pushd "$repo"
mkdir foo
pushd foo
setup_svn_path "$BASH_IT/test/fixtures/svn/working"
# init the base theme again so that the working SVN script is detected
_bash_it_appearance_scm_init
scm
# Make sure that the SVN command is used
assert_equal "$SCM" "$SCM_SVN"
}
@test 'themes base: SVN: no SCM if no .svn folder can be found' {
repo="$(setup_repo)"
pushd "$repo"
rm -rf .svn
setup_svn_path "$BASH_IT/test/fixtures/svn/working"
# Init the base theme again so that the working SVN script is detected
_bash_it_appearance_scm_init
scm
# Make sure that no SVN command is used
assert_equal "$SCM" "$SCM_NONE"
}
@test 'themes base: SVN: ignore SVN repo when using broken SVN command' {
repo="$(setup_repo)"
pushd "$repo"
setup_svn_path "$BASH_IT/test/fixtures/svn/broken"
# Init the base theme again so that the broken SVN script is detected
_bash_it_appearance_scm_init
scm
# Make sure that no SVN command is not used
assert_equal "$SCM" "$SCM_NONE"
}
@test 'themes base: SVN: ignore SVN repo even from a subfolder when using a broken SVN' {
repo="$(setup_repo)"
pushd "$repo"
mkdir foo
pushd foo
setup_svn_path "$BASH_IT/test/fixtures/svn/broken"
# Init the base theme again so that the broken SVN script is detected
_bash_it_appearance_scm_init
scm
# Make sure that no SVN command is used
assert_equal "$SCM" "$SCM_NONE"
}