Skip to content

Commit 7fb3374

Browse files
authored
Add shellrc tests for unified env (#660)
## Summary TSIA ## How was it tested? `go test`
1 parent 4928aea commit 7fb3374

File tree

10 files changed

+269
-0
lines changed

10 files changed

+269
-0
lines changed

internal/nix/shell_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,24 @@ import (
1515
var update = flag.Bool("update", false, "update the golden files with the test results")
1616

1717
func TestWriteDevboxShellrc(t *testing.T) {
18+
os.Setenv("DEVBOX_FEATURE_UNIFIED_ENV", "0")
1819
testdirs, err := filepath.Glob("testdata/shellrc/*")
1920
if err != nil {
2021
t.Fatal("Error globbing testdata:", err)
2122
}
23+
testWriteDevboxShellrc(t, testdirs)
24+
}
25+
26+
func TestWriteDevboxShellrcWithUnifiedEnv(t *testing.T) {
27+
os.Setenv("DEVBOX_FEATURE_UNIFIED_ENV", "1")
28+
testdirs, err := filepath.Glob("testdata/shellrc_unifiedenv/*")
29+
if err != nil {
30+
t.Fatal("Error globbing testdata:", err)
31+
}
32+
testWriteDevboxShellrc(t, testdirs)
33+
}
2234

35+
func testWriteDevboxShellrc(t *testing.T, testdirs []string) {
2336
// Load up all the necessary data from each testdata/shellrc directory
2437
// into a slice of tests cases.
2538
tests := make([]struct {
@@ -29,6 +42,7 @@ func TestWriteDevboxShellrc(t *testing.T) {
2942
goldShellrcPath string
3043
goldShellrc []byte
3144
}, len(testdirs))
45+
var err error
3246
for i, path := range testdirs {
3347
test := &tests[i]
3448
test.name = filepath.Base(path)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "Hello from a devbox shell hook!"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Set up the prompt
2+
3+
autoload -Uz promptinit
4+
promptinit
5+
#prompt adam1
6+
7+
setopt histignorealldups sharehistory
8+
9+
# Use emacs keybindings even if our EDITOR is set to vi
10+
bindkey -e
11+
12+
# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
13+
HISTSIZE=1000
14+
SAVEHIST=1000
15+
HISTFILE=~/.zsh_history
16+
17+
# Use modern completion system
18+
autoload -Uz compinit
19+
compinit
20+
21+
zstyle ':completion:*' auto-description 'specify: %d'
22+
zstyle ':completion:*' completer _expand _complete _correct _approximate
23+
zstyle ':completion:*' format 'Completing %d'
24+
zstyle ':completion:*' group-name ''
25+
zstyle ':completion:*' menu select=2
26+
eval "$(dircolors -b)"
27+
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
28+
zstyle ':completion:*' list-colors ''
29+
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
30+
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
31+
zstyle ':completion:*' menu select=long
32+
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
33+
zstyle ':completion:*' use-compctl false
34+
zstyle ':completion:*' verbose true
35+
36+
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
37+
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Run the shell hook defined in shell.nix or flake.nix
2+
eval $shellHook
3+
4+
# Begin testdata/shellrc_unifiedenv/basic/shellrc
5+
6+
# Set up the prompt
7+
8+
autoload -Uz promptinit
9+
promptinit
10+
#prompt adam1
11+
12+
setopt histignorealldups sharehistory
13+
14+
# Use emacs keybindings even if our EDITOR is set to vi
15+
bindkey -e
16+
17+
# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
18+
HISTSIZE=1000
19+
SAVEHIST=1000
20+
HISTFILE=~/.zsh_history
21+
22+
# Use modern completion system
23+
autoload -Uz compinit
24+
compinit
25+
26+
zstyle ':completion:*' auto-description 'specify: %d'
27+
zstyle ':completion:*' completer _expand _complete _correct _approximate
28+
zstyle ':completion:*' format 'Completing %d'
29+
zstyle ':completion:*' group-name ''
30+
zstyle ':completion:*' menu select=2
31+
eval "$(dircolors -b)"
32+
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
33+
zstyle ':completion:*' list-colors ''
34+
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
35+
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
36+
zstyle ':completion:*' menu select=long
37+
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
38+
zstyle ':completion:*' use-compctl false
39+
zstyle ':completion:*' verbose true
40+
41+
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
42+
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
43+
44+
# End testdata/shellrc_unifiedenv/basic/shellrc
45+
46+
# Begin Devbox Post-init Hook
47+
48+
PATH="$DEVBOX_PATH_PREPEND:$PATH"
49+
50+
# Prepend to the prompt to make it clear we're in a devbox shell.
51+
export PS1="(devbox) $PS1"
52+
53+
# End Devbox Post-init Hook
54+
55+
# Switch to the directory where devbox.json config is
56+
workingDir=$(pwd)
57+
cd path/to/projectDir
58+
59+
# Begin Plugin Init Hook
60+
61+
echo "Welcome to the devbox!"
62+
63+
# End Plugin Init Hook
64+
65+
# Begin Devbox User Hook
66+
67+
echo "Hello from a devbox shell hook!"
68+
69+
# End Devbox User Hook
70+
71+
cd $workingDir
72+
73+
# Begin Script command
74+
75+
# End Script command
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PATH=/a/test/path
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Set up the prompt
2+
3+
autoload -Uz promptinit
4+
promptinit
5+
#prompt adam1
6+
7+
setopt histignorealldups sharehistory
8+
9+
# Use emacs keybindings even if our EDITOR is set to vi
10+
bindkey -e
11+
12+
# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
13+
HISTSIZE=1000
14+
SAVEHIST=1000
15+
HISTFILE=~/.zsh_history
16+
17+
# Use modern completion system
18+
autoload -Uz compinit
19+
compinit
20+
21+
zstyle ':completion:*' auto-description 'specify: %d'
22+
zstyle ':completion:*' completer _expand _complete _correct _approximate
23+
zstyle ':completion:*' format 'Completing %d'
24+
zstyle ':completion:*' group-name ''
25+
zstyle ':completion:*' menu select=2
26+
eval "$(dircolors -b)"
27+
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
28+
zstyle ':completion:*' list-colors ''
29+
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
30+
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
31+
zstyle ':completion:*' menu select=long
32+
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
33+
zstyle ':completion:*' use-compctl false
34+
zstyle ':completion:*' verbose true
35+
36+
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
37+
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Run the shell hook defined in shell.nix or flake.nix
2+
eval $shellHook
3+
4+
# Begin testdata/shellrc_unifiedenv/nohook/shellrc
5+
6+
# Set up the prompt
7+
8+
autoload -Uz promptinit
9+
promptinit
10+
#prompt adam1
11+
12+
setopt histignorealldups sharehistory
13+
14+
# Use emacs keybindings even if our EDITOR is set to vi
15+
bindkey -e
16+
17+
# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
18+
HISTSIZE=1000
19+
SAVEHIST=1000
20+
HISTFILE=~/.zsh_history
21+
22+
# Use modern completion system
23+
autoload -Uz compinit
24+
compinit
25+
26+
zstyle ':completion:*' auto-description 'specify: %d'
27+
zstyle ':completion:*' completer _expand _complete _correct _approximate
28+
zstyle ':completion:*' format 'Completing %d'
29+
zstyle ':completion:*' group-name ''
30+
zstyle ':completion:*' menu select=2
31+
eval "$(dircolors -b)"
32+
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
33+
zstyle ':completion:*' list-colors ''
34+
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
35+
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
36+
zstyle ':completion:*' menu select=long
37+
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
38+
zstyle ':completion:*' use-compctl false
39+
zstyle ':completion:*' verbose true
40+
41+
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
42+
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
43+
44+
# End testdata/shellrc_unifiedenv/nohook/shellrc
45+
46+
# Begin Devbox Post-init Hook
47+
48+
PATH="$DEVBOX_PATH_PREPEND:$PATH"
49+
50+
# Prepend to the prompt to make it clear we're in a devbox shell.
51+
export PS1="(devbox) $PS1"
52+
53+
# End Devbox Post-init Hook
54+
55+
# Switch to the directory where devbox.json config is
56+
workingDir=$(pwd)
57+
cd path/to/projectDir
58+
59+
# Begin Plugin Init Hook
60+
61+
echo "Welcome to the devbox!"
62+
63+
# End Plugin Init Hook
64+
65+
cd $workingDir
66+
67+
# Begin Script command
68+
69+
# End Script command
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PATH=/a/test/path
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "Hello from a devbox shell hook!"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Run the shell hook defined in shell.nix or flake.nix
2+
eval $shellHook
3+
4+
# Begin Devbox Post-init Hook
5+
6+
PATH="$DEVBOX_PATH_PREPEND:$PATH"
7+
8+
# Prepend to the prompt to make it clear we're in a devbox shell.
9+
export PS1="(devbox) $PS1"
10+
11+
# End Devbox Post-init Hook
12+
13+
# Switch to the directory where devbox.json config is
14+
workingDir=$(pwd)
15+
cd path/to/projectDir
16+
17+
# Begin Plugin Init Hook
18+
19+
echo "Welcome to the devbox!"
20+
21+
# End Plugin Init Hook
22+
23+
# Begin Devbox User Hook
24+
25+
echo "Hello from a devbox shell hook!"
26+
27+
# End Devbox User Hook
28+
29+
cd $workingDir
30+
31+
# Begin Script command
32+
33+
# End Script command

0 commit comments

Comments
 (0)