MCPcopy Index your code
hub / github.com/jetify-com/devbox / TestShellPath

Function TestShellPath

internal/devbox/shell_test.go:198–254  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

196}
197
198func TestShellPath(t *testing.T) {
199 tests := []struct {
200 name string
201 envOpts devopt.EnvOptions
202 expected string
203 env map[string]string
204 }{
205 {
206 name: "pure mode enabled",
207 envOpts: devopt.EnvOptions{
208 Pure: true,
209 },
210 expected: `^/nix/store/.*/bin/bash$`,
211 },
212 {
213 name: "pure mode disabled",
214 envOpts: devopt.EnvOptions{
215 Pure: false,
216 },
217 env: map[string]string{
218 envir.Shell: "/usr/local/bin/bash",
219 },
220 expected: "^/usr/local/bin/bash$",
221 },
222 }
223
224 for _, test := range tests {
225 t.Run(test.name, func(t *testing.T) {
226 for k, v := range test.env {
227 t.Setenv(k, v)
228 }
229 tmpDir := t.TempDir()
230 err := InitConfig(tmpDir)
231 if err != nil {
232 t.Fatal("Got InitConfig error:", err)
233 }
234 d, err := Open(&devopt.Opts{
235 Dir: tmpDir,
236 Stderr: os.Stderr,
237 })
238 if err != nil {
239 t.Fatal("Got Open error:", err)
240 }
241 gotPath, err := d.shellPath(test.envOpts)
242 if err != nil {
243 t.Fatal("Got shellPath error:", err)
244 }
245 matched, err := regexp.MatchString(test.expected, gotPath)
246 if err != nil {
247 t.Fatal("Got regexp.MatchString error:", err)
248 }
249 if !matched {
250 t.Errorf("Expected shell path %s, but got %s", test.expected, gotPath)
251 }
252 })
253 }
254}
255

Callers

nothing calls this directly

Calls 4

shellPathMethod · 0.80
InitConfigFunction · 0.70
OpenFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected