@@ -294,24 +294,49 @@ func TestLoad(t *testing.T) {
294
294
}
295
295
scenarios := []scenario {
296
296
{
297
- "Load workspace" ,
297
+ "Load workspace with a bash shell " ,
298
298
"" ,
299
299
func () {
300
+ os .Setenv ("SHELL" , "bash" )
301
+ },
302
+ func (args []string ) {
303
+ assert .Equal (t , []string {"-c" , "export WO_NAME=test && export WO_ENV=default && source " + getHomePath (t ) + "/.config/wo/functions/bash/test.bash" }, args )
304
+ },
305
+ },
306
+ {
307
+ "Load workspace with a fish shell" ,
308
+ "" ,
309
+ func () {
310
+ os .Setenv ("SHELL" , "fish" )
300
311
},
301
312
func (args []string ) {
302
- assert .Equal (t , []string {"-C" , "source " + getHomePath (t ) + "/.config/wo/functions/bash /test.bash " }, args )
313
+ assert .Equal (t , []string {"-C" , "set -x -g WO_NAME test" , "-C" , "set -x -g WO_ENV default" , "-C" , " source " + getHomePath (t ) + "/.config/wo/functions/fish /test.fish " }, args )
303
314
},
304
315
},
305
316
{
306
- "Load workspace with an env defined" ,
317
+ "Load workspace with an env defined and a bash shell " ,
307
318
"prod" ,
308
319
func () {
309
320
envPath := getConfigPath (t ) + "/envs/bash"
310
321
assert .NoError (t , os .MkdirAll (envPath + "/test" , 0777 ))
311
322
assert .NoError (t , os .WriteFile (envPath + "/test/prod.bash" , []byte {}, 0777 ))
323
+ os .Setenv ("SHELL" , "bash" )
324
+ },
325
+ func (args []string ) {
326
+ assert .Equal (t , []string {"-c" , "export WO_NAME=test && export WO_ENV=prod && source " + getHomePath (t ) + "/.config/wo/envs/bash/test/prod.bash && source " + getHomePath (t ) + "/.config/wo/functions/bash/test.bash" }, args )
327
+ },
328
+ },
329
+ {
330
+ "Load workspace with an env defined and a fish shell" ,
331
+ "prod" ,
332
+ func () {
333
+ envPath := getConfigPath (t ) + "/envs/fish"
334
+ assert .NoError (t , os .MkdirAll (envPath + "/test" , 0777 ))
335
+ assert .NoError (t , os .WriteFile (envPath + "/test/prod.fish" , []byte {}, 0777 ))
336
+ os .Setenv ("SHELL" , "fish" )
312
337
},
313
338
func (args []string ) {
314
- assert .Equal (t , []string {"-C" , "source " + getHomePath (t ) + "/.config/wo/envs/bash /test/prod.bash " , "-C" , "source " + getHomePath (t ) + "/.config/wo/functions/bash /test.bash " }, args )
339
+ assert .Equal (t , []string {"-C" , "set -x -g WO_NAME test" , "-C" , "set -x -g WO_ENV prod" , "-C" , " source " + getHomePath (t ) + "/.config/wo/envs/fish /test/prod.fish " , "-C" , "source " + getHomePath (t ) + "/.config/wo/functions/fish /test.fish " }, args )
315
340
},
316
341
},
317
342
}
@@ -320,15 +345,15 @@ func TestLoad(t *testing.T) {
320
345
os .RemoveAll (getConfigPath (t ))
321
346
os .Setenv ("VISUAL" , "emacs" )
322
347
os .Setenv ("EDITOR" , "emacs" )
323
- os .Setenv ("SHELL" , "bash" )
348
+ os .Unsetenv ("SHELL" )
349
+ s .setup ()
324
350
w , err := NewWorkspaceManager ()
325
351
args := []string {}
326
352
w .execCommand = func (a ... string ) error {
327
353
args = a
328
354
return nil
329
355
}
330
356
assert .NoError (t , err )
331
- s .setup ()
332
357
assert .NoError (t , w .Load ("test" , s .env ))
333
358
s .test (args )
334
359
})
@@ -345,43 +370,70 @@ func TestRunFunction(t *testing.T) {
345
370
}
346
371
scenarios := []scenario {
347
372
{
348
- "Run function" ,
373
+ "Run a function with a bash shell " ,
349
374
[]string {"run-db" },
350
375
"" ,
351
376
func () {
377
+ os .Setenv ("SHELL" , "/bin/bash" )
352
378
},
353
379
func (args []string ) {
354
- assert .Equal (t , []string {"-C " , "source " + getHomePath (t ) + "/.config/wo/functions/bash/test.bash" , "-c" , " run-db" }, args )
380
+ assert .Equal (t , []string {"-c " , "export WO_NAME=test && export WO_ENV=default && source " + getHomePath (t ) + "/.config/wo/functions/bash/test.bash && run-db" }, args )
355
381
},
356
382
},
357
383
{
358
- "Run a function with an env defined" ,
359
- []string {"run-db" , "--watch" },
384
+ "Run a function with a fish shell" ,
385
+ []string {"run-db" },
386
+ "" ,
387
+ func () {
388
+ os .Setenv ("SHELL" , "/bin/fish" )
389
+ },
390
+ func (args []string ) {
391
+ assert .Equal (t , []string {"-C" , "set -x -g WO_NAME test" , "-C" , "set -x -g WO_ENV default" , "-C" , "source " + getHomePath (t ) + "/.config/wo/functions/fish/test.fish" , "-c" , "run-db" }, args )
392
+ },
393
+ },
394
+ {
395
+ "Run a function with an env defined and a bash shell" ,
396
+ []string {"run-db" , "watch" },
360
397
"prod" ,
361
398
func () {
362
399
envPath := getConfigPath (t ) + "/envs/bash"
363
400
assert .NoError (t , os .MkdirAll (envPath + "/test" , 0777 ))
364
401
assert .NoError (t , os .WriteFile (envPath + "/test/prod.bash" , []byte {}, 0777 ))
402
+ os .Setenv ("SHELL" , "/bin/bash" )
365
403
},
366
404
func (args []string ) {
367
- assert .Equal (t , []string {"-C" , "source " + getHomePath (t ) + "/.config/wo/envs/bash/test/prod.bash" , "-C" , "source " + getHomePath (t ) + "/.config/wo/functions/bash/test.bash" , "-c" , "run-db --watch" }, args )
405
+ assert .Equal (t , []string {"-c" , "export WO_NAME=test && export WO_ENV=prod && source " + getHomePath (t ) + "/.config/wo/envs/bash/test/prod.bash && source " + getHomePath (t ) + "/.config/wo/functions/bash/test.bash && run-db watch" }, args )
406
+ },
407
+ },
408
+ {
409
+ "Run a function with an env defined and a fish shell" ,
410
+ []string {"run-db" , "watch" },
411
+ "prod" ,
412
+ func () {
413
+ envPath := getConfigPath (t ) + "/envs/fish"
414
+ assert .NoError (t , os .MkdirAll (envPath + "/test" , 0777 ))
415
+ assert .NoError (t , os .WriteFile (envPath + "/test/prod.fish" , []byte {}, 0777 ))
416
+ os .Setenv ("SHELL" , "/bin/fish" )
417
+ },
418
+ func (args []string ) {
419
+ assert .Equal (t , []string {"-C" , "set -x -g WO_NAME test" , "-C" , "set -x -g WO_ENV prod" , "-C" , "source " + getHomePath (t ) + "/.config/wo/envs/fish/test/prod.fish" , "-C" , "source " + getHomePath (t ) + "/.config/wo/functions/fish/test.fish" , "-c" , "run-db watch" }, args )
368
420
},
369
421
},
370
422
}
371
423
for _ , s := range scenarios {
372
424
t .Run (s .name , func (t * testing.T ) {
373
425
os .RemoveAll (getConfigPath (t ))
426
+ os .Unsetenv ("SHELL" )
374
427
os .Setenv ("VISUAL" , "emacs" )
375
428
os .Setenv ("EDITOR" , "emacs" )
376
- os . Setenv ( "SHELL" , "bash" )
429
+ s . setup ( )
377
430
w , err := NewWorkspaceManager ()
378
431
args := []string {}
379
432
w .execCommand = func (a ... string ) error {
380
433
args = a
381
434
return nil
382
435
}
383
436
assert .NoError (t , err )
384
- s .setup ()
385
437
assert .NoError (t , w .RunFunction ("test" , s .env , s .functionAndArgs ))
386
438
s .test (args )
387
439
})
0 commit comments