File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Test the direnv integration
2
+ #
3
+ # Our main concern is that `devenv shell` should not trigger direnv to immediately reload.
4
+ # Because direnv only checks the modification time of watched files, we need to take extra care not to "carelessly" write to such files.
5
+ set -xeuo pipefail
6
+
7
+ # Install direnv
8
+ export PATH=" $( nix build nixpkgs#direnv --print-out-paths --no-out-link) /bin:$PATH "
9
+
10
+ export TMPDIR=$( mktemp -d)
11
+ export XDG_CONFIG_HOME=${TMPDIR} /config
12
+ export XDG_DATA_HOME=${TMPDIR} /data
13
+
14
+ direnv_eval () {
15
+ eval " $( direnv export bash) "
16
+ }
17
+
18
+ # Setup direnv
19
+ mkdir -p $XDG_CONFIG_HOME /.config/direnv/
20
+ cat > $XDG_CONFIG_HOME /.config/direnv/direnv.toml << 'EOF '
21
+ [global]
22
+ strict_env = true
23
+ EOF
24
+
25
+ # Initialize direnv
26
+ cat > .envrc << 'EOF '
27
+ eval "$(devenv direnvrc)"
28
+ use devenv
29
+ EOF
30
+
31
+ # Load the environment
32
+ direnv allow
33
+ direnv_eval
34
+
35
+ # Enter shell and capture initial watches
36
+ DIRENV_WATCHES_BEFORE=$DIRENV_WATCHES
37
+
38
+ # Execute some operations that should not cause direnv to reload
39
+ echo " Running commands that should not trigger direnv reload..." >&2
40
+ devenv shell " echo 'Hello from devenv shell'"
41
+
42
+ direnv_eval
43
+
44
+ # Capture watches after
45
+ DIRENV_WATCHES_AFTER=$DIRENV_WATCHES
46
+
47
+ echo " Checking whether direnv reload was triggered..." >&2
48
+ if [[ " $DIRENV_WATCHES_BEFORE " == " $DIRENV_WATCHES_AFTER " ]]; then
49
+ echo " PASS: DIRENV_WATCHES remained unchanged" >&2
50
+ exit 0
51
+ else
52
+ echo " FAIL: DIRENV_WATCHES changed, indicating unwanted reload" >&2
53
+ echo " Before: $DIRENV_WATCHES_BEFORE " >&2
54
+ echo " After: $DIRENV_WATCHES_AFTER " >&2
55
+ exit 1
56
+ fi
Original file line number Diff line number Diff line change
1
+ { }
You can’t perform that action at this time.
0 commit comments