Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/nix/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ import (
var update = flag.Bool("update", false, "update the golden files with the test results")

func TestWriteDevboxShellrc(t *testing.T) {
os.Setenv("DEVBOX_FEATURE_UNIFIED_ENV", "0")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want t.Setenv https://pkg.go.dev/testing#T.Setenv

testdirs, err := filepath.Glob("testdata/shellrc/*")
if err != nil {
t.Fatal("Error globbing testdata:", err)
}
testWriteDevboxShellrc(t, testdirs)
}

func TestWriteDevboxShellrcWithUnifiedEnv(t *testing.T) {
os.Setenv("DEVBOX_FEATURE_UNIFIED_ENV", "1")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as well

testdirs, err := filepath.Glob("testdata/shellrc_unifiedenv/*")
if err != nil {
t.Fatal("Error globbing testdata:", err)
}
testWriteDevboxShellrc(t, testdirs)
}

func testWriteDevboxShellrc(t *testing.T, testdirs []string) {
// Load up all the necessary data from each testdata/shellrc directory
// into a slice of tests cases.
tests := make([]struct {
Expand All @@ -29,6 +42,7 @@ func TestWriteDevboxShellrc(t *testing.T) {
goldShellrcPath string
goldShellrc []byte
}, len(testdirs))
var err error
for i, path := range testdirs {
test := &tests[i]
test.name = filepath.Base(path)
Expand Down
1 change: 1 addition & 0 deletions internal/nix/testdata/shellrc_unifiedenv/basic/hook
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "Hello from a devbox shell hook!"
37 changes: 37 additions & 0 deletions internal/nix/testdata/shellrc_unifiedenv/basic/shellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Set up the prompt

autoload -Uz promptinit
promptinit
#prompt adam1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?


setopt histignorealldups sharehistory

# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means war


# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history

# Use modern completion system
autoload -Uz compinit
compinit

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
75 changes: 75 additions & 0 deletions internal/nix/testdata/shellrc_unifiedenv/basic/shellrc.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Run the shell hook defined in shell.nix or flake.nix
eval $shellHook

# Begin testdata/shellrc_unifiedenv/basic/shellrc

# Set up the prompt

autoload -Uz promptinit
promptinit
#prompt adam1

setopt histignorealldups sharehistory

# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e

# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history

# Use modern completion system
autoload -Uz compinit
compinit

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

# End testdata/shellrc_unifiedenv/basic/shellrc

# Begin Devbox Post-init Hook

PATH="$DEVBOX_PATH_PREPEND:$PATH"

# Prepend to the prompt to make it clear we're in a devbox shell.
export PS1="(devbox) $PS1"

# End Devbox Post-init Hook

# Switch to the directory where devbox.json config is
workingDir=$(pwd)
cd path/to/projectDir

# Begin Plugin Init Hook

echo "Welcome to the devbox!"

# End Plugin Init Hook

# Begin Devbox User Hook

echo "Hello from a devbox shell hook!"

# End Devbox User Hook

cd $workingDir

# Begin Script command

# End Script command
1 change: 1 addition & 0 deletions internal/nix/testdata/shellrc_unifiedenv/nohook/env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PATH=/a/test/path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this value used?

37 changes: 37 additions & 0 deletions internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Set up the prompt

autoload -Uz promptinit
promptinit
#prompt adam1

setopt histignorealldups sharehistory

# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e

# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history

# Use modern completion system
autoload -Uz compinit
compinit

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
69 changes: 69 additions & 0 deletions internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Run the shell hook defined in shell.nix or flake.nix
eval $shellHook

# Begin testdata/shellrc_unifiedenv/nohook/shellrc

# Set up the prompt

autoload -Uz promptinit
promptinit
#prompt adam1

setopt histignorealldups sharehistory

# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e

# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history

# Use modern completion system
autoload -Uz compinit
compinit

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

# End testdata/shellrc_unifiedenv/nohook/shellrc

# Begin Devbox Post-init Hook

PATH="$DEVBOX_PATH_PREPEND:$PATH"

# Prepend to the prompt to make it clear we're in a devbox shell.
export PS1="(devbox) $PS1"

# End Devbox Post-init Hook

# Switch to the directory where devbox.json config is
workingDir=$(pwd)
cd path/to/projectDir

# Begin Plugin Init Hook

echo "Welcome to the devbox!"

# End Plugin Init Hook

cd $workingDir

# Begin Script command

# End Script command
1 change: 1 addition & 0 deletions internal/nix/testdata/shellrc_unifiedenv/noshellrc/env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PATH=/a/test/path
1 change: 1 addition & 0 deletions internal/nix/testdata/shellrc_unifiedenv/noshellrc/hook
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "Hello from a devbox shell hook!"
33 changes: 33 additions & 0 deletions internal/nix/testdata/shellrc_unifiedenv/noshellrc/shellrc.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Run the shell hook defined in shell.nix or flake.nix
eval $shellHook

# Begin Devbox Post-init Hook

PATH="$DEVBOX_PATH_PREPEND:$PATH"

# Prepend to the prompt to make it clear we're in a devbox shell.
export PS1="(devbox) $PS1"

# End Devbox Post-init Hook

# Switch to the directory where devbox.json config is
workingDir=$(pwd)
cd path/to/projectDir

# Begin Plugin Init Hook

echo "Welcome to the devbox!"

# End Plugin Init Hook

# Begin Devbox User Hook

echo "Hello from a devbox shell hook!"

# End Devbox User Hook

cd $workingDir

# Begin Script command

# End Script command