(t *testing.T)
| 196 | } |
| 197 | |
| 198 | func 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 |
nothing calls this directly
no test coverage detected