1 Test recursing into parent .env files.
3 $ source $TESTDIR/setup.sh
5 Setup env actions / output.
7 $ AUTOENV_LOOK_UPWARDS=1
9 Create env files in root dir.
11 $ echo 'echo ENTERED_root: PWD:${PWD:t} from:${_autoenv_from_dir:t} to:${_autoenv_to_dir:t}' > .env
12 $ echo 'echo LEFT_root: PWD:${PWD:t} from:${_autoenv_from_dir:t} to:${_autoenv_to_dir:t}' > .env.leave
13 $ test_autoenv_auth_env_files
15 Create env files in sub dir.
19 ENTERED_root: PWD:sub from:recurse-upwards.t to:sub
21 $ echo 'echo ENTERED_sub: PWD:${PWD:t} from:${_autoenv_from_dir:t} to:${_autoenv_to_dir:t}' > .env
22 $ echo 'echo LEFT_sub: PWD:${PWD:t} from:${_autoenv_from_dir:t} to:${_autoenv_to_dir:t}' > .env.leave
23 $ test_autoenv_auth_env_files
28 ENTERED_sub: PWD:sub from:sub to:sub
31 LEFT_sub: PWD:sub from:sub to:recurse-upwards.t
34 ENTERED_sub: PWD:sub2 from:recurse-upwards.t to:sub2
38 Changing the .env file should re-source it.
40 $ echo 'echo ENTER2' >> .env
42 Set timestamp of auth file into the past, so it gets seen as new below.
44 $ touch -t 201401010101 .env
46 $ test_autoenv_auth_env_files
48 ENTERED_sub: PWD:sub from:sub to:sub
51 Add sub/sub2/.env file, with a call to autoenv_source_parent.
53 $ echo "echo autoenv_source_parent_from_sub2:\nautoenv_source_parent\necho done_sub2\n" > sub2/.env
54 $ test_autoenv_add_to_env sub2/.env
56 autoenv_source_parent_from_sub2:
57 ENTERED_sub: PWD:sub from:sub to:sub2
61 Move sub/.env away, now the root .env file should get sourced.
63 $ mv ../.env ../.env.out
64 $ touch -t 201401010102 .env
66 autoenv_source_parent_from_sub2:
67 ENTERED_root: PWD:recurse-upwards.t from:sub2 to:sub2
69 $ mv ../.env.out ../.env
71 Prepend call to autoenv_source_parent to sub/.env file.
74 $ sed -i -e "1s/^/echo autoenv_source_parent_from_sub:\nautoenv_source_parent\n/" .env
75 $ echo "echo done_sub" >> .env
76 $ touch -t 201401010103 .env
77 $ test_autoenv_auth_env_files
80 autoenv_source_parent_from_sub:
81 ENTERED_root: PWD:recurse-upwards.t from:sub to:sub
82 ENTERED_sub: PWD:sub from:sub to:sub
87 Add sub/sub2/.env file.
89 $ echo -e "echo autoenv_source_parent_from_sub2:\nautoenv_source_parent\necho done_sub2\n" > sub2/.env
90 $ test_autoenv_add_to_env sub2/.env
92 autoenv_source_parent_from_sub2:
93 autoenv_source_parent_from_sub:
94 ENTERED_root: PWD:recurse-upwards.t from:sub to:sub
95 ENTERED_sub: PWD:sub from:sub to:sub
103 LEFT_sub: PWD:sub from:sub2 to:recurse-upwards.t
104 ENTERED_root: PWD:recurse-upwards.t from:sub2 to:recurse-upwards.t
107 Changing the root .env should trigger re-authentication via autoenv_source_parent.
109 First, let's answer "no".
111 $ echo "echo NEW" > .env
112 $ _autoenv_read_answer() { echo 'n' }
114 autoenv_source_parent_from_sub:
115 Attempting to load unauthorized env file: /tmp/cramtests-*/recurse-upwards.t/.env (glob)
117 **********************************************
121 **********************************************
123 Would you like to authorize it? [y/N]
124 ENTERED_sub: PWD:sub from:recurse-upwards.t to:sub
129 This currently does not trigger re-execution of the .env file.
131 $ _autoenv_read_answer() { echo 'y' }
134 Touching the .env file will now source the parent env file.
136 $ touch -t 201401010104 .env
138 autoenv_source_parent_from_sub:
139 Attempting to load unauthorized env file: /tmp/cramtests-*/recurse-upwards.t/.env (glob)
141 **********************************************
145 **********************************************
147 Would you like to authorize it? [y/N]
149 ENTERED_sub: PWD:sub from:sub to:sub