@@ -4522,7 +4522,7 @@ def test_github_new_update_pr(self):
45224522 res = [d for d in res if os .path .basename (d ) != os .path .basename (git_working_dir )]
45234523 if len (res ) == 1 :
45244524 unstaged_file_full = os .path .join (res [0 ], unstaged_file )
4525- self .assertNotExists (unstaged_file_full ), "%s not found in %s" % ( unstaged_file , res [ 0 ])
4525+ self .assertNotExists (unstaged_file_full )
45264526 else :
45274527 self .fail ("Found copy of easybuild-easyconfigs working copy" )
45284528
@@ -5249,6 +5249,45 @@ def test_dump_env_script(self):
52495249 ])
52505250 self .assertEqual (out .strip (), expected_out )
52515251
5252+ def test_dump_env_script_existing_module (self ):
5253+ toy_ec = 'toy-0.0.eb'
5254+
5255+ os .chdir (self .test_prefix )
5256+ self ._run_mock_eb ([toy_ec , '--force' ], do_build = True )
5257+ env_script = os .path .join (self .test_prefix , os .path .splitext (toy_ec )[0 ] + '.env' )
5258+ test_module = os .path .join (self .test_installpath , 'modules' , 'all' , 'toy' , '0.0' )
5259+ if get_module_syntax () == 'Lua' :
5260+ test_module += '.lua'
5261+ self .assertExists (test_module )
5262+ self .assertNotExists (env_script )
5263+
5264+ args = [toy_ec , '--dump-env' ]
5265+ os .chdir (self .test_prefix )
5266+ self ._run_mock_eb (args , do_build = True , raise_error = True )
5267+ self .assertExists (env_script )
5268+ self .assertExists (test_module )
5269+ module_content = read_file (test_module )
5270+ env_file_content = read_file (env_script )
5271+
5272+ error_msg = (r"Script\(s\) already exists, not overwriting them \(unless --force is used\): "
5273+ + os .path .basename (env_script ))
5274+ os .chdir (self .test_prefix )
5275+ self .assertErrorRegex (EasyBuildError , error_msg , self ._run_mock_eb , args , do_build = True , raise_error = True )
5276+ self .assertExists (env_script )
5277+ self .assertExists (test_module )
5278+ # Unchanged module and env file
5279+ self .assertEqual (read_file (test_module ), module_content )
5280+ self .assertEqual (read_file (env_script ), env_file_content )
5281+
5282+ args .append ('--force' )
5283+ os .chdir (self .test_prefix )
5284+ self ._run_mock_eb (args , do_build = True , raise_error = True )
5285+ self .assertExists (env_script )
5286+ self .assertExists (test_module )
5287+ # Unchanged module and env file
5288+ self .assertEqual (read_file (test_module ), module_content )
5289+ self .assertEqual (read_file (env_script ), env_file_content )
5290+
52525291 def test_stop (self ):
52535292 """Test use of --stop."""
52545293 args = ['toy-0.0.eb' , '--force' , '--stop=configure' ]
0 commit comments