]> Sergey Matveev's repositories - zsh-autoenv.git/blob - tests/leave.t
tests: add setup script, used to be for all tests
[zsh-autoenv.git] / tests / leave.t
1   $ source $TESTDIR/setup.sh
2
3 Lets set a simple .env action
4
5   $ mkdir sub
6   $ cd sub
7   $ echo 'echo ENTERED' >> .env
8   $ echo 'echo LEFT' >> .env.leave
9
10 Change to the directory.
11
12   $ _dotenv_read_answer() { echo 'y' }
13   $ cd .
14   Attempting to load unauthorized env file: /tmp/cramtests-??????/leave.t/sub/.env (glob)
15   
16   **********************************************
17   
18   echo ENTERED
19   
20   **********************************************
21   
22   Would you like to authorize it? [y/N] 
23   ENTERED
24
25
26 Leave the directory and answer "no".
27
28   $ _dotenv_read_answer() { echo 'n' }
29   $ cd ..
30   Attempting to load unauthorized env file: /tmp/cramtests-??????/leave.t/sub/.env.leave (glob)
31   
32   **********************************************
33   
34   echo LEFT
35   
36   **********************************************
37   
38   Would you like to authorize it? [y/N] 
39
40
41   $ cd sub
42   ENTERED
43   $ _dotenv_read_answer() { echo 'y' }
44   $ cd ..
45   Attempting to load unauthorized env file: /tmp/cramtests-??????/leave.t/sub/.env.leave (glob)
46   
47   **********************************************
48   
49   echo LEFT
50   
51   **********************************************
52   
53   Would you like to authorize it? [y/N] 
54   LEFT
55
56
57 Now check with subdirs, looking upwards.
58
59   $ DOTENV_LOOK_UPWARDS=1
60   $ mkdir sub/child
61   $ cd sub/child
62   ENTERED
63   $ cd .
64   $ cd ..
65   $ cd ..
66   LEFT
67
68
69 Now check with subdirs, not looking at parent dirs.
70
71   $ DOTENV_LOOK_UPWARDS=0
72   $ cd sub/child
73   $ cd ..
74   ENTERED
75   $ cd child
76   $ cd ../..
77   LEFT
78
79
80 Test that .env is sourced only once with DOTENV_HANDLE_LEAVE=0.
81
82   $ unset _dotenv_stack_entered
83   $ DOTENV_HANDLE_LEAVE=0
84   $ cd sub
85   ENTERED
86   $ cd ..
87   $ cd sub