Run shfmt

This commit is contained in:
Willa Drengwitz
2018-08-31 08:58:41 -04:00
parent d0c8329137
commit 89cf0eb6ad

View File

@@ -7,10 +7,14 @@
# #
# Unit tests for git shell scripts # Unit tests for git shell scripts
export scmbDir="$( cd -P "$( dirname "$0" )" && pwd )/../../.." export scmbDir="$(cd -P "$(dirname "$0")" && pwd)/../../.."
# Zsh compatibility # Zsh compatibility
if [ -n "${ZSH_VERSION:-}" ]; then shell="zsh"; SHUNIT_PARENT=$0; setopt shwordsplit; fi if [ -n "${ZSH_VERSION:-}" ]; then
shell="zsh"
SHUNIT_PARENT=$0
setopt shwordsplit
fi
# Load test helpers # Load test helpers
source "$scmbDir/test/support/test_helper.sh" source "$scmbDir/test/support/test_helper.sh"
@@ -19,7 +23,6 @@ source "$scmbDir/test/support/test_helper.sh"
source "$scmbDir/lib/scm_breeze.sh" source "$scmbDir/lib/scm_breeze.sh"
source "$scmbDir/lib/git/repo_index.sh" source "$scmbDir/lib/git/repo_index.sh"
# Setup and tear down # Setup and tear down
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
oneTimeSetUp() { oneTimeSetUp() {
@@ -34,7 +37,10 @@ oneTimeSetUp() {
cd $GIT_REPO_DIR cd $GIT_REPO_DIR
# Setup test repos in temp repo dir # Setup test repos in temp repo dir
for repo in github bitbucket source_forge TestCaps; do for repo in github bitbucket source_forge TestCaps; do
mkdir $repo; cd $repo; git init; cd - > /dev/null mkdir $repo
cd $repo
git init
cd - >/dev/null
done done
# Add some nested dirs for testing resursive tab completion # Add some nested dirs for testing resursive tab completion
@@ -47,7 +53,7 @@ oneTimeSetUp() {
mkdir submodules_everywhere mkdir submodules_everywhere
cd submodules_everywhere cd submodules_everywhere
git init git init
cat > .gitmodules <<EOF cat >.gitmodules <<EOF
[submodule "very/nested/directory/red_submodule"] [submodule "very/nested/directory/red_submodule"]
[submodule "very/nested/directory/green_submodule"] [submodule "very/nested/directory/green_submodule"]
[submodule "very/nested/directory/blue_submodule"] [submodule "very/nested/directory/blue_submodule"]
@@ -55,13 +61,18 @@ EOF
mkdir -p "very/nested/directory" mkdir -p "very/nested/directory"
cd "very/nested/directory" cd "very/nested/directory"
for repo in red_submodule green_submodule blue_submodule; do for repo in red_submodule green_submodule blue_submodule; do
mkdir $repo; cd $repo; git init; cd - > /dev/null mkdir $repo
cd $repo
git init
cd - >/dev/null
done done
# Setup some custom repos outside the main repo dir # Setup some custom repos outside the main repo dir
IFS=":" IFS=":"
for dir in $GIT_REPOS; do for dir in $GIT_REPOS; do
mkdir -p $dir; cd $dir; git init; mkdir -p $dir
cd $dir
git init
done done
unset IFS unset IFS
@@ -85,13 +96,12 @@ index_no_newlines() {
tr "\\n" " " < $git_index_file tr "\\n" " " < $git_index_file
} }
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Unit tests # Unit tests
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
test_repo_index_command() { test_repo_index_command() {
git_index --rebuild > /dev/null git_index --rebuild >/dev/null
# Test that all repos are detected, and sorted alphabetically # Test that all repos are detected, and sorted alphabetically
assertIncludes "$(index_no_newlines)" $( assertIncludes "$(index_no_newlines)" $(
@@ -111,7 +121,7 @@ EXPECT
test_check_git_index() { test_check_git_index() {
ensureIndex ensureIndex
echo "should not be regenerated" >> $git_index_file echo "should not be regenerated" >>$git_index_file
_check_git_index _check_git_index
# Test that index is not rebuilt unless empty # Test that index is not rebuilt unless empty
assertIncludes "$(index_no_newlines)" "should not be regenerated" assertIncludes "$(index_no_newlines)" "should not be regenerated"
@@ -136,16 +146,26 @@ test_repo_list() {
# Test matching rules for changing directory # Test matching rules for changing directory
test_git_index_changing_directory() { test_git_index_changing_directory() {
ensureIndex ensureIndex
git_index "github"; assertEquals "$GIT_REPO_DIR/github" "$PWD" git_index "github"
git_index "github/"; assertEquals "$GIT_REPO_DIR/github" "$PWD" assertEquals "$GIT_REPO_DIR/github" "$PWD"
git_index "bucket"; assertEquals "$GIT_REPO_DIR/bitbucket" "$PWD" git_index "github/"
git_index "testcaps"; assertEquals "$GIT_REPO_DIR/TestCaps" "$PWD" assertEquals "$GIT_REPO_DIR/github" "$PWD"
git_index "green_sub"; assertEquals "$GIT_REPO_DIR/submodules_everywhere/very/nested/directory/green_submodule" "$PWD" git_index "bucket"
git_index "_submod"; assertEquals "$GIT_REPO_DIR/submodules_everywhere/very/nested/directory/blue_submodule" "$PWD" assertEquals "$GIT_REPO_DIR/bitbucket" "$PWD"
git_index "test_repo_1"; assertEquals "/tmp/test_repo_1" "$PWD" git_index "testcaps"
git_index "test_repo_11"; assertEquals "/tmp/test_repo_11" "$PWD" assertEquals "$GIT_REPO_DIR/TestCaps" "$PWD"
git_index "test_repo_"; assertEquals "/tmp/test_repo_1" "$PWD" git_index "green_sub"
git_index "github/videos/octocat/live_action"; assertEquals "$GIT_REPO_DIR/github/videos/octocat/live_action" "$PWD" assertEquals "$GIT_REPO_DIR/submodules_everywhere/very/nested/directory/green_submodule" "$PWD"
git_index "_submod"
assertEquals "$GIT_REPO_DIR/submodules_everywhere/very/nested/directory/blue_submodule" "$PWD"
git_index "test_repo_1"
assertEquals "/tmp/test_repo_1" "$PWD"
git_index "test_repo_11"
assertEquals "/tmp/test_repo_11" "$PWD"
git_index "test_repo_"
assertEquals "/tmp/test_repo_1" "$PWD"
git_index "github/videos/octocat/live_action"
assertEquals "$GIT_REPO_DIR/github/videos/octocat/live_action" "$PWD"
} }
test_git_index_tab_completion() { test_git_index_tab_completion() {
@@ -175,7 +195,6 @@ test_git_index_tab_completion() {
_git_index_tab_completion _git_index_tab_completion
assertIncludes "$(tab_completions)" "github/videos/octocat/" assertIncludes "$(tab_completions)" "github/videos/octocat/"
# Test that completion checks for other matching projects even if one matches perfectly # Test that completion checks for other matching projects even if one matches perfectly
COMP_WORDS="test_repo_1" COMP_WORDS="test_repo_1"
_git_index_tab_completion _git_index_tab_completion
@@ -183,7 +202,6 @@ test_git_index_tab_completion() {
fi fi
} }
# Test changing to top-level directory (when arg begins with '/') # Test changing to top-level directory (when arg begins with '/')
test_changing_to_top_level_directory() { test_changing_to_top_level_directory() {
mkdir "$GIT_REPO_DIR/gems" mkdir "$GIT_REPO_DIR/gems"
@@ -191,8 +209,6 @@ test_changing_to_top_level_directory() {
assertEquals "$GIT_REPO_DIR/gems" "$PWD" assertEquals "$GIT_REPO_DIR/gems" "$PWD"
} }
# load and run shUnit2 # load and run shUnit2
# Call this function to run tests # Call this function to run tests
source "$scmbDir/test/support/shunit2" source "$scmbDir/test/support/shunit2"