From 2cc2ec160ede7bbace8d51ee298c68fb2b5ff6ba Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 29 Dec 2015 11:12:22 -0500 Subject: [PATCH 1/4] Remove redundant test Spaces in hook path is tested in test/hooks.bats --- test/exec.bats | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/exec.bats b/test/exec.bats index aeb0456c..42948c5c 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -43,17 +43,6 @@ ruby OUT } -@test "supports hook path with spaces" { - hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks" - mkdir -p "${hook_path}/exec" - echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash" - - export RBENV_VERSION=system - RBENV_HOOK_PATH="$hook_path" run rbenv-exec env - assert_success - assert_line "HELLO=from hook" -} - @test "carries original IFS within hooks" { hook_path="${RBENV_TEST_DIR}/rbenv.d" mkdir -p "${hook_path}/exec" From 5ccba5d7cc38a31b464ce6299173b5f0056b428e Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 29 Dec 2015 10:53:01 -0500 Subject: [PATCH 2/4] Extract common create_hook helper --- test/rbenv.bats | 1 + test/test_helper.bash | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/test/rbenv.bats b/test/rbenv.bats index 6ded889c..0f305bca 100644 --- a/test/rbenv.bats +++ b/test/rbenv.bats @@ -70,6 +70,7 @@ load test_helper } @test "RBENV_HOOK_PATH includes rbenv built-in plugins" { + unset RBENV_HOOK_PATH run rbenv echo "RBENV_HOOK_PATH" assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" } diff --git a/test/test_helper.bash b/test/test_helper.bash index b62cdc15..aef883a4 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -17,6 +17,7 @@ if [ -z "$RBENV_TEST_DIR" ]; then export RBENV_ROOT="${RBENV_TEST_DIR}/root" export HOME="${RBENV_TEST_DIR}/home" + export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin PATH="${RBENV_TEST_DIR}/bin:$PATH" @@ -129,3 +130,11 @@ path_without() { path="${path#:}" echo "${path%:}" } + +create_hook() { + mkdir -p "${RBENV_HOOK_PATH}/$1" + touch "${RBENV_HOOK_PATH}/$1/$2" + if [ ! -t 0 ]; then + cat > "${RBENV_HOOK_PATH}/$1/$2" + fi +} From 0f7a2cad8d497cce55b25035e4cf65a5bbe588de Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 29 Dec 2015 11:01:10 -0500 Subject: [PATCH 3/4] Use create_hook helper Use extracted create_hook helper in tests for: - exec - hooks - rehash - version-name - version-origin - which --- test/exec.bats | 6 ++---- test/hooks.bats | 27 +++++++++++++-------------- test/rehash.bats | 6 ++---- test/version-name.bats | 8 ++------ test/version-origin.bats | 7 ++----- test/which.bats | 6 ++---- 6 files changed, 23 insertions(+), 37 deletions(-) diff --git a/test/exec.bats b/test/exec.bats index 42948c5c..5413912b 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -44,15 +44,13 @@ OUT } @test "carries original IFS within hooks" { - hook_path="${RBENV_TEST_DIR}/rbenv.d" - mkdir -p "${hook_path}/exec" - cat > "${hook_path}/exec/hello.bash" <" @@ -15,11 +10,13 @@ create_hook() { @test "prints list of hooks" { path1="${RBENV_TEST_DIR}/rbenv.d" path2="${RBENV_TEST_DIR}/etc/rbenv_hooks" - create_hook "$path1" exec "hello.bash" - create_hook "$path1" exec "ahoy.bash" - create_hook "$path1" exec "invalid.sh" - create_hook "$path1" which "boom.bash" - create_hook "$path2" exec "bueno.bash" + RBENV_HOOK_PATH="$path1" + create_hook exec "hello.bash" + create_hook exec "ahoy.bash" + create_hook exec "invalid.sh" + create_hook which "boom.bash" + RBENV_HOOK_PATH="$path2" + create_hook exec "bueno.bash" RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec assert_success @@ -33,8 +30,10 @@ OUT @test "supports hook paths with spaces" { path1="${RBENV_TEST_DIR}/my hooks/rbenv.d" path2="${RBENV_TEST_DIR}/etc/rbenv hooks" - create_hook "$path1" exec "hello.bash" - create_hook "$path2" exec "ahoy.bash" + RBENV_HOOK_PATH="$path1" + create_hook exec "hello.bash" + RBENV_HOOK_PATH="$path2" + create_hook exec "ahoy.bash" RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec assert_success @@ -45,8 +44,8 @@ OUT } @test "resolves relative paths" { - path="${RBENV_TEST_DIR}/rbenv.d" - create_hook "$path" exec "hello.bash" + RBENV_HOOK_PATH="${RBENV_TEST_DIR}/rbenv.d" + create_hook exec "hello.bash" mkdir -p "$HOME" RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec diff --git a/test/rehash.bats b/test/rehash.bats index 74f55a97..15d7a89b 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -105,15 +105,13 @@ OUT } @test "carries original IFS within hooks" { - hook_path="${RBENV_TEST_DIR}/rbenv.d" - mkdir -p "${hook_path}/rehash" - cat > "${hook_path}/rehash/hello.bash" < "${RBENV_ROOT}/rbenv.d/version-name/test.bash" < "${RBENV_ROOT}/rbenv.d/version-origin/test.bash" < "${hook_path}/which/hello.bash" < Date: Tue, 29 Dec 2015 11:15:27 -0500 Subject: [PATCH 4/4] Test IFS handling in version-name/version-origin hooks --- test/version-name.bats | 12 ++++++++++++ test/version-origin.bats | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/test/version-name.bats b/test/version-name.bats index 6d19ab02..c240757c 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -31,6 +31,18 @@ setup() { assert_success "1.9.3" } +@test "carries original IFS within hooks" { + create_hook version-name hello.bash <