Skip to content

Commit

Permalink
example tests
Browse files Browse the repository at this point in the history
Signed-off-by: meonlol <[email protected]>
  • Loading branch information
meonlol committed Dec 26, 2017
1 parent d84ca13 commit 753b877
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ __gradle-set-build-file() {
gradle_build_file="$project_root_dir/build.gradle"
if [[ -f "$project_root_dir/settings.gradle" ]]; then
local build_file_name=$(grep "^rootProject\.buildFileName" "$project_root_dir/settings.gradle" | \
sed -n -e "s/rootProject\.buildFileName = [\'\"]\(.*\)[\'\"]/\1/p")
sed -n -e "s/rootProject\.buildFileName[[:space:]]*=[[:space:]]*[\'\"]\(.*\)[\'\"]/\1/p")
gradle_build_file="$project_root_dir/${build_file_name:-build.gradle}"
fi
}
Expand Down
49 changes: 49 additions & 0 deletions test_gradle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

_TEST_HOME=./tmp
_ORIG_HOME=$HOME

setup() {
source gradle-completion.bash
mkdir -p $_TEST_HOME
HOME=$_TEST_HOME
}

teardown() {
rm -rf $_TEST_HOME
HOME=$_ORIG_HOME
}

test__should_init_cache_home() {
__gradle-init-cache-dir

if [[ ! -d $_TEST_HOME/.gradle/completion ]]; then
fail "Expected the home directory to be created."
fi
}

test__should_set_build_file() {
touch $_TEST_HOME/build.gradle
project_root_dir=$_TEST_HOME

__gradle-set-build-file

assertEquals "$_TEST_HOME/build.gradle" "$gradle_build_file"
}

test__should_set_build_file_for_custom_name() {
echo "rootProject.buildFileName = 'sample.gradle'" > $_TEST_HOME/settings.gradle
project_root_dir=$_TEST_HOME

__gradle-set-build-file

assertEquals "$_TEST_HOME/sample.gradle" "$gradle_build_file"
}

test__should_set_build_file_for_custom_name_no_spaces() {
echo "rootProject.buildFileName='sample.gradle'" > $_TEST_HOME/settings.gradle
project_root_dir=$_TEST_HOME

__gradle-set-build-file

assertEquals "$_TEST_HOME/sample.gradle" "$gradle_build_file"
}

0 comments on commit 753b877

Please sign in to comment.