diff options
author | Jarkko Kniivilä <jkniiv@gmail.com> | 2015-09-05 23:31:42 +0300 |
---|---|---|
committer | Mike Burns <mike@mike-burns.com> | 2015-11-01 18:59:02 +0100 |
commit | b3f25262c260e81a4bffaa6444b48013f902a04a (patch) | |
tree | 8e83ad07b4af379f48de7941779dc600a8f6d8b4 /test/rcdn-hooks-run-in-situ.t | |
parent | 5f592878eed79dd28f9f93418f9456185fd21ac9 (diff) |
Fix hooks so that they are run in the directory where they are located
Calls `find(1)` with the `-exec` action just like before but instead of `run_hooks()`
letting `find` execute the hook directly it is wrapped in a shell one-liner which
changes to the hook's directory and executes the hook with "./" prepended to its
basename. These changes allow hooks to refer to dotfiles with relative paths.
For instance we can call a Makefile two directories up simply with `make -C ../..`.
Also make sure we are compatible with Solaris' Bourne shell and `find(1)`.
Closes #150. Closes #149.
Diffstat (limited to 'test/rcdn-hooks-run-in-situ.t')
-rw-r--r-- | test/rcdn-hooks-run-in-situ.t | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/rcdn-hooks-run-in-situ.t b/test/rcdn-hooks-run-in-situ.t new file mode 100644 index 0000000..17b8f09 --- /dev/null +++ b/test/rcdn-hooks-run-in-situ.t @@ -0,0 +1,28 @@ + $ . "$TESTDIR/helper.sh" + +Use a pre-generated UUID in a filename to make sure the filename is unique to this test +and also that the pre-down hook has found the right directory having found this file. + + $ uniquish_file_prefix='test-hooks-run-in-situ-' + > uuid='5b811e03-5977-40e6-80ef-dd6c35013e56' + > uniquish_file=${uniquish_file_prefix}${uuid} + +Pre-down and post-down hooks should run by default. More importantly the hooks\' cwd should +be the directory where they are situated. We test this by trying to find $uniquish_file. + + $ touch .dotfiles/$uniquish_file + > mkdir -p .dotfiles/hooks/pre-down .dotfiles/hooks/post-down + > touch .dotfiles/hooks/pre-down/00-test.sh .dotfiles/hooks/post-down/00-test.sh + > chmod +x .dotfiles/hooks/pre-down/00-test.sh .dotfiles/hooks/post-down/00-test.sh + + $ echo "echo ../../${uniquish_file_prefix}* > /tmp/test-$uuid" > .dotfiles/hooks/pre-down/00-test.sh + > echo "cat /tmp/test-$uuid; rm /tmp/test-$uuid" > .dotfiles/hooks/post-down/00-test.sh + + $ rcdn + ../../test-hooks-run-in-situ-5b811e03-5977-40e6-80ef-dd6c35013e56 + +Ensure that hooks run when output of lsrc is non-empty + $ touch .dotfiles/testrc + > rcup + > rcdn + ../../test-hooks-run-in-situ-5b811e03-5977-40e6-80ef-dd6c35013e56 |