From 2f9199196760fa5f60253cf20c81f8265339c6a5 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 2 Oct 2017 11:17:52 +0200 Subject: [PATCH 01/10] Added bats-core as a Git submodule --- .gitmodules | 3 +++ test_lib/bats-core | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 test_lib/bats-core diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..d006fc41 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test_lib/bats-core"] + path = test_lib/bats-core + url = https://github.com/bats-core/bats-core diff --git a/test_lib/bats-core b/test_lib/bats-core new file mode 160000 index 00000000..7b032e4b --- /dev/null +++ b/test_lib/bats-core @@ -0,0 +1 @@ +Subproject commit 7b032e4b232666ee24f150338bad73de65c7b99d From 8319545b0a1f33b450bc7bfe0ed6768445fd9495 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 2 Oct 2017 11:50:09 +0200 Subject: [PATCH 02/10] Switched to Bats-core as a submodule Can't use the official v0.4.0 release, since our tests rely on a change that was made after the release of v0.4.0. This code currently uses an unversioned commit of the bats-core repo, we will switch to a supported version once it has been released, e.g. v0.4.1. --- test/bash_it/bash_it.bats | 4 +++- test/completion/bash-it.completion.bats | 2 +- test/install/install.bats | 2 +- test/install/uninstall.bats | 2 +- test/lib/helpers.bats | 2 +- test/lib/search.bats | 2 +- test/plugins/ruby.plugin.bats | 2 +- test/run | 7 +++++-- test_lib/bats-core | 2 +- 9 files changed, 15 insertions(+), 10 deletions(-) diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index ccd0c9a5..2957b956 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -6,9 +6,11 @@ load ../../lib/composure function local_setup { mkdir -p "$BASH_IT" lib_directory="$(cd "$(dirname "$0")" && pwd)" + echo "Bi : $BASH_IT" + echo "Lib: $lib_directory" # Use rsync to copy Bash-it to the temp folder # rsync is faster than cp, since we can exclude the large ".git" folder - rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT" rm -rf "$BASH_IT"/enabled rm -rf "$BASH_IT"/aliases/enabled diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index eb77edae..6b93afeb 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -9,7 +9,7 @@ function local_setup { lib_directory="$(cd "$(dirname "$0")" && pwd)" # Use rsync to copy Bash-it to the temp folder # rsync is faster than cp, since we can exclude the large ".git" folder - rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT" rm -rf "$BASH_IT"/enabled rm -rf "$BASH_IT"/aliases/enabled diff --git a/test/install/install.bats b/test/install/install.bats index acb41e0a..4fb3d0a9 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -18,7 +18,7 @@ function local_setup { lib_directory="$(cd "$(dirname "$0")" && pwd)" # Use rsync to copy Bash-it to the temp folder # rsync is faster than cp, since we can exclude the large ".git" folder - rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT" rm -rf "$BASH_IT"/enabled rm -rf "$BASH_IT"/aliases/enabled diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index 6c7ae561..45af20bc 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -18,7 +18,7 @@ function local_setup { lib_directory="$(cd "$(dirname "$0")" && pwd)" # Use rsync to copy Bash-it to the temp folder # rsync is faster than cp, since we can exclude the large ".git" folder - rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT" rm -rf "$BASH_IT"/enabled rm -rf "$BASH_IT"/aliases/enabled diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 7398e08a..92fbf117 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -13,7 +13,7 @@ function local_setup { lib_directory="$(cd "$(dirname "$0")" && pwd)" # Use rsync to copy Bash-it to the temp folder # rsync is faster than cp, since we can exclude the large ".git" folder - rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT" rm -rf "$BASH_IT"/enabled rm -rf "$BASH_IT"/aliases/enabled diff --git a/test/lib/search.bats b/test/lib/search.bats index e00feee5..0993d0b1 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -17,7 +17,7 @@ function local_setup { lib_directory="$(cd "$(dirname "$0")" && pwd)" # Use rsync to copy Bash-it to the temp folder # rsync is faster than cp, since we can exclude the large ".git" folder - rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT" rm -rf "$BASH_IT"/enabled rm -rf "$BASH_IT"/aliases/enabled diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index a57e45fc..87c971b2 100755 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -10,7 +10,7 @@ function local_setup { lib_directory="$(cd "$(dirname "$0")" && pwd)" # Use rsync to copy Bash-it to the temp folder # rsync is faster than cp, since we can exclude the large ".git" folder - rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT" rm -rf "$BASH_IT"/enabled rm -rf "$BASH_IT"/aliases/enabled diff --git a/test/run b/test/run index bd4b1c61..7bbbb511 100755 --- a/test/run +++ b/test/run @@ -1,12 +1,15 @@ #!/usr/bin/env bash test_directory="$(cd "$(dirname "$0")" && pwd)" -bats_executable="${test_directory}/../bats/bin/bats" +#bats_executable="${test_directory}/../bats/bin/bats" +bats_executable="${test_directory}/../test_lib/bats-core/bin/bats" [ ! -e $bats_executable ] && \ - git clone --depth 1 https://github.com/sstephenson/bats.git ${test_directory}/../bats + git submodule init && git submodule update if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi +echo "Bats: $bats_executable" + exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes} diff --git a/test_lib/bats-core b/test_lib/bats-core index 7b032e4b..85388685 160000 --- a/test_lib/bats-core +++ b/test_lib/bats-core @@ -1 +1 @@ -Subproject commit 7b032e4b232666ee24f150338bad73de65c7b99d +Subproject commit 85388685632f85d5a1c32e6bca2deec401964cf7 From c1c29ccc42b57aa1d01032cb04007b8924349ea5 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 2 Oct 2017 16:23:40 +0200 Subject: [PATCH 03/10] Added some more bats-* libs for testing --- .gitmodules | 9 +++++++++ test_lib/bats-assert | 1 + test_lib/bats-file | 1 + test_lib/bats-support | 1 + 4 files changed, 12 insertions(+) create mode 160000 test_lib/bats-assert create mode 160000 test_lib/bats-file create mode 160000 test_lib/bats-support diff --git a/.gitmodules b/.gitmodules index d006fc41..095a6a5e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,12 @@ [submodule "test_lib/bats-core"] path = test_lib/bats-core url = https://github.com/bats-core/bats-core +[submodule "test_lib/bats-support"] + path = test_lib/bats-support + url = https://github.com/ztombol/bats-support +[submodule "test_lib/bats-assert"] + path = test_lib/bats-assert + url = https://github.com/ztombol/bats-assert +[submodule "test_lib/bats-file"] + path = test_lib/bats-file + url = https://github.com/ztombol/bats-file diff --git a/test_lib/bats-assert b/test_lib/bats-assert new file mode 160000 index 00000000..9f88b420 --- /dev/null +++ b/test_lib/bats-assert @@ -0,0 +1 @@ +Subproject commit 9f88b4207da750093baabc4e3f41bf68f0dd3630 diff --git a/test_lib/bats-file b/test_lib/bats-file new file mode 160000 index 00000000..2fddb2b8 --- /dev/null +++ b/test_lib/bats-file @@ -0,0 +1 @@ +Subproject commit 2fddb2b831d65cdf2e411f3b47f4677fbb15729c diff --git a/test_lib/bats-support b/test_lib/bats-support new file mode 160000 index 00000000..004e7076 --- /dev/null +++ b/test_lib/bats-support @@ -0,0 +1 @@ +Subproject commit 004e707638eedd62e0481e8cdc9223ad471f12ee From 2691a5b13843b9269fe4a5459584f5a808767c37 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 4 Oct 2017 08:19:10 +0200 Subject: [PATCH 04/10] Moved to bats-assert for assert functions --- test/bash_it/bash_it.bats | 22 ++--- test/completion/bash-it.completion.bats | 82 ++++++++-------- test/lib/helpers.bats | 118 ++++++++++++------------ test/lib/search.bats | 12 +-- test/plugins/ruby.plugin.bats | 2 +- test/run | 5 +- test/test_helper.bash | 80 ++-------------- test/themes/base.theme.bats | 4 +- 8 files changed, 127 insertions(+), 198 deletions(-) diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index 2957b956..bd3995b6 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -61,7 +61,7 @@ function local_teardown { run alias test_alias &> /dev/null assert_success - assert_line "0" "alias test_alias='b'" + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load aliases in priority order" { @@ -84,7 +84,7 @@ function local_teardown { run alias test_alias &> /dev/null assert_success - assert_line "0" "alias test_alias='a'" + assert_line -n 0 "alias test_alias='a'" } @test "bash-it: load aliases and plugins in priority order" { @@ -109,7 +109,7 @@ function local_teardown { run alias test_alias &> /dev/null assert_success - assert_line "0" "alias test_alias='c'" + assert_line -n 0 "alias test_alias='c'" } @test "bash-it: load aliases, plugins and completions in priority order" { @@ -136,7 +136,7 @@ function local_teardown { run alias test_alias &> /dev/null assert_success # "b" wins since completions are loaded last in the old directory structure - assert_line "0" "alias test_alias='b'" + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" { @@ -163,7 +163,7 @@ function local_teardown { run alias test_alias &> /dev/null assert_success # "b" wins since completions are loaded last in the old directory structure - assert_line "0" "alias test_alias='b'" + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" { @@ -190,7 +190,7 @@ function local_teardown { assert_success # This will be c, loaded from the c plugin, since the individual directories # are loaded one by one. - assert_line "0" "alias test_alias='c'" + assert_line -n 0 "alias test_alias='c'" } @test "bash-it: load global aliases in order" { @@ -212,7 +212,7 @@ function local_teardown { run alias test_alias &> /dev/null assert_success - assert_line "0" "alias test_alias='b'" + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load global aliases in priority order" { @@ -234,7 +234,7 @@ function local_teardown { run alias test_alias &> /dev/null assert_success - assert_line "0" "alias test_alias='a'" + assert_line -n 0 "alias test_alias='a'" } @test "bash-it: load global aliases and plugins in priority order" { @@ -258,7 +258,7 @@ function local_teardown { run alias test_alias &> /dev/null assert_success - assert_line "0" "alias test_alias='c'" + assert_line -n 0 "alias test_alias='c'" } @test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" { @@ -284,7 +284,7 @@ function local_teardown { assert_success # This will be a, loaded from the a aliases, since the global directory # loads all component types at once - assert_line "0" "alias test_alias='a'" + assert_line -n 0 "alias test_alias='a'" } @test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" { @@ -314,7 +314,7 @@ function local_teardown { assert_success # This will be "b", loaded from the b aliases in the individual directory, since # the individual directories are loaded after the global one. - assert_line "0" "alias test_alias='b'" + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load enabled aliases from new structure, priority-based" { diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 6b93afeb..b8aef96f 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -74,92 +74,92 @@ function __check_completion () { @test "completion bash-it: help - show options" { run __check_completion 'bash-it help ' - assert_line "0" "aliases completions migrate plugins update" + assert_line -n 0 "aliases completions migrate plugins update" } @test "completion bash-it: help - aliases v" { run __check_completion 'bash-it help aliases v' - assert_line "0" "vagrant vault vim" + assert_line -n 0 "vagrant vault vim" } @test "completion bash-it: update - show no options" { run __check_completion 'bash-it update ' - assert_line "0" "" + assert_line -n 0 "" } @test "completion bash-it: search - show no options" { run __check_completion 'bash-it search ' - assert_line "0" "" + assert_line -n 0 "" } @test "completion bash-it: migrate - show no options" { run __check_completion 'bash-it migrate ' - assert_line "0" "" + assert_line -n 0 "" } @test "completion bash-it: show options" { run __check_completion 'bash-it ' - assert_line "0" "disable enable help migrate search show update version" + assert_line -n 0 "disable enable help migrate search show update version" } @test "completion bash-it: bash-ti - show options" { run __check_completion 'bash-ti ' - assert_line "0" "disable enable help migrate search show update version" + assert_line -n 0 "disable enable help migrate search show update version" } @test "completion bash-it: shit - show options" { run __check_completion 'shit ' - assert_line "0" "disable enable help migrate search show update version" + assert_line -n 0 "disable enable help migrate search show update version" } @test "completion bash-it: bashit - show options" { run __check_completion 'bashit ' - assert_line "0" "disable enable help migrate search show update version" + assert_line -n 0 "disable enable help migrate search show update version" } @test "completion bash-it: batshit - show options" { run __check_completion 'batshit ' - assert_line "0" "disable enable help migrate search show update version" + assert_line -n 0 "disable enable help migrate search show update version" } @test "completion bash-it: bash_it - show options" { run __check_completion 'bash_it ' - assert_line "0" "disable enable help migrate search show update version" + assert_line -n 0 "disable enable help migrate search show update version" } @test "completion bash-it: show - show options" { run __check_completion 'bash-it show ' - assert_line "0" "aliases completions plugins" + assert_line -n 0 "aliases completions plugins" } @test "completion bash-it: enable - show options" { run __check_completion 'bash-it enable ' - assert_line "0" "alias completion plugin" + assert_line -n 0 "alias completion plugin" } @test "completion bash-it: enable - show options a" { run __check_completion 'bash-it enable a' - assert_line "0" "alias" + assert_line -n 0 "alias" } @test "completion bash-it: disable - show options" { run __check_completion 'bash-it disable ' - assert_line "0" "alias completion plugin" + assert_line -n 0 "alias completion plugin" } @test "completion bash-it: disable - show options a" { run __check_completion 'bash-it disable a' - assert_line "0" "alias" + assert_line -n 0 "alias" } @test "completion bash-it: disable - provide nothing when atom is not enabled" { run __check_completion 'bash-it disable alias ato' - assert_line "0" "" + assert_line -n 0 "" } @test "completion bash-it: disable - provide all when atom is not enabled" { run __check_completion 'bash-it disable alias a' - assert_line "0" "all" + assert_line -n 0 "all" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" { @@ -170,7 +170,7 @@ function __check_completion () { assert [ -L "$BASH_IT/completion/enabled/apm.completion.bash" ] run __check_completion 'bash-it disable alias a' - assert_line "0" "all atom" + assert_line -n 0 "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" { @@ -181,7 +181,7 @@ function __check_completion () { assert [ -L "$BASH_IT/completion/enabled/350---apm.completion.bash" ] run __check_completion 'bash-it disable alias a' - assert_line "0" "all atom" + assert_line -n 0 "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" { @@ -192,7 +192,7 @@ function __check_completion () { assert [ -L "$BASH_IT/enabled/350---apm.completion.bash" ] run __check_completion 'bash-it disable alias a' - assert_line "0" "all atom" + assert_line -n 0 "all atom" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" { @@ -203,7 +203,7 @@ function __check_completion () { assert [ -L "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" ] run __check_completion 'bash-it disable plugin docker' - assert_line "0" "docker-machine" + assert_line -n 0 "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" { @@ -214,7 +214,7 @@ function __check_completion () { assert [ -L "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" ] run __check_completion 'bash-it disable plugin docker' - assert_line "0" "docker-machine" + assert_line -n 0 "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" { @@ -225,7 +225,7 @@ function __check_completion () { assert [ -L "$BASH_IT/enabled/350---docker-machine.plugin.bash" ] run __check_completion 'bash-it disable plugin docker' - assert_line "0" "docker-machine" + assert_line -n 0 "docker-machine" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { @@ -236,7 +236,7 @@ function __check_completion () { assert [ -L "$BASH_IT/plugins/enabled/todo.plugin.bash" ] run __check_completion 'bash-it disable alias to' - assert_line "0" "todo.txt-cli" + assert_line -n 0 "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { @@ -247,7 +247,7 @@ function __check_completion () { assert [ -L "$BASH_IT/plugins/enabled/350---todo.plugin.bash" ] run __check_completion 'bash-it disable alias to' - assert_line "0" "todo.txt-cli" + assert_line -n 0 "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { @@ -258,17 +258,17 @@ function __check_completion () { assert [ -L "$BASH_IT/enabled/350---todo.plugin.bash" ] run __check_completion 'bash-it disable alias to' - assert_line "0" "todo.txt-cli" + assert_line -n 0 "todo.txt-cli" } @test "completion bash-it: enable - provide the atom aliases when not enabled" { run __check_completion 'bash-it enable alias ato' - assert_line "0" "atom" + assert_line -n 0 "atom" } @test "completion bash-it: enable - provide the a* aliases when not enabled" { run __check_completion 'bash-it enable alias a' - assert_line "0" "all ag ansible apt atom" + assert_line -n 0 "all ag ansible apt atom" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" { @@ -276,7 +276,7 @@ function __check_completion () { assert [ -L "$BASH_IT/aliases/enabled/atom.aliases.bash" ] run __check_completion 'bash-it enable alias a' - assert_line "0" "all ag ansible apt" + assert_line -n 0 "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" { @@ -284,7 +284,7 @@ function __check_completion () { assert [ -L "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ] run __check_completion 'bash-it enable alias a' - assert_line "0" "all ag ansible apt" + assert_line -n 0 "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" { @@ -292,7 +292,7 @@ function __check_completion () { assert [ -L "$BASH_IT/enabled/150---atom.aliases.bash" ] run __check_completion 'bash-it enable alias a' - assert_line "0" "all ag ansible apt" + assert_line -n 0 "all ag ansible apt" } @test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the old location and name" { @@ -300,7 +300,7 @@ function __check_completion () { assert [ -L "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" ] run __check_completion 'bash-it enable plugin docker' - assert_line "0" "docker-compose docker-machine docker" + assert_line -n 0 "docker-compose docker-machine docker" } @test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the old location and priority-based name" { @@ -308,7 +308,7 @@ function __check_completion () { assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] run __check_completion 'bash-it enable plugin docker' - assert_line "0" "docker-compose docker-machine docker" + assert_line -n 0 "docker-compose docker-machine docker" } @test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the new location and priority-based name" { @@ -316,7 +316,7 @@ function __check_completion () { assert [ -L "$BASH_IT/enabled/150---docker-compose.aliases.bash" ] run __check_completion 'bash-it enable plugin docker' - assert_line "0" "docker-compose docker-machine docker" + assert_line -n 0 "docker-compose docker-machine docker" } @test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the old location and name" { @@ -324,7 +324,7 @@ function __check_completion () { assert [ -L "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" ] run __check_completion 'bash-it enable completion docker' - assert_line "0" "docker docker-compose docker-machine" + assert_line -n 0 "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the old location and priority-based name" { @@ -332,7 +332,7 @@ function __check_completion () { assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] run __check_completion 'bash-it enable completion docker' - assert_line "0" "docker docker-compose docker-machine" + assert_line -n 0 "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the new location and priority-based name" { @@ -340,7 +340,7 @@ function __check_completion () { assert [ -L "$BASH_IT/enabled/150---docker-compose.aliases.bash" ] run __check_completion 'bash-it enable completion docker' - assert_line "0" "docker docker-compose docker-machine" + assert_line -n 0 "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { @@ -348,7 +348,7 @@ function __check_completion () { assert [ -L "$BASH_IT/plugins/enabled/todo.plugin.bash" ] run __check_completion 'bash-it enable alias to' - assert_line "0" "todo.txt-cli" + assert_line -n 0 "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { @@ -356,7 +356,7 @@ function __check_completion () { assert [ -L "$BASH_IT/plugins/enabled/350---todo.plugin.bash" ] run __check_completion 'bash-it enable alias to' - assert_line "0" "todo.txt-cli" + assert_line -n 0 "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { @@ -364,5 +364,5 @@ function __check_completion () { assert [ -L "$BASH_IT/enabled/350---todo.plugin.bash" ] run __check_completion 'bash-it enable alias to' - assert_line "0" "todo.txt-cli" + assert_line -n 0 "todo.txt-cli" } diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 92fbf117..db956fc2 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -52,17 +52,17 @@ function local_setup { @test "helpers: bash-it help aliases ag" { run bash-it help aliases "ag" - assert_line "0" "ag='ag --smart-case --pager=\"less -MIRFX'" + assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'" } @test "helpers: bash-it help aliases without any aliases enabled" { run bash-it help aliases - assert_line "0" "" + assert_line -n 0 "" } @test "helpers: bash-it help list aliases without any aliases enabled" { run _help-list-aliases "$BASH_IT/aliases/available/ag.aliases.bash" - assert_line "0" "ag:" + assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with ag aliases enabled" { @@ -70,7 +70,7 @@ function local_setup { assert [ -L "$BASH_IT/aliases/enabled/150---ag.aliases.bash" ] run _help-list-aliases "$BASH_IT/aliases/enabled/150---ag.aliases.bash" - assert_line "0" "ag:" + assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" { @@ -78,7 +78,7 @@ function local_setup { assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ] run _help-list-aliases "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" - assert_line "0" "todo.txt-cli:" + assert_line -n 0 "todo.txt-cli:" } @test "helpers: bash-it help list aliases with docker-compose aliases enabled" { @@ -86,7 +86,7 @@ function local_setup { assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] run _help-list-aliases "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - assert_line "0" "docker-compose:" + assert_line -n 0 "docker-compose:" } @test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { @@ -94,7 +94,7 @@ function local_setup { assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] run _help-list-aliases "$BASH_IT/enabled/150---ag.aliases.bash" - assert_line "0" "ag:" + assert_line -n 0 "ag:" } @test "helpers: bash-it help aliases one alias enabled in the old directory" { @@ -102,50 +102,50 @@ function local_setup { assert [ -L "$BASH_IT/aliases/enabled/150---ag.aliases.bash" ] run bash-it help aliases - assert_line "0" "ag:" + assert_line -n 0 "ag:" } @test "helpers: bash-it help aliases one alias enabled in global directory" { run bash-it enable alias "ag" - assert_line "0" 'ag enabled with priority 150.' + assert_line -n 0 'ag enabled with priority 150.' assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] run bash-it enable plugin "aws" - assert_line "0" 'aws enabled with priority 250.' + assert_line -n 0 'aws enabled with priority 250.' assert [ -L "$BASH_IT/enabled/250---aws.plugin.bash" ] run bash-it help aliases - assert_line "0" "ag:" - assert_line "1" "ag='ag --smart-case --pager=\"less -MIRFX'" + assert_line -n 0 "ag:" + assert_line -n 1 "ag='ag --smart-case --pager=\"less -MIRFX'" } @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" - assert_line "0" 'todo.txt-cli enabled with priority 150.' + assert_line -n 0 'todo.txt-cli enabled with priority 150.' assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] } @test "helpers: enable the curl aliases" { run _enable-alias "curl" - assert_line "0" 'curl enabled with priority 150.' + assert_line -n 0 'curl enabled with priority 150.' assert [ -L "$BASH_IT/enabled/150---curl.aliases.bash" ] } @test "helpers: enable the apm completion through the bash-it function" { run bash-it enable completion "apm" - assert_line "0" 'apm enabled with priority 350.' + assert_line -n 0 'apm enabled with priority 350.' assert [ -L "$BASH_IT/enabled/350---apm.completion.bash" ] } @test "helpers: enable the brew completion" { run _enable-completion "brew" - assert_line "0" 'brew enabled with priority 350.' + assert_line -n 0 'brew enabled with priority 350.' assert [ -L "$BASH_IT/enabled/350---brew.completion.bash" ] } @test "helpers: enable the node plugin" { run _enable-plugin "node" - assert_line "0" 'node enabled with priority 250.' + assert_line -n 0 'node enabled with priority 250.' assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] assert_equal "../plugins/available/node.plugin.bash" "`readlink $BASH_IT/enabled/250---node.plugin.bash`" @@ -153,34 +153,34 @@ function local_setup { @test "helpers: enable the node plugin through the bash-it function" { run bash-it enable plugin "node" - assert_line "0" 'node enabled with priority 250.' + assert_line -n 0 'node enabled with priority 250.' assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] } @test "helpers: enable the node and nvm plugins through the bash-it function" { run bash-it enable plugin "node" "nvm" - assert_line "0" 'node enabled with priority 250.' - assert_line "1" 'nvm enabled with priority 225.' + assert_line -n 0 'node enabled with priority 250.' + assert_line -n 1 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" { run bash-it enable plugin "foo-unknown" "nvm" - assert_line "0" 'sorry, foo-unknown does not appear to be an available plugin.' - assert_line "1" 'nvm enabled with priority 225.' + assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.' + assert_line -n 1 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin" { run _enable-plugin "nvm" - assert_line "0" 'nvm enabled with priority 225.' + assert_line -n 0 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable an unknown plugin" { run _enable-plugin "unknown-foo" - assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.' + assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' # Check for both old an new structure assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] @@ -193,7 +193,7 @@ function local_setup { @test "helpers: enable an unknown plugin through the bash-it function" { run bash-it enable plugin "unknown-foo" echo "${lines[@]}" - assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.' + assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' # Check for both old an new structure assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] @@ -205,17 +205,17 @@ function local_setup { @test "helpers: disable a plugin that is not enabled" { run _disable-plugin "sdkman" - assert_line "0" 'sorry, sdkman does not appear to be an enabled plugin.' + assert_line -n 0 'sorry, sdkman does not appear to be an enabled plugin.' } @test "helpers: enable and disable the nvm plugin" { run _enable-plugin "nvm" - assert_line "0" 'nvm enabled with priority 225.' + assert_line -n 0 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" - assert_line "0" 'nvm disabled.' + assert_line -n 0 'nvm disabled.' assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @@ -225,7 +225,7 @@ function local_setup { assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" - assert_line "0" 'nvm disabled.' + assert_line -n 0 'nvm disabled.' assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @@ -235,7 +235,7 @@ function local_setup { assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] run _disable-plugin "nvm" - assert_line "0" 'nvm disabled.' + assert_line -n 0 'nvm disabled.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] } @@ -244,7 +244,7 @@ function local_setup { assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] run _enable-plugin "nvm" - assert_line "0" 'nvm is already enabled.' + assert_line -n 0 'nvm is already enabled.' assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] @@ -255,7 +255,7 @@ function local_setup { assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] run _enable-plugin "nvm" - assert_line "0" 'nvm is already enabled.' + assert_line -n 0 'nvm is already enabled.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] @@ -263,11 +263,11 @@ function local_setup { @test "helpers: enable the nvm plugin twice" { run _enable-plugin "nvm" - assert_line "0" 'nvm enabled with priority 225.' + assert_line -n 0 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] run _enable-plugin "nvm" - assert_line "0" 'nvm is already enabled.' + assert_line -n 0 'nvm is already enabled.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @@ -279,13 +279,13 @@ function local_setup { assert [ -L "$BASH_IT/plugins/enabled/250---dirs.plugin.bash" ] run _bash-it-migrate - assert_line "0" 'Migrating plugin dirs.' - assert_line "1" 'dirs disabled.' - assert_line "2" 'dirs enabled with priority 250.' - assert_line "3" 'Migrating completion dirs.' - assert_line "4" 'dirs disabled.' - assert_line "5" 'dirs enabled with priority 350.' - assert_line "6" 'If any migration errors were reported, please try the following: reload && bash-it migrate' + assert_line -n 0 'Migrating plugin dirs.' + assert_line -n 1 'dirs disabled.' + assert_line -n 2 'dirs enabled with priority 250.' + assert_line -n 3 'Migrating completion dirs.' + assert_line -n 4 'dirs disabled.' + assert_line -n 5 'dirs enabled with priority 350.' + assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert [ -L "$BASH_IT/enabled/350---dirs.completion.bash" ] assert [ -L "$BASH_IT/enabled/250---dirs.plugin.bash" ] @@ -307,9 +307,9 @@ function local_setup { assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] run _bash-it-migrate - assert_line "0" 'Migrating alias todo.txt-cli.' - assert_line "1" 'todo.txt-cli disabled.' - assert_line "2" 'todo.txt-cli enabled with priority 150.' + assert_line -n 0 'Migrating alias todo.txt-cli.' + assert_line -n 1 'todo.txt-cli disabled.' + assert_line -n 2 'todo.txt-cli enabled with priority 150.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] @@ -433,11 +433,11 @@ function __migrate_all_components() { assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] run bash-it enable plugin "node" - assert_line "0" 'Migrating plugin nvm.' - assert_line "1" 'nvm disabled.' - assert_line "2" 'nvm enabled with priority 225.' - assert_line "3" 'If any migration errors were reported, please try the following: reload && bash-it migrate' - assert_line "4" 'node enabled with priority 250.' + assert_line -n 0 'Migrating plugin nvm.' + assert_line -n 1 'nvm disabled.' + assert_line -n 2 'nvm enabled with priority 225.' + assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate' + assert_line -n 4 'node enabled with priority 250.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] @@ -450,14 +450,14 @@ function __migrate_all_components() { assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] run bash-it disable plugin "node" - assert_line "0" 'Migrating plugin node.' - assert_line "1" 'node disabled.' - assert_line "2" 'node enabled with priority 250.' - assert_line "3" 'Migrating plugin nvm.' - assert_line "4" 'nvm disabled.' - assert_line "5" 'nvm enabled with priority 225.' - assert_line "6" 'If any migration errors were reported, please try the following: reload && bash-it migrate' - assert_line "7" 'node disabled.' + assert_line -n 0 'Migrating plugin node.' + assert_line -n 1 'node disabled.' + assert_line -n 2 'node enabled with priority 250.' + assert_line -n 3 'Migrating plugin nvm.' + assert_line -n 4 'nvm disabled.' + assert_line -n 5 'nvm enabled with priority 225.' + assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' + assert_line -n 7 'node disabled.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] @@ -539,7 +539,7 @@ function __migrate_all_components() { @test "helpers: enable the ansible aliases through the bash-it function" { run bash-it enable alias "ansible" - assert_line "0" 'ansible enabled with priority 150.' + assert_line -n 0 'ansible enabled with priority 150.' assert [ -L "$BASH_IT/enabled/150---ansible.aliases.bash" ] } @@ -549,7 +549,7 @@ function __migrate_all_components() { @test "helpers: describe the nvm plugin after enabling it" { run _enable-plugin "nvm" - assert_line "0" 'nvm enabled with priority 225.' + assert_line -n 0 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] _bash-it-plugins | grep "nvm" | grep "\[x\]" diff --git a/test/lib/search.bats b/test/lib/search.bats index 0993d0b1..1043c1a4 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -54,15 +54,15 @@ function local_setup { run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' run _enable-alias 'rails' run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' - assert_line "0" ' aliases => bundler ✓rails' - assert_line "1" ' plugins => chruby chruby-auto rails ruby' - assert_line "2" ' completions => bundler gem rake' + assert_line -n 0 ' aliases => bundler ✓rails' + assert_line -n 1 ' plugins => chruby chruby-auto rails ruby' + assert_line -n 2 ' completions => bundler gem rake' } @test "search: (all enabled) ruby gem bundle rake rails" { run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails' '--enable' run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails' - assert_line "0" ' aliases => ✓bundler ✓rails' - assert_line "1" ' plugins => ✓rails ✓ruby' - assert_line "2" ' completions => ✓bundler ✓gem ✓rake' + assert_line -n 0 ' aliases => ✓bundler ✓rails' + assert_line -n 1 ' plugins => ✓rails ✓ruby' + assert_line -n 2 ' completions => ✓bundler ✓gem ✓rake' } diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index 87c971b2..ab11bda1 100755 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -33,7 +33,7 @@ function local_teardown { @test "plugins ruby: remove_gem is defined" { run type remove_gem - assert_line 1 "remove_gem () " + assert_line -n 1 "remove_gem () " } @test "plugins ruby: PATH includes ~/.gem/ruby/bin" { diff --git a/test/run b/test/run index 7bbbb511..f6e57d45 100755 --- a/test/run +++ b/test/run @@ -3,13 +3,10 @@ test_directory="$(cd "$(dirname "$0")" && pwd)" #bats_executable="${test_directory}/../bats/bin/bats" bats_executable="${test_directory}/../test_lib/bats-core/bin/bats" -[ ! -e $bats_executable ] && \ - git submodule init && git submodule update +git submodule init && git submodule update if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi -echo "Bats: $bats_executable" - exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes} diff --git a/test/test_helper.bash b/test/test_helper.bash index 08638b54..fa9ed2e8 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -13,6 +13,12 @@ if [ "$BASH_IT_ROOT" != "${BASH_IT_TEST_DIR}/root" ]; then export BASH_IT=$BASH_IT_TEST_DIR fi +export TEST_MAIN_DIR="${BATS_TEST_DIRNAME}/.." +export TEST_DEPS_DIR="${TEST_DEPS_DIR-${TEST_MAIN_DIR}/../test_lib}" + +load "${TEST_DEPS_DIR}/bats-support/load.bash" +load "${TEST_DEPS_DIR}/bats-assert/load.bash" + local_setup() { true } @@ -32,77 +38,3 @@ teardown() { rm -rf "${BASH_IT_TEST_DIR}" } - -assert() { - if ! "$@"; then - flunk "failed: $@" - fi -} - -flunk() { - { if [ "$#" -eq 0 ]; then cat - - else echo "$@" - fi - } | sed "s:${BASH_IT_TEST_DIR}:TEST_DIR:g" >&2 - return 1 -} - -assert_success() { - if [ "$status" -ne 0 ]; then - flunk "command failed with exit status $status" - elif [ "$#" -gt 0 ]; then - assert_output "$1" - fi -} - -assert_failure() { - if [ "$status" -eq 0 ]; then - flunk "expected failed exit status" - elif [ "$#" -gt 0 ]; then - assert_output "$1" - fi -} - -assert_equal() { - if [ "$1" != "$2" ]; then - { echo "expected: $1" - echo "actual: $2" - } | flunk - fi -} - -assert_output() { - local expected - if [ $# -eq 0 ]; then expected="$(cat -)" - else expected="$1" - fi - assert_equal "$expected" "$output" -} - -assert_line() { - if [ "$1" -ge 0 ] 2>/dev/null; then - assert_equal "$2" "${lines[$1]}" - else - local line - for line in "${lines[@]}"; do - if [ "$line" = "$1" ]; then return 0; fi - done - flunk "expected line \`$1'" - fi -} - -refute_line() { - if [ "$1" -ge 0 ] 2>/dev/null; then - local num_lines="${#lines[@]}" - if [ "$1" -lt "$num_lines" ]; then - flunk "output has $num_lines lines" - fi - else - local line - for line in "${lines[@]}"; do - if [ "$line" = "$1" ]; then - flunk "expected to not find line \`$line'" - fi - done - fi -} diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index ab320c81..2cf809dc 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -26,7 +26,7 @@ load ../../themes/base.theme run battery_char assert_success - assert_line "0" "" + assert_line -n 0 "" run type -a battery_char assert_line " echo -n" @@ -53,7 +53,7 @@ load ../../themes/base.theme run battery_charge assert_success - assert_line "0" "" + assert_line -n 0 "" } @test 'themes base: battery_charge should exist if battery plugin loaded' { From efc09fe45453a1e47cd73c67e64cbc66f307bc03 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 4 Oct 2017 08:51:31 +0200 Subject: [PATCH 05/10] Updated documentation --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 77bf3064..1f0aa4a4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,7 +58,7 @@ To run the test suite, simply execute the following in the directory where you c test/run ``` -This command will clone the [Bats Test Framework](https://github.com/sstephenson/bats) to a local directory and then run the test suite found in the [test](test) folder. +This command will ensure that the [Bats Test Framework](https://github.com/bats-core/bats-core) is available in a local directory (it's included as a Git submodule) and then run the test suite found in the [test](test) folder. The test script will execute each test in turn, and will print a status for each test case. When adding new test cases, please take a look at the existing test cases for examples. From e574de8f4792a92b0c85e5dbb02c40c7524cfa50 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Thu, 5 Oct 2017 07:31:54 +0200 Subject: [PATCH 06/10] Moved testing for files to bats-file library functions --- test/bash_it/bash_it.bats | 4 ++-- test/install/install.bats | 8 ++++---- test/install/uninstall.bats | 14 +++++++------- test/plugins/base.plugin.bats | 2 +- test/test_helper.bash | 1 + 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index bd3995b6..1fef3033 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -37,8 +37,8 @@ function local_teardown { } @test "bash-it: verify that the test fixture is available" { - assert [ -e "$BASH_IT/aliases/available/a.aliases.bash" ] - assert [ -e "$BASH_IT/aliases/available/b.aliases.bash" ] + assert_file_exist "$BASH_IT/aliases/available/a.aliases.bash" + assert_file_exist "$BASH_IT/aliases/available/b.aliases.bash" } @test "bash-it: load aliases in order" { diff --git a/test/install/install.bats b/test/install/install.bats index 4fb3d0a9..23684137 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -42,7 +42,7 @@ function local_teardown { } @test "install: verify that the install script exists" { - assert [ -e "$BASH_IT/install.sh" ] + assert_file_exist "$BASH_IT/install.sh" } @test "install: run the install script silently" { @@ -50,7 +50,7 @@ function local_teardown { ./install.sh --silent - assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] + assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" assert [ -L "$BASH_IT/enabled/150---general.aliases.bash" ] assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] @@ -68,8 +68,8 @@ function local_teardown { ./install.sh --silent - assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] - assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ] + assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" + assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index 45af20bc..d71ac06a 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -42,7 +42,7 @@ function local_teardown { } @test "uninstall: verify that the uninstall script exists" { - assert [ -e "$BASH_IT/uninstall.sh" ] + assert_file_exist "$BASH_IT/uninstall.sh" } @test "uninstall: run the uninstall script with an existing backup file" { @@ -56,9 +56,9 @@ function local_teardown { assert_success - assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" ] - assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ] - assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] + assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" local md5_conf=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') @@ -75,9 +75,9 @@ function local_teardown { assert_success - assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" ] - assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ] - assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] + assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" local md5_uninstall=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index a27a4ae7..d5b6ef4e 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -52,5 +52,5 @@ load ../../plugins/available/base.plugin declare -r file="${BASH_IT_ROOT}/file" touch $file run buf $file - assert [ -e ${file}_$(date +%Y%m%d_%H%M%S) ] + assert_file_exist ${file}_$(date +%Y%m%d_%H%M%S) } diff --git a/test/test_helper.bash b/test/test_helper.bash index fa9ed2e8..9155b434 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -18,6 +18,7 @@ export TEST_DEPS_DIR="${TEST_DEPS_DIR-${TEST_MAIN_DIR}/../test_lib}" load "${TEST_DEPS_DIR}/bats-support/load.bash" load "${TEST_DEPS_DIR}/bats-assert/load.bash" +load "${TEST_DEPS_DIR}/bats-file/load.bash" local_setup() { true From 80e510d65bd4b20e2e61cafee0b5f7c2ec832ab6 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 6 Oct 2017 17:29:12 +0200 Subject: [PATCH 07/10] Added assert_link_exist function and use that --- test/bash_it/bash_it.bats | 94 ++++++++-------- test/completion/bash-it.completion.bats | 60 +++++----- test/install/install.bats | 10 +- test/lib/helpers.bats | 140 ++++++++++++------------ test/test_helper.bash | 45 ++++++++ 5 files changed, 197 insertions(+), 152 deletions(-) diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index 1fef3033..886453dd 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -46,12 +46,12 @@ function local_teardown { mkdir -p $BASH_IT/plugins/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---a.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -69,12 +69,12 @@ function local_teardown { mkdir -p $BASH_IT/plugins/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/175---a.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/175---a.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/175---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -92,14 +92,14 @@ function local_teardown { mkdir -p $BASH_IT/plugins/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---a.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---c.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -118,14 +118,14 @@ function local_teardown { mkdir -p $BASH_IT/completion/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---a.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash - assert [ -L "$BASH_IT/completion/enabled/350---b.completion.bash" ] + assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash" ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---c.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -145,14 +145,14 @@ function local_teardown { mkdir -p $BASH_IT/completion/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/450---a.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/450---a.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/450---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash - assert [ -L "$BASH_IT/completion/enabled/350---b.completion.bash" ] + assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash" ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/950---c.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/950---c.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/950---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -171,14 +171,14 @@ function local_teardown { mkdir -p $BASH_IT/plugins/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/350---a.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/350---a.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/350---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---c.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -197,12 +197,12 @@ function local_teardown { mkdir -p $BASH_IT/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash - assert [ -L "$BASH_IT/enabled/150---a.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -219,12 +219,12 @@ function local_teardown { mkdir -p $BASH_IT/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/175---a.aliases.bash - assert [ -L "$BASH_IT/enabled/175---a.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/175---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -241,14 +241,14 @@ function local_teardown { mkdir -p $BASH_IT/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash - assert [ -L "$BASH_IT/enabled/150---a.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert [ -L "$BASH_IT/enabled/250---c.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -265,14 +265,14 @@ function local_teardown { mkdir -p $BASH_IT/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash - assert [ -L "$BASH_IT/enabled/350---a.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert [ -L "$BASH_IT/enabled/250---c.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -292,17 +292,17 @@ function local_teardown { mkdir -p $BASH_IT/aliases/enabled ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash - assert [ -L "$BASH_IT/enabled/350---a.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert [ -L "$BASH_IT/enabled/250---c.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" # Add one file in the old directory structure ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null @@ -320,9 +320,9 @@ function local_teardown { @test "bash-it: load enabled aliases from new structure, priority-based" { mkdir -p $BASH_IT/enabled ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash - assert [ -L "$BASH_IT/enabled/150---atom.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null @@ -338,9 +338,9 @@ function local_teardown { mkdir -p $BASH_IT/aliases/enabled mkdir -p $BASH_IT/plugins/enabled ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null @@ -356,9 +356,9 @@ function local_teardown { mkdir -p $BASH_IT/aliases/enabled mkdir -p $BASH_IT/plugins/enabled ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/atom.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/base.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/base.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index b8aef96f..3cdc84ba 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -164,10 +164,10 @@ function __check_completion () { @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" { ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/atom.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" ln -s $BASH_IT/completion/available/apm.completion.bash $BASH_IT/completion/enabled/apm.completion.bash - assert [ -L "$BASH_IT/completion/enabled/apm.completion.bash" ] + assert_link_exist "$BASH_IT/completion/enabled/apm.completion.bash" run __check_completion 'bash-it disable alias a' assert_line -n 0 "all atom" @@ -175,10 +175,10 @@ function __check_completion () { @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" { ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ln -s $BASH_IT/completion/available/apm.completion.bash $BASH_IT/completion/enabled/350---apm.completion.bash - assert [ -L "$BASH_IT/completion/enabled/350---apm.completion.bash" ] + assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash" run __check_completion 'bash-it disable alias a' assert_line -n 0 "all atom" @@ -186,10 +186,10 @@ function __check_completion () { @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" { ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash - assert [ -L "$BASH_IT/enabled/150---atom.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" ln -s $BASH_IT/completion/available/apm.completion.bash $BASH_IT/enabled/350---apm.completion.bash - assert [ -L "$BASH_IT/enabled/350---apm.completion.bash" ] + assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" run __check_completion 'bash-it disable alias a' assert_line -n 0 "all atom" @@ -197,10 +197,10 @@ function __check_completion () { @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/docker-compose.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" ln -s $BASH_IT/plugins/available/docker-machine.plugin.bash $BASH_IT/plugins/enabled/docker-machine.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' assert_line -n 0 "docker-machine" @@ -208,10 +208,10 @@ function __check_completion () { @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ln -s $BASH_IT/plugins/available/docker-machine.plugin.bash $BASH_IT/plugins/enabled/350---docker-machine.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' assert_line -n 0 "docker-machine" @@ -219,10 +219,10 @@ function __check_completion () { @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/enabled/150---docker-compose.aliases.bash - assert [ -L "$BASH_IT/enabled/150---docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" ln -s $BASH_IT/plugins/available/docker-machine.plugin.bash $BASH_IT/enabled/350---docker-machine.plugin.bash - assert [ -L "$BASH_IT/enabled/350---docker-machine.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' assert_line -n 0 "docker-machine" @@ -230,10 +230,10 @@ function __check_completion () { @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/todo.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/todo.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" run __check_completion 'bash-it disable alias to' assert_line -n 0 "todo.txt-cli" @@ -241,10 +241,10 @@ function __check_completion () { @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/350---todo.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/350---todo.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run __check_completion 'bash-it disable alias to' assert_line -n 0 "todo.txt-cli" @@ -252,10 +252,10 @@ function __check_completion () { @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/enabled/150---todo.txt-cli.aliases.bash - assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/enabled/350---todo.plugin.bash - assert [ -L "$BASH_IT/enabled/350---todo.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" run __check_completion 'bash-it disable alias to' assert_line -n 0 "todo.txt-cli" @@ -273,7 +273,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" { ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/atom.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" run __check_completion 'bash-it enable alias a' assert_line -n 0 "all ag ansible apt" @@ -281,7 +281,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" { ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" run __check_completion 'bash-it enable alias a' assert_line -n 0 "all ag ansible apt" @@ -289,7 +289,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" { ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash - assert [ -L "$BASH_IT/enabled/150---atom.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" run __check_completion 'bash-it enable alias a' assert_line -n 0 "all ag ansible apt" @@ -297,7 +297,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the old location and name" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/docker-compose.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' assert_line -n 0 "docker-compose docker-machine docker" @@ -305,7 +305,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the old location and priority-based name" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' assert_line -n 0 "docker-compose docker-machine docker" @@ -313,7 +313,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the new location and priority-based name" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/enabled/150---docker-compose.aliases.bash - assert [ -L "$BASH_IT/enabled/150---docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' assert_line -n 0 "docker-compose docker-machine docker" @@ -321,7 +321,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the old location and name" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/docker-compose.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' assert_line -n 0 "docker docker-compose docker-machine" @@ -329,7 +329,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the old location and priority-based name" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' assert_line -n 0 "docker docker-compose docker-machine" @@ -337,7 +337,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the new location and priority-based name" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/enabled/150---docker-compose.aliases.bash - assert [ -L "$BASH_IT/enabled/150---docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' assert_line -n 0 "docker docker-compose docker-machine" @@ -345,7 +345,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/todo.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/todo.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" run __check_completion 'bash-it enable alias to' assert_line -n 0 "todo.txt-cli" @@ -353,7 +353,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/350---todo.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/350---todo.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run __check_completion 'bash-it enable alias to' assert_line -n 0 "todo.txt-cli" @@ -361,7 +361,7 @@ function __check_completion () { @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/enabled/350---todo.plugin.bash - assert [ -L "$BASH_IT/enabled/350---todo.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" run __check_completion 'bash-it enable alias to' assert_line -n 0 "todo.txt-cli" diff --git a/test/install/install.bats b/test/install/install.bats index 23684137..7e971d1f 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -52,11 +52,11 @@ function local_teardown { assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" - assert [ -L "$BASH_IT/enabled/150---general.aliases.bash" ] - assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/365---alias-completion.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/350---bash-it.completion.bash" ] - assert [ -L "$BASH_IT/enabled/350---system.completion.bash" ] + assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" + assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash" + assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" + assert_link_exist "$BASH_IT/enabled/350---system.completion.bash" } @test "install: verify that a backup file is created" { diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index db956fc2..08e4ec5f 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -67,7 +67,7 @@ function local_setup { @test "helpers: bash-it help list aliases with ag aliases enabled" { ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" run _help-list-aliases "$BASH_IT/aliases/enabled/150---ag.aliases.bash" assert_line -n 0 "ag:" @@ -75,7 +75,7 @@ function local_setup { @test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" { ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" run _help-list-aliases "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" assert_line -n 0 "todo.txt-cli:" @@ -83,7 +83,7 @@ function local_setup { @test "helpers: bash-it help list aliases with docker-compose aliases enabled" { ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run _help-list-aliases "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_line -n 0 "docker-compose:" @@ -91,7 +91,7 @@ function local_setup { @test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/enabled/150---ag.aliases.bash - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" run _help-list-aliases "$BASH_IT/enabled/150---ag.aliases.bash" assert_line -n 0 "ag:" @@ -99,7 +99,7 @@ function local_setup { @test "helpers: bash-it help aliases one alias enabled in the old directory" { ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" run bash-it help aliases assert_line -n 0 "ag:" @@ -108,11 +108,11 @@ function local_setup { @test "helpers: bash-it help aliases one alias enabled in global directory" { run bash-it enable alias "ag" assert_line -n 0 'ag enabled with priority 150.' - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" run bash-it enable plugin "aws" assert_line -n 0 'aws enabled with priority 250.' - assert [ -L "$BASH_IT/enabled/250---aws.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---aws.plugin.bash" run bash-it help aliases assert_line -n 0 "ag:" @@ -122,31 +122,31 @@ function local_setup { @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line -n 0 'todo.txt-cli enabled with priority 150.' - assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" } @test "helpers: enable the curl aliases" { run _enable-alias "curl" assert_line -n 0 'curl enabled with priority 150.' - assert [ -L "$BASH_IT/enabled/150---curl.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---curl.aliases.bash" } @test "helpers: enable the apm completion through the bash-it function" { run bash-it enable completion "apm" assert_line -n 0 'apm enabled with priority 350.' - assert [ -L "$BASH_IT/enabled/350---apm.completion.bash" ] + assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" } @test "helpers: enable the brew completion" { run _enable-completion "brew" assert_line -n 0 'brew enabled with priority 350.' - assert [ -L "$BASH_IT/enabled/350---brew.completion.bash" ] + assert_link_exist "$BASH_IT/enabled/350---brew.completion.bash" } @test "helpers: enable the node plugin" { run _enable-plugin "node" assert_line -n 0 'node enabled with priority 250.' - assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" assert_equal "../plugins/available/node.plugin.bash" "`readlink $BASH_IT/enabled/250---node.plugin.bash`" } @@ -154,28 +154,28 @@ function local_setup { @test "helpers: enable the node plugin through the bash-it function" { run bash-it enable plugin "node" assert_line -n 0 'node enabled with priority 250.' - assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" } @test "helpers: enable the node and nvm plugins through the bash-it function" { run bash-it enable plugin "node" "nvm" assert_line -n 0 'node enabled with priority 250.' assert_line -n 1 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" } @test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" { run bash-it enable plugin "foo-unknown" "nvm" assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.' assert_line -n 1 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" } @test "helpers: enable the nvm plugin" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" } @test "helpers: enable an unknown plugin" { @@ -211,7 +211,7 @@ function local_setup { @test "helpers: enable and disable the nvm plugin" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" @@ -221,7 +221,7 @@ function local_setup { @test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" @@ -232,7 +232,7 @@ function local_setup { @test "helpers: disable the nvm plugin if it was enabled without a priority" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' @@ -241,42 +241,42 @@ function local_setup { @test "helpers: enable the nvm plugin if it was enabled without a priority" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin twice" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" } @test "helpers: migrate plugins and completions that share the same name" { ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash - assert [ -L "$BASH_IT/completion/enabled/350---dirs.completion.bash" ] + assert_link_exist "$BASH_IT/completion/enabled/350---dirs.completion.bash" ln -s $BASH_IT/plugins/available/dirs.plugin.bash $BASH_IT/plugins/enabled/250---dirs.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---dirs.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---dirs.plugin.bash" run _bash-it-migrate assert_line -n 0 'Migrating plugin dirs.' @@ -287,34 +287,34 @@ function local_setup { assert_line -n 5 'dirs enabled with priority 350.' assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' - assert [ -L "$BASH_IT/enabled/350---dirs.completion.bash" ] - assert [ -L "$BASH_IT/enabled/250---dirs.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/350---dirs.completion.bash" + assert_link_exist "$BASH_IT/enabled/250---dirs.plugin.bash" assert [ ! -L "$BASH_IT/completion/enabled/350----dirs.completion.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/250----dirs.plugin.bash" ] } @test "helpers: migrate enabled plugins that don't use the new priority-based configuration" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" run _enable-plugin "ssh" - assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" run _bash-it-migrate assert_line -n 0 'Migrating alias todo.txt-cli.' assert_line -n 1 'todo.txt-cli disabled.' assert_line -n 2 'todo.txt-cli enabled with priority 150.' - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" + assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] @@ -322,22 +322,22 @@ function local_setup { @test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash - assert [ -L "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash" ] + assert_link_exist "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash" run _enable-plugin "ssh" - assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" run _bash-it-migrate - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" + assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ] @@ -349,10 +349,10 @@ function local_setup { @test "helpers: run the migrate command without anything to migrate" { run _enable-plugin "ssh" - assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" run _bash-it-migrate - assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" } function __migrate_all_components() { @@ -430,7 +430,7 @@ function __migrate_all_components() { @test "helpers: verify that existing components are automatically migrated when something is enabled" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" run bash-it enable plugin "node" assert_line -n 0 'Migrating plugin nvm.' @@ -439,15 +439,15 @@ function __migrate_all_components() { assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 4 'node enabled with priority 250.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" } @test "helpers: verify that existing components are automatically migrated when something is disabled" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" run bash-it disable plugin "node" assert_line -n 0 'Migrating plugin node.' @@ -459,7 +459,7 @@ function __migrate_all_components() { assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 7 'node disabled.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ] } @@ -478,50 +478,50 @@ function __migrate_all_components() { assert_equal "$available" "$enabled" run _enable-alias "ag" - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" run _disable-plugin "all" local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) assert_equal "0" "$enabled2" - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) assert_equal "2" "$enabled" run _enable-alias "ag" - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" run _disable-plugin "all" local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) assert_equal "0" "$enabled2" - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure with priority" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/250---nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---nvm.plugin.bash" ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) assert_equal "2" "$enabled" run _enable-alias "ag" - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" run _disable-plugin "all" local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) assert_equal "0" "$enabled2" - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins without anything enabled" { @@ -529,18 +529,18 @@ function __migrate_all_components() { assert_equal "0" "$enabled" run _enable-alias "ag" - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" run _disable-plugin "all" local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) assert_equal "0" "$enabled2" - assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" } @test "helpers: enable the ansible aliases through the bash-it function" { run bash-it enable alias "ansible" assert_line -n 0 'ansible enabled with priority 150.' - assert [ -L "$BASH_IT/enabled/150---ansible.aliases.bash" ] + assert_link_exist "$BASH_IT/enabled/150---ansible.aliases.bash" } @test "helpers: describe the nvm plugin without enabling it" { @@ -550,21 +550,21 @@ function __migrate_all_components() { @test "helpers: describe the nvm plugin after enabling it" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory with priority" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } diff --git a/test/test_helper.bash b/test/test_helper.bash index 9155b434..e2bb9442 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -39,3 +39,48 @@ teardown() { rm -rf "${BASH_IT_TEST_DIR}" } + +# Fail and display path of the link if it does not exist. Also fails +# if the path exists, but is not a link. +# This function is the logical complement of `assert_file_not_exist'. +# There is no dedicated function for checking that a link does not exist. +# +# Globals: +# BATSLIB_FILE_PATH_REM +# BATSLIB_FILE_PATH_ADD +# Arguments: +# $1 - path +# Returns: +# 0 - link exists and is a link +# 1 - otherwise +# Outputs: +# STDERR - details, on failure +assert_link_exist() { + local -r file="$1" + local -r target="$2" + if [[ ! -L "$file" ]]; then + local -r rem="$BATSLIB_FILE_PATH_REM" + local -r add="$BATSLIB_FILE_PATH_ADD" + if [[ -e "$file" ]]; then + batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ + | batslib_decorate 'exists, but is not a link' \ + | fail + else + batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ + | batslib_decorate 'link does not exist' \ + | fail + fi + else + if [ -n "$target" ]; then + local link_target='' + link_target=$(readlink "$file") + if [[ "$link_target" != "$target" ]]; then + batslib_print_kv_single_or_multi 8 'path' "${file/$rem/$add}" \ + 'expected' "$target" \ + 'actual' "$link_target" \ + | batslib_decorate 'link exists, but does not point to target file' \ + | fail + fi + fi + fi +} From e2f00b1eb628ab1dd2b1a079e1d5cb5f20e2bbae Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Sun, 8 Oct 2017 12:42:02 +0200 Subject: [PATCH 08/10] Checking for link target --- test/lib/helpers.bats | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 08e4ec5f..7720b930 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -146,9 +146,7 @@ function local_setup { @test "helpers: enable the node plugin" { run _enable-plugin "node" assert_line -n 0 'node enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - - assert_equal "../plugins/available/node.plugin.bash" "`readlink $BASH_IT/enabled/250---node.plugin.bash`" + assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" } @test "helpers: enable the node plugin through the bash-it function" { From b6401075661e16a5aac9ad3898e27ac35c77c300 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Sat, 14 Oct 2017 18:09:58 +0200 Subject: [PATCH 09/10] Added list of test libraries (bats-assert etc.) --- CONTRIBUTING.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1f0aa4a4..04451473 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,11 +58,20 @@ To run the test suite, simply execute the following in the directory where you c test/run ``` -This command will ensure that the [Bats Test Framework](https://github.com/bats-core/bats-core) is available in a local directory (it's included as a Git submodule) and then run the test suite found in the [test](test) folder. +This command will ensure that the [Bats Test Framework](https://github.com/bats-core/bats-core) is available in the local `test_lib` directory (Bats is included as a Git submodule) and then run the test suite found in the [test](test) folder. The test script will execute each test in turn, and will print a status for each test case. When adding new test cases, please take a look at the existing test cases for examples. +The following libraries are used to help with the tests: + +* Test Framework: https://github.com/bats-core/bats-core +* Support library for Bats-Assert: https://github.com/ztombol/bats-support +* General `assert` functions: https://github.com/ztombol/bats-assert +* File `assert` functions: https://github.com/ztombol/bats-file + +When verifying test results, please try to use the `assert` functions found in these libraries. + ## Features * When adding new completions or plugins, please don't simply copy existing tools into the Bash-it codebase, try to load/integrate the tools instead. From 3a899916bdc4be76f7b64cf7cf673cbccc1fef14 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Sat, 14 Oct 2017 18:15:48 +0200 Subject: [PATCH 10/10] Removed extra line, no longer needed --- test/run | 1 - 1 file changed, 1 deletion(-) diff --git a/test/run b/test/run index f6e57d45..b6d4cc78 100755 --- a/test/run +++ b/test/run @@ -1,6 +1,5 @@ #!/usr/bin/env bash test_directory="$(cd "$(dirname "$0")" && pwd)" -#bats_executable="${test_directory}/../bats/bin/bats" bats_executable="${test_directory}/../test_lib/bats-core/bin/bats" git submodule init && git submodule update