Merge pull request #258 from ghthor/osx-testing

OSX/Darwin testing and compatibility - Retest
This commit is contained in:
Wilhelmina Drengwitz
2018-08-31 09:03:34 -04:00
committed by GitHub
9 changed files with 136 additions and 53 deletions

View File

@@ -1,3 +1,16 @@
script: ./run_tests.sh os:
- linux
- osx
env:
- TEST_SHELLS=bash
- TEST_SHELLS=zsh
install:
- ./test/support/travisci_deps.sh
before_script: before_script:
- sudo apt-get install zsh - echo -e "test_repo_11\ntest_repo_1" | sort
script:
- ./run_tests.sh

View File

@@ -23,7 +23,7 @@
# Add ignore rule to .git/info/exclude if not already present # Add ignore rule to .git/info/exclude if not already present
_design_add_git_exclude(){ _design_add_git_exclude(){
local git_dir="$(cd $1 && readlink -m $(git rev-parse --git-dir))" local git_dir="$(cd $1 && cd `git rev-parse --git-dir` && pwd -P)"
if [ -e "$git_dir/info/exclude" ] && ! $(grep -q "$project_design_dir" "$git_dir/info/exclude"); then if [ -e "$git_dir/info/exclude" ] && ! $(grep -q "$project_design_dir" "$git_dir/info/exclude"); then
echo "$project_design_dir" >> "$git_dir/info/exclude" echo "$project_design_dir" >> "$git_dir/info/exclude"
fi fi

View File

@@ -68,8 +68,8 @@ function git_index() {
elif [ "$1" = "--list" ] || [ "$1" = "-l" ]; then elif [ "$1" = "--list" ] || [ "$1" = "-l" ]; then
echo -e "$_bld_col$(_git_index_count)$_txt_col Git repositories in $_bld_col$GIT_REPO_DIR$_txt_col:\n" echo -e "$_bld_col$(_git_index_count)$_txt_col Git repositories in $_bld_col$GIT_REPO_DIR$_txt_col:\n"
for repo in $(_git_index_dirs_without_home); do for repo in $(_git_index_dirs_without_home); do
echo $(basename $repo) : $repo echo $(basename $repo | sed "s/ /_/g") : $repo
done | sort | column -t -s ':' done | sort -t ":" -k1,1 | column -t -s ':'
elif [ "$1" = "--count-by-host" ]; then elif [ "$1" = "--count-by-host" ]; then
echo -e "=== Producing a report of the number of repos per host...\n" echo -e "=== Producing a report of the number of repos per host...\n"
_git_index_batch_cmd git remote -v | \grep "origin.*(fetch)" | _git_index_batch_cmd git remote -v | \grep "origin.*(fetch)" |
@@ -148,8 +148,8 @@ function _rebuild_git_index() {
# Get repos from src dir and custom dirs, then sort by basename # Get repos from src dir and custom dirs, then sort by basename
IFS=$'\n' IFS=$'\n'
for repo in $(echo -e "$(_find_git_repos)\n$(echo $GIT_REPOS | sed "s/:/\\\\n/g")"); do for repo in $(echo -e "$(_find_git_repos)\n$(echo $GIT_REPOS | sed "s/:/\\\\n/g")"); do
echo $(basename $repo | sed "s/ /_/g") $repo echo $(basename $repo | sed "s/ /_/g"):$repo
done | sort | cut -d " " -f2- >| "$GIT_REPO_DIR/.git_index" done | sort -t ":" -k1,1 | cut -d ":" -f2- >| "$GIT_REPO_DIR/.git_index"
unset IFS unset IFS
if [ "$1" != "--silent" ]; then if [ "$1" != "--silent" ]; then

View File

@@ -3,8 +3,15 @@
failed=false failed=false
# allow list of shells to run tests in to be overriden by environment variable
# if empty or null, use defaults
if [ -z "$TEST_SHELLS" ]; then
TEST_SHELLS="bash zsh"
fi
echo "== Will run all tests with following shells: ${TEST_SHELLS}"
for test in $(find test/lib -name *_test.sh); do for test in $(find test/lib -name *_test.sh); do
for shell in bash zsh; do for shell in $TEST_SHELLS; do
echo "== Running tests with [$shell]: $test" echo "== Running tests with [$shell]: $test"
$shell $test || failed=true $shell $test || failed=true
done done

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,30 +96,32 @@ 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)" "bitbucket.*\ assertIncludes "$(index_no_newlines)" $(
blue_submodule.*\ cat <<EXPECT | sort -t "." -k1,1 | tr -d '\n' | awk '{print ".*"$1}'
github.*\ bitbucket.*
green_submodule.*\ blue_submodule.*
red_submodule.*\ github.*
source_forge.*\ green_submodule.*
submodules_everywhere.*\ red_submodule.*
test_repo_11.*\ source_forge.*
test_repo_1" submodules_everywhere.*
test_repo_11.*
test_repo_1.*
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"
@@ -125,7 +138,7 @@ test_git_index_count() {
test_repo_list() { test_repo_list() {
ensureIndex ensureIndex
list=$(git_index --list) list=$(git_index --list)
assertIncludes "$list" "bitbucket" || return assertIncludes "$list" "bitbucket" || return
assertIncludes "$list" "blue_submodule" || return assertIncludes "$list" "blue_submodule" || return
assertIncludes "$list" "test_repo_11" assertIncludes "$list" "test_repo_11"
} }
@@ -133,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_11" "$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() {
@@ -163,16 +186,15 @@ test_git_index_tab_completion() {
# Test completion for project sub-directories when project ends with '/' # Test completion for project sub-directories when project ends with '/'
COMP_WORDS="github/" COMP_WORDS="github/"
_git_index_tab_completion _git_index_tab_completion
assertIncludes "$(tab_completions)" "github/videos/" assertIncludes "$(tab_completions)" "github/videos/"
# Check that '.git/' is filtered from completion, but other hidden dirs are available # Check that '.git/' is filtered from completion, but other hidden dirs are available
assertNotIncludes "$(tab_completions)" "github/.git/" assertNotIncludes "$(tab_completions)" "github/.git/"
assertIncludes "$(tab_completions)" "github/.im_hidden/" assertIncludes "$(tab_completions)" "github/.im_hidden/"
COMP_WORDS="github/videos/" COMP_WORDS="github/videos/"
_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
@@ -180,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"
@@ -188,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"

View File

@@ -32,11 +32,15 @@ oneTimeSetUp() {
# Test functions # Test functions
function ln() { ln $@; } function ln() { ln $@; }
# Test aliases
# Before aliasing, get original locations so we can compare them in the test
unalias mv rm sed cat 2>/dev/null
export mv_path="$(which mv)" export mv_path="$(which mv)"
export rm_path="$(which rm)" export rm_path="$(which rm)"
export sed_path="$(which sed)" export sed_path="$(which sed)"
export cat_pathj="$(which cat)" export cat_path="$(which cat)"
# Test aliases
alias mv="nocorrect $mv_path" alias mv="nocorrect $mv_path"
alias rm="$rm_path --option" alias rm="$rm_path --option"
alias sed="$sed_path" alias sed="$sed_path"
@@ -63,11 +67,11 @@ assertAliasEquals(){
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
test_shell_command_wrapping() { test_shell_command_wrapping() {
assertAliasEquals "exec_scmb_expand_args $rm_path --option" "rm"
assertAliasEquals "exec_scmb_expand_args nocorrect $mv_path" "mv" assertAliasEquals "exec_scmb_expand_args nocorrect $mv_path" "mv"
assertAliasEquals "exec_scmb_expand_args $rm_path --option" "rm"
assertAliasEquals "exec_scmb_expand_args $sed_path" "sed" assertAliasEquals "exec_scmb_expand_args $sed_path" "sed"
assertAliasEquals "exec_scmb_expand_args $cat_path" "cat" assertAliasEquals "exec_scmb_expand_args $cat_path" "cat"
assertAliasEquals "exec_scmb_expand_args builtin cd" "cd" assertAliasEquals "exec_scmb_expand_args builtin cd" "cd"
assertIncludes "$(declare -f ln)" "ln ()" assertIncludes "$(declare -f ln)" "ln ()"
assertIncludes "$(declare -f ln)" "exec_scmb_expand_args __original_ln" assertIncludes "$(declare -f ln)" "exec_scmb_expand_args __original_ln"
} }
@@ -76,7 +80,15 @@ test_ls_with_file_shortcuts() {
export git_env_char="e" export git_env_char="e"
TEST_DIR=$(mktemp -d -t scm_breeze.XXXXXXXXXX) TEST_DIR=$(mktemp -d -t scm_breeze.XXXXXXXXXX)
# Darwin actually symlinks /var inside /private, but mktemp reports back the
# logical pathat time of file creation. So make sure we always get the
# full physical path to be absolutely certain when doing comparisons later,
# because thats how the Ruby status_shortcuts.rb script is going to obtain
# them.
cd $TEST_DIR cd $TEST_DIR
TEST_DIR=$(pwd -P)
touch 'test file' 'test_file' touch 'test file' 'test_file'
mkdir -p "a [b]" 'a "b"' "a 'b'" mkdir -p "a [b]" 'a "b"' "a 'b'"
touch "a \"b\"/c" touch "a \"b\"/c"
@@ -87,7 +99,7 @@ test_ls_with_file_shortcuts() {
ls_with_file_shortcuts > $temp_file ls_with_file_shortcuts > $temp_file
ls_output=$(<$temp_file strip_colors) ls_output=$(<$temp_file strip_colors)
# Compare as fixed strings (F), instead of regex (P) # Compare as fixed strings (F), instead of normal grep behavior
assertIncludes "$ls_output" '[1] a "b"' F assertIncludes "$ls_output" '[1] a "b"' F
assertIncludes "$ls_output" "[2] a 'b'" F assertIncludes "$ls_output" "[2] a 'b'" F
assertIncludes "$ls_output" '[3] a [b]' F assertIncludes "$ls_output" '[3] a [b]' F

View File

@@ -29,6 +29,7 @@ oneTimeSetUp() {
export ga_auto_remove="yes" export ga_auto_remove="yes"
testRepo=$(mktemp -d -t scm_breeze.XXXXXXXXXX) testRepo=$(mktemp -d -t scm_breeze.XXXXXXXXXX)
testRepo=$(cd $testRepo && pwd -P)
} }
oneTimeTearDown() { oneTimeTearDown() {

View File

@@ -15,7 +15,7 @@ fi
# Strip color codes from a string # Strip color codes from a string
strip_colors() { strip_colors() {
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" perl -pe 's/\e\[[\d;]*m//g'
} }
# Print space separated tab completion options # Print space separated tab completion options
@@ -34,7 +34,7 @@ verboseGitCommands() {
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
_includes() { _includes() {
if [ -n "$3" ]; then regex="$3"; else regex=P; fi if [ -n "$3" ]; then regex="$3"; else regex=''; fi
if echo "$1" | grep -q$regex "$2"; then echo 0; else echo 1; fi if echo "$1" | grep -q$regex "$2"; then echo 0; else echo 1; fi
} }
@@ -46,4 +46,3 @@ assertIncludes() {
assertNotIncludes() { assertNotIncludes() {
assertFalse "'$1' should not have contained '$2'" $(_includes "$@") assertFalse "'$1' should not have contained '$2'" $(_includes "$@")
} }

32
test/support/travisci_deps.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Installs dependencies for travis-ci environments.
# Install dependencies, which looks to be just bash & zsh.
#
# Darwin has zsh preinstalled already, so only need to install on Ubuntu.
#
# Note: $TRAVIS_OS_NAME will only be set on text boxes with multi-os enabled,
# so use negation test so it will fail gracefully on normal Travis linux setup.
if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then
# okay, so we know we're probably on a linux box (or at least not an osx box)
# at this point. do we need to install zsh? let's say the default case is no:
needs_zsh=false
# check if zsh is listed in the TEST_SHELLS environment variable, set by
# our travis-ci build matrix.
if [[ $TEST_SHELLS =~ zsh ]]; then needs_zsh=true; fi
# if there is NO $TEST_SHELLS env variable persent (which should never happen,
# but maybe someone has been monkeying with the .travis.yml), run_tests.sh is
# going to fall back onto the default of testing everything, so we need zsh.
if [[ -z "$TEST_SHELLS" ]]; then needs_zsh=true; fi
# finally, we install zsh if needed!
if $needs_zsh ; then
sudo apt-get install zsh
else
echo "No deps required."
fi
fi