@@ -3390,6 +3390,45 @@ def test_find_related_easyconfigs(self):
33903390        res  =  [os .path .basename (x ) for  x  in  find_related_easyconfigs (test_easyconfigs , ec )]
33913391        self .assertEqual (res , ['toy-0.0-deps.eb' ])
33923392
3393+         # Expected order: 
3394+         # 1. Same toolchain & version 
3395+         # 2. Same toolchain, different version 
3396+         # 3. Any toolchain 
3397+         # For each: 
3398+         #   exact version, major/minor version, major version, any version 
3399+         ec ['version' ] =  '1.2.3' 
3400+         ec ['toolchain' ] =  {'name' : 'GCC' , 'version' : '12' }
3401+ 
3402+         # Use an empty folder to have full control over existing files 
3403+         tmp_ec_dir  =  tempfile .mkdtemp ()
3404+         files  =  []
3405+         # Create list of files in desired order, 
3406+         # so we can remove them one by one to check that the search still finds the correct one 
3407+         # 1. Same toolchain incl. version 
3408+         # 2. Same toolchain, different version 
3409+         # 3. Different toolchain 
3410+         for  toolchain  in  ('GCC-12' , 'GCC-11' , 'Clang-12' ):
3411+             # Secondary criteria: 
3412+             # a. Same version 
3413+             # b. Same major.minor version 
3414+             # c. Same major version 
3415+             # d. Different version 
3416+             for  version  in  ('1.2.3' , '1.2' , '1' , '4' ):
3417+                 filepath  =  os .path .join (tmp_ec_dir , '-' .join ((ec ['name' ], version , toolchain )) +  '.eb' )
3418+                 write_file (filepath , f"name = '{ ec ['name' ]}  )
3419+                 files .append (filepath )
3420+ 
3421+         ec_name  =  f'{ ec .name } { ec .version } { ec ["toolchain" ]["name" ]} { ec ["toolchain" ]["version" ]}  
3422+         while  files :
3423+             result  =  find_related_easyconfigs (tmp_ec_dir , ec )
3424+             # Only show basenames in error 
3425+             result , expected , files_b  =  [[os .path .basename (f ) for  f  in  cur_files ]
3426+                                          for  cur_files  in  (result , [files [0 ]], files )]
3427+             self .assertEqual (result , expected ,
3428+                              msg = 'Found %s but expected %s when searching for "%s" in %s' 
3429+                              %  (result , expected , ec_name , files_b ))
3430+             remove_file (files .pop (0 ))
3431+ 
33933432        # no matches for unknown software name 
33943433        ec ['name' ] =  'nosuchsoftware' 
33953434        self .assertEqual (find_related_easyconfigs (test_easyconfigs , ec ), [])
0 commit comments