@@ -432,6 +432,8 @@ def tearDown(self):
432432
433433 def test_start_directory (self ):
434434
435+ start_directory = os .getcwd ()
436+
435437 sconfig = kaptan .Kaptan (handler = 'yaml' )
436438 sconfig = sconfig .import_config (self .yaml_config ).get ()
437439 sconfig = config .expand (sconfig )
@@ -441,7 +443,117 @@ def test_start_directory(self):
441443 builder .build (session = self .session )
442444
443445 assert (self .session == builder .session )
444- dirs = ['/usr/bin' , '/dev' , '/tmp/foo bar' , '/usr' , os .getcwd ()]
446+ dirs = ['/usr/bin' , '/dev' , '/tmp/foo bar' , '/usr' , '/usr' ]
447+ for path , window in zip (dirs , self .session .windows ):
448+ for p in window .panes :
449+ for i in range (60 ):
450+ p .server ._update_panes ()
451+ if p .get ('pane_current_path' ) == path :
452+ break
453+ time .sleep (.2 )
454+
455+ self .assertEqual (p .get ('pane_current_path' ), path )
456+
457+
458+ class StartDirectoryRelativeTest (TmuxTestCase ):
459+ """Same as above test, but with relative start directory, mimicing
460+ loading it from a location of project file. Like::
461+
462+ $ tmuxp load ~/workspace/myproject/.tmuxp.yaml
463+
464+ instead of::
465+
466+ $ cd ~/workspace/myproject/.tmuxp.yaml
467+ $ tmuxp load .
468+
469+ """
470+
471+ yaml_config = """
472+ session_name: sampleconfig
473+ start_directory: ./
474+ windows:
475+ - window_name: supposed to be /usr/bin
476+ start_directory: '/usr/bin'
477+ layout: main-horizontal
478+ options:
479+ main-pane-height: 50
480+ panes:
481+ - shell_command:
482+ - echo "hey"
483+ - shell_command:
484+ - echo "moo"
485+ - window_name: support to be /dev
486+ start_directory: '/dev'
487+ layout: main-horizontal
488+ panes:
489+ - shell_command:
490+ - pwd
491+ - shell_command:
492+ - echo "hey"
493+ - shell_command:
494+ - echo "moo"
495+ - window_name: cwd containing a space
496+ start_directory: /tmp/foo bar
497+ layout: main-horizontal
498+ panes:
499+ - shell_command:
500+ - pwd
501+ - shell_command:
502+ - echo "hey"
503+ - shell_command:
504+ - echo "moo"
505+ - window_name: testsa3
506+ layout: main-horizontal
507+ panes:
508+ - shell_command:
509+ - pwd
510+ - shell_command:
511+ - echo "hey"
512+ - shell_command:
513+ - echo "moo3"
514+ - window_name: cwd relative to config file
515+ layout: main-horizontal
516+ start_directory: ./
517+ panes:
518+ - shell_command:
519+ - pwd
520+ - shell_command:
521+ - echo "hey"
522+ - shell_command:
523+ - echo "moo3"
524+ """
525+
526+ def setUp (self ):
527+ super (StartDirectoryRelativeTest , self ).setUp ()
528+ if not os .path .exists ('/tmp/foo bar' ) and not os .path .exists ('/tmp/testRelConfigDir' ):
529+ os .mkdir ('/tmp/foo bar' )
530+ os .mkdir ('/tmp/testRelConfigDir' )
531+ self ._temp_dir_created = True
532+ else :
533+ self ._temp_dir_created = False
534+
535+ def tearDown (self ):
536+ super (StartDirectoryRelativeTest , self ).tearDown ()
537+ if self ._temp_dir_created :
538+ os .rmdir ('/tmp/foo bar' )
539+ os .rmdir ('/tmp/testRelConfigDir' )
540+
541+ def test_start_directory (self ):
542+
543+ start_directory = os .getcwd ()
544+
545+ sconfig = kaptan .Kaptan (handler = 'yaml' )
546+ sconfig = sconfig .import_config (self .yaml_config ).get ()
547+ # the second argument of os.getcwd() mimics the behavior
548+ # the CLI loader will do, but it passes in the config file's location.
549+ sconfig = config .expand (sconfig , '/tmp/testRelConfigDir' )
550+ sconfig = config .trickle (sconfig )
551+
552+ builder = WorkspaceBuilder (sconf = sconfig )
553+ builder .build (session = self .session )
554+
555+ assert (self .session == builder .session )
556+ dirs = ['/usr/bin' , '/dev' , '/tmp/foo bar' , '/tmp/testRelConfigDir' ]
445557 for path , window in zip (dirs , self .session .windows ):
446558 for p in window .panes :
447559 for i in range (60 ):
@@ -660,6 +772,7 @@ def suite():
660772 suite .addTest (unittest .makeSuite (FocusAndPaneIndexTest ))
661773 suite .addTest (unittest .makeSuite (PaneOrderingTest ))
662774 suite .addTest (unittest .makeSuite (StartDirectoryTest ))
775+ suite .addTest (unittest .makeSuite (StartDirectoryRelativeTest ))
663776 suite .addTest (unittest .makeSuite (ThreePaneTest ))
664777 suite .addTest (unittest .makeSuite (TwoPaneTest ))
665778 suite .addTest (unittest .makeSuite (WindowAutomaticRename ))
0 commit comments