]> Sergey Matveev's repositories - zsh-autoenv.git/blobdiff - tests/leave.t
Change default values: .env => .autoenv.zsh etc
[zsh-autoenv.git] / tests / leave.t
index d5531b142d9c7ae1eae5f04bc95e84b63384fbfc..93ad7c13612d92db704b73eaeea2b1605521e884 100644 (file)
@@ -1,17 +1,18 @@
-  $ source $TESTDIR/setup.sh
+  $ source $TESTDIR/setup.zsh || return 1
 
-Lets set a simple .env action
+Lets set a simple .autoenv.zsh action
 
   $ mkdir sub
   $ cd sub
-  $ echo 'echo ENTERED' >> .env
-  $ echo 'echo LEFT' >> .env.leave
+  $ echo 'echo ENTERED' > .autoenv.zsh
+  $ echo 'echo LEFT' > .autoenv_leave.zsh
 
 Change to the directory.
 
-  $ _autoenv_read_answer() { echo 'y' }
+  $ _autoenv_ask_for_yes() { echo "yes"; return 0 }
   $ cd .
-  Attempting to load unauthorized env file: /tmp/cramtests-??????/leave.t/sub/.env (glob)
+  Attempting to load unauthorized env file!
+  -* /tmp/cramtests-*/leave.t/sub/.autoenv.zsh (glob)
   
   **********************************************
   
@@ -19,15 +20,16 @@ Change to the directory.
   
   **********************************************
   
-  Would you like to authorize it? [y/N] 
+  Would you like to authorize it? (type 'yes') yes
   ENTERED
 
 
 Leave the directory and answer "no".
 
-  $ _autoenv_read_answer() { echo 'n' }
+  $ _autoenv_ask_for_yes() { echo "no"; return 1 }
   $ cd ..
-  Attempting to load unauthorized env file: /tmp/cramtests-??????/leave.t/sub/.env.leave (glob)
+  Attempting to load unauthorized env file!
+  -* /tmp/cramtests-*/leave.t/sub/.autoenv_leave.zsh (glob)
   
   **********************************************
   
@@ -35,14 +37,15 @@ Leave the directory and answer "no".
   
   **********************************************
   
-  Would you like to authorize it? [y/N] 
+  Would you like to authorize it? (type 'yes') no
 
 
   $ cd sub
   ENTERED
-  $ _autoenv_read_answer() { echo 'y' }
+  $ _autoenv_ask_for_yes() { echo "yes"; return 0 }
   $ cd ..
-  Attempting to load unauthorized env file: /tmp/cramtests-??????/leave.t/sub/.env.leave (glob)
+  Attempting to load unauthorized env file!
+  -* /tmp/cramtests-*/leave.t/sub/.autoenv_leave.zsh (glob)
   
   **********************************************
   
@@ -50,7 +53,7 @@ Leave the directory and answer "no".
   
   **********************************************
   
-  Would you like to authorize it? [y/N] 
+  Would you like to authorize it? (type 'yes') yes
   LEFT
 
 
@@ -77,7 +80,7 @@ Now check with subdirs, not looking at parent dirs.
   LEFT
 
 
-Test that .env is sourced only once with AUTOENV_HANDLE_LEAVE=0.
+Test that .autoenv.zsh is sourced only once with AUTOENV_HANDLE_LEAVE=0.
 
   $ unset _autoenv_stack_entered
   $ AUTOENV_HANDLE_LEAVE=0
@@ -85,3 +88,37 @@ Test that .env is sourced only once with AUTOENV_HANDLE_LEAVE=0.
   ENTERED
   $ cd ..
   $ cd sub
+
+
+Test that "leave" is not triggered when entering an outside dir via symlink.
+
+  $ AUTOENV_HANDLE_LEAVE=1
+  $ cd ..
+  LEFT
+  $ mkdir outside
+  $ cd outside
+  $ echo 'echo ENTERED outside: PWD:${PWD:t} pwd:${${"$(pwd)"}:t} from:${autoenv_from_dir:t} to:${autoenv_to_dir:t} event:${autoenv_event}' > .autoenv.zsh
+  $ echo 'echo LEFT outside: PWD:${PWD:t} pwd:${${"$(pwd)"}:t} from:${autoenv_from_dir:t} to:${autoenv_to_dir:t} event:${autoenv_event}' > .autoenv_leave.zsh
+  $ test_autoenv_auth_env_files
+
+  $ cd ..
+  $ ln -s ../outside sub/symlink
+  $ cd sub
+  ENTERED
+  $ cd symlink
+  ENTERED outside: PWD:symlink pwd:symlink from:sub to:symlink event:enter
+
+  $ cd ../..
+  LEFT
+  LEFT outside: PWD:leave.t pwd:leave.t from:symlink to:leave.t event:leave
+  $ cd sub/symlink
+  ENTERED outside: PWD:symlink pwd:symlink from:leave.t to:symlink event:enter
+
+$autoenv_env_file should be reset when leaving.
+
+  $ echo $autoenv_env_file
+  */leave.t/sub/symlink/.autoenv.zsh (glob)
+  $ cd ../..
+  LEFT outside: PWD:leave.t pwd:leave.t from:symlink to:leave.t event:leave
+  $ echo ${autoenv_env_file:-empty}
+  empty