Merge pull request #258 from ghthor/osx-testing
OSX/Darwin testing and compatibility - Retest
This commit is contained in:
17
.travis.yml
17
.travis.yml
@@ -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:
|
||||
- sudo apt-get install zsh
|
||||
- echo -e "test_repo_11\ntest_repo_1" | sort
|
||||
|
||||
script:
|
||||
- ./run_tests.sh
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
# Add ignore rule to .git/info/exclude if not already present
|
||||
_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
|
||||
echo "$project_design_dir" >> "$git_dir/info/exclude"
|
||||
fi
|
||||
|
||||
@@ -68,8 +68,8 @@ function git_index() {
|
||||
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"
|
||||
for repo in $(_git_index_dirs_without_home); do
|
||||
echo $(basename $repo) : $repo
|
||||
done | sort | column -t -s ':'
|
||||
echo $(basename $repo | sed "s/ /_/g") : $repo
|
||||
done | sort -t ":" -k1,1 | column -t -s ':'
|
||||
elif [ "$1" = "--count-by-host" ]; then
|
||||
echo -e "=== Producing a report of the number of repos per host...\n"
|
||||
_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
|
||||
IFS=$'\n'
|
||||
for repo in $(echo -e "$(_find_git_repos)\n$(echo $GIT_REPOS | sed "s/:/\\\\n/g")"); do
|
||||
echo $(basename $repo | sed "s/ /_/g") $repo
|
||||
done | sort | cut -d " " -f2- >| "$GIT_REPO_DIR/.git_index"
|
||||
echo $(basename $repo | sed "s/ /_/g"):$repo
|
||||
done | sort -t ":" -k1,1 | cut -d ":" -f2- >| "$GIT_REPO_DIR/.git_index"
|
||||
unset IFS
|
||||
|
||||
if [ "$1" != "--silent" ]; then
|
||||
|
||||
@@ -3,8 +3,15 @@
|
||||
|
||||
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 shell in bash zsh; do
|
||||
for shell in $TEST_SHELLS; do
|
||||
echo "== Running tests with [$shell]: $test"
|
||||
$shell $test || failed=true
|
||||
done
|
||||
|
||||
@@ -7,10 +7,14 @@
|
||||
#
|
||||
# Unit tests for git shell scripts
|
||||
|
||||
export scmbDir="$( cd -P "$( dirname "$0" )" && pwd )/../../.."
|
||||
export scmbDir="$(cd -P "$(dirname "$0")" && pwd)/../../.."
|
||||
|
||||
# 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
|
||||
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/git/repo_index.sh"
|
||||
|
||||
|
||||
# Setup and tear down
|
||||
#-----------------------------------------------------------------------------
|
||||
oneTimeSetUp() {
|
||||
@@ -34,7 +37,10 @@ oneTimeSetUp() {
|
||||
cd $GIT_REPO_DIR
|
||||
# Setup test repos in temp repo dir
|
||||
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
|
||||
|
||||
# Add some nested dirs for testing resursive tab completion
|
||||
@@ -47,7 +53,7 @@ oneTimeSetUp() {
|
||||
mkdir submodules_everywhere
|
||||
cd submodules_everywhere
|
||||
git init
|
||||
cat > .gitmodules <<EOF
|
||||
cat >.gitmodules <<EOF
|
||||
[submodule "very/nested/directory/red_submodule"]
|
||||
[submodule "very/nested/directory/green_submodule"]
|
||||
[submodule "very/nested/directory/blue_submodule"]
|
||||
@@ -55,13 +61,18 @@ EOF
|
||||
mkdir -p "very/nested/directory"
|
||||
cd "very/nested/directory"
|
||||
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
|
||||
|
||||
# Setup some custom repos outside the main repo dir
|
||||
IFS=":"
|
||||
for dir in $GIT_REPOS; do
|
||||
mkdir -p $dir; cd $dir; git init;
|
||||
mkdir -p $dir
|
||||
cd $dir
|
||||
git init
|
||||
done
|
||||
unset IFS
|
||||
|
||||
@@ -85,30 +96,32 @@ index_no_newlines() {
|
||||
tr "\\n" " " < $git_index_file
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Unit tests
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
test_repo_index_command() {
|
||||
git_index --rebuild > /dev/null
|
||||
git_index --rebuild >/dev/null
|
||||
|
||||
# Test that all repos are detected, and sorted alphabetically
|
||||
assertIncludes "$(index_no_newlines)" "bitbucket.*\
|
||||
blue_submodule.*\
|
||||
github.*\
|
||||
green_submodule.*\
|
||||
red_submodule.*\
|
||||
source_forge.*\
|
||||
submodules_everywhere.*\
|
||||
test_repo_11.*\
|
||||
test_repo_1"
|
||||
|
||||
assertIncludes "$(index_no_newlines)" $(
|
||||
cat <<EXPECT | sort -t "." -k1,1 | tr -d '\n' | awk '{print ".*"$1}'
|
||||
bitbucket.*
|
||||
blue_submodule.*
|
||||
github.*
|
||||
green_submodule.*
|
||||
red_submodule.*
|
||||
source_forge.*
|
||||
submodules_everywhere.*
|
||||
test_repo_11.*
|
||||
test_repo_1.*
|
||||
EXPECT
|
||||
)
|
||||
}
|
||||
|
||||
test_check_git_index() {
|
||||
ensureIndex
|
||||
echo "should not be regenerated" >> $git_index_file
|
||||
echo "should not be regenerated" >>$git_index_file
|
||||
_check_git_index
|
||||
# Test that index is not rebuilt unless empty
|
||||
assertIncludes "$(index_no_newlines)" "should not be regenerated"
|
||||
@@ -125,7 +138,7 @@ test_git_index_count() {
|
||||
test_repo_list() {
|
||||
ensureIndex
|
||||
list=$(git_index --list)
|
||||
assertIncludes "$list" "bitbucket" || return
|
||||
assertIncludes "$list" "bitbucket" || return
|
||||
assertIncludes "$list" "blue_submodule" || return
|
||||
assertIncludes "$list" "test_repo_11"
|
||||
}
|
||||
@@ -133,16 +146,26 @@ test_repo_list() {
|
||||
# Test matching rules for changing directory
|
||||
test_git_index_changing_directory() {
|
||||
ensureIndex
|
||||
git_index "github"; assertEquals "$GIT_REPO_DIR/github" "$PWD"
|
||||
git_index "github/"; assertEquals "$GIT_REPO_DIR/github" "$PWD"
|
||||
git_index "bucket"; assertEquals "$GIT_REPO_DIR/bitbucket" "$PWD"
|
||||
git_index "testcaps"; assertEquals "$GIT_REPO_DIR/TestCaps" "$PWD"
|
||||
git_index "green_sub"; 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_11" "$PWD"
|
||||
git_index "github/videos/octocat/live_action"; assertEquals "$GIT_REPO_DIR/github/videos/octocat/live_action" "$PWD"
|
||||
git_index "github"
|
||||
assertEquals "$GIT_REPO_DIR/github" "$PWD"
|
||||
git_index "github/"
|
||||
assertEquals "$GIT_REPO_DIR/github" "$PWD"
|
||||
git_index "bucket"
|
||||
assertEquals "$GIT_REPO_DIR/bitbucket" "$PWD"
|
||||
git_index "testcaps"
|
||||
assertEquals "$GIT_REPO_DIR/TestCaps" "$PWD"
|
||||
git_index "green_sub"
|
||||
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() {
|
||||
@@ -163,16 +186,15 @@ test_git_index_tab_completion() {
|
||||
# Test completion for project sub-directories when project ends with '/'
|
||||
COMP_WORDS="github/"
|
||||
_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
|
||||
assertNotIncludes "$(tab_completions)" "github/.git/"
|
||||
assertIncludes "$(tab_completions)" "github/.im_hidden/"
|
||||
assertIncludes "$(tab_completions)" "github/.im_hidden/"
|
||||
|
||||
COMP_WORDS="github/videos/"
|
||||
_git_index_tab_completion
|
||||
assertIncludes "$(tab_completions)" "github/videos/octocat/"
|
||||
|
||||
|
||||
# Test that completion checks for other matching projects even if one matches perfectly
|
||||
COMP_WORDS="test_repo_1"
|
||||
_git_index_tab_completion
|
||||
@@ -180,7 +202,6 @@ test_git_index_tab_completion() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Test changing to top-level directory (when arg begins with '/')
|
||||
test_changing_to_top_level_directory() {
|
||||
mkdir "$GIT_REPO_DIR/gems"
|
||||
@@ -188,8 +209,6 @@ test_changing_to_top_level_directory() {
|
||||
assertEquals "$GIT_REPO_DIR/gems" "$PWD"
|
||||
}
|
||||
|
||||
|
||||
# load and run shUnit2
|
||||
# Call this function to run tests
|
||||
source "$scmbDir/test/support/shunit2"
|
||||
|
||||
|
||||
@@ -32,11 +32,15 @@ oneTimeSetUp() {
|
||||
|
||||
# Test functions
|
||||
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 rm_path="$(which rm)"
|
||||
export sed_path="$(which sed)"
|
||||
export cat_pathj="$(which cat)"
|
||||
export cat_path="$(which cat)"
|
||||
|
||||
# Test aliases
|
||||
alias mv="nocorrect $mv_path"
|
||||
alias rm="$rm_path --option"
|
||||
alias sed="$sed_path"
|
||||
@@ -63,11 +67,11 @@ assertAliasEquals(){
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
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 $rm_path --option" "rm"
|
||||
assertAliasEquals "exec_scmb_expand_args $sed_path" "sed"
|
||||
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)" "exec_scmb_expand_args __original_ln"
|
||||
}
|
||||
@@ -76,7 +80,15 @@ test_ls_with_file_shortcuts() {
|
||||
export git_env_char="e"
|
||||
|
||||
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
|
||||
TEST_DIR=$(pwd -P)
|
||||
|
||||
touch 'test file' 'test_file'
|
||||
mkdir -p "a [b]" 'a "b"' "a 'b'"
|
||||
touch "a \"b\"/c"
|
||||
@@ -87,7 +99,7 @@ test_ls_with_file_shortcuts() {
|
||||
ls_with_file_shortcuts > $temp_file
|
||||
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" "[2] a 'b'" F
|
||||
assertIncludes "$ls_output" '[3] a [b]' F
|
||||
|
||||
@@ -29,6 +29,7 @@ oneTimeSetUp() {
|
||||
export ga_auto_remove="yes"
|
||||
|
||||
testRepo=$(mktemp -d -t scm_breeze.XXXXXXXXXX)
|
||||
testRepo=$(cd $testRepo && pwd -P)
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
|
||||
@@ -15,7 +15,7 @@ fi
|
||||
|
||||
# Strip color codes from a string
|
||||
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
|
||||
@@ -34,7 +34,7 @@ verboseGitCommands() {
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
@@ -46,4 +46,3 @@ assertIncludes() {
|
||||
assertNotIncludes() {
|
||||
assertFalse "'$1' should not have contained '$2'" $(_includes "$@")
|
||||
}
|
||||
|
||||
|
||||
32
test/support/travisci_deps.sh
Executable file
32
test/support/travisci_deps.sh
Executable 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
|
||||
Reference in New Issue
Block a user