From 33bfc4bc575120254566487c0eac22cd598308e5 Mon Sep 17 00:00:00 2001 From: Rodrigo Ipince Date: Tue, 21 Feb 2023 12:06:31 -0500 Subject: [PATCH] Add shellrc tests for unified env --- internal/nix/shell_test.go | 14 ++++ .../testdata/shellrc_unifiedenv/basic/hook | 1 + .../testdata/shellrc_unifiedenv/basic/shellrc | 37 +++++++++ .../shellrc_unifiedenv/basic/shellrc.golden | 75 +++++++++++++++++++ .../testdata/shellrc_unifiedenv/nohook/env | 1 + .../shellrc_unifiedenv/nohook/shellrc | 37 +++++++++ .../shellrc_unifiedenv/nohook/shellrc.golden | 69 +++++++++++++++++ .../testdata/shellrc_unifiedenv/noshellrc/env | 1 + .../shellrc_unifiedenv/noshellrc/hook | 1 + .../noshellrc/shellrc.golden | 33 ++++++++ 10 files changed, 269 insertions(+) create mode 100644 internal/nix/testdata/shellrc_unifiedenv/basic/hook create mode 100644 internal/nix/testdata/shellrc_unifiedenv/basic/shellrc create mode 100644 internal/nix/testdata/shellrc_unifiedenv/basic/shellrc.golden create mode 100644 internal/nix/testdata/shellrc_unifiedenv/nohook/env create mode 100644 internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc create mode 100644 internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc.golden create mode 100644 internal/nix/testdata/shellrc_unifiedenv/noshellrc/env create mode 100644 internal/nix/testdata/shellrc_unifiedenv/noshellrc/hook create mode 100644 internal/nix/testdata/shellrc_unifiedenv/noshellrc/shellrc.golden diff --git a/internal/nix/shell_test.go b/internal/nix/shell_test.go index 5e02d5a8d51..190478ace4a 100644 --- a/internal/nix/shell_test.go +++ b/internal/nix/shell_test.go @@ -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") 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") + 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 { @@ -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) diff --git a/internal/nix/testdata/shellrc_unifiedenv/basic/hook b/internal/nix/testdata/shellrc_unifiedenv/basic/hook new file mode 100644 index 00000000000..770d44938c5 --- /dev/null +++ b/internal/nix/testdata/shellrc_unifiedenv/basic/hook @@ -0,0 +1 @@ +echo "Hello from a devbox shell hook!" diff --git a/internal/nix/testdata/shellrc_unifiedenv/basic/shellrc b/internal/nix/testdata/shellrc_unifiedenv/basic/shellrc new file mode 100644 index 00000000000..85834d546fd --- /dev/null +++ b/internal/nix/testdata/shellrc_unifiedenv/basic/shellrc @@ -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' diff --git a/internal/nix/testdata/shellrc_unifiedenv/basic/shellrc.golden b/internal/nix/testdata/shellrc_unifiedenv/basic/shellrc.golden new file mode 100644 index 00000000000..2923438a143 --- /dev/null +++ b/internal/nix/testdata/shellrc_unifiedenv/basic/shellrc.golden @@ -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 diff --git a/internal/nix/testdata/shellrc_unifiedenv/nohook/env b/internal/nix/testdata/shellrc_unifiedenv/nohook/env new file mode 100644 index 00000000000..5b9b5a3f6ee --- /dev/null +++ b/internal/nix/testdata/shellrc_unifiedenv/nohook/env @@ -0,0 +1 @@ +PATH=/a/test/path diff --git a/internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc b/internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc new file mode 100644 index 00000000000..85834d546fd --- /dev/null +++ b/internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc @@ -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' diff --git a/internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc.golden b/internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc.golden new file mode 100644 index 00000000000..140d3bf9f8f --- /dev/null +++ b/internal/nix/testdata/shellrc_unifiedenv/nohook/shellrc.golden @@ -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 diff --git a/internal/nix/testdata/shellrc_unifiedenv/noshellrc/env b/internal/nix/testdata/shellrc_unifiedenv/noshellrc/env new file mode 100644 index 00000000000..5b9b5a3f6ee --- /dev/null +++ b/internal/nix/testdata/shellrc_unifiedenv/noshellrc/env @@ -0,0 +1 @@ +PATH=/a/test/path diff --git a/internal/nix/testdata/shellrc_unifiedenv/noshellrc/hook b/internal/nix/testdata/shellrc_unifiedenv/noshellrc/hook new file mode 100644 index 00000000000..770d44938c5 --- /dev/null +++ b/internal/nix/testdata/shellrc_unifiedenv/noshellrc/hook @@ -0,0 +1 @@ +echo "Hello from a devbox shell hook!" diff --git a/internal/nix/testdata/shellrc_unifiedenv/noshellrc/shellrc.golden b/internal/nix/testdata/shellrc_unifiedenv/noshellrc/shellrc.golden new file mode 100644 index 00000000000..4082948341a --- /dev/null +++ b/internal/nix/testdata/shellrc_unifiedenv/noshellrc/shellrc.golden @@ -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