From 6785de2199d9963724d0b461c3c7ccee7003e456 Mon Sep 17 00:00:00 2001 From: Alex Domingo Date: Wed, 25 Sep 2024 10:38:16 +0200 Subject: [PATCH] add unit test for option module-search-path-headers --- test/framework/easyblock.py | 90 +++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/test/framework/easyblock.py b/test/framework/easyblock.py index bdf15504f4..ad8cc243d7 100644 --- a/test/framework/easyblock.py +++ b/test/framework/easyblock.py @@ -593,6 +593,96 @@ def test_make_module_req(self): eb.close_log() os.remove(eb.logfile) + def test_module_search_path_headers(self): + """Test functionality of module-search-path-headers option""" + sp_headers_mode = { + "none": [], + "CPATH": ["CPATH"], + "INCLUDE_PATHS": ["C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH", "OBJC_INCLUDE_PATH"], + } + + self.contents = '\n'.join([ + 'easyblock = "ConfigureMake"', + 'name = "pi"', + 'version = "3.14"', + 'homepage = "http://example.com"', + 'description = "test easyconfig"', + 'toolchain = SYSTEM', + ]) + self.writeEC() + eb = EasyBlock(EasyConfig(self.eb_file)) + eb.installdir = config.install_path() + os.makedirs(eb.installdir) + os.mkdir(os.path.join(eb.installdir, 'include')) + write_file(os.path.join(eb.installdir, 'include', 'header.h'), 'dummy header file') + + for build_opt in sp_headers_mode: + init_config(build_options={"module_search_path_headers": build_opt, "silent": True}) + with eb.module_generator.start_module_creation(): + guess = eb.make_module_req() + if not sp_headers_mode[build_opt]: + # none option adds nothing to module file + for header_path in eb.module_header_dirs: + if get_module_syntax() == 'Tcl': + tcl_ref_pattern = rf"^prepend-path\s+CPATH\s+\$root/{header_path}$" + self.assertFalse(re.search(tcl_ref_pattern, guess, re.M)) + elif get_module_syntax() == 'Lua': + lua_ref_pattern = rf'^prepend_path\("CPATH", pathJoin\(root, "{header_path}"\)\)$' + self.assertFalse(re.search(lua_ref_pattern, guess, re.M)) + else: + for env_var in sp_headers_mode[build_opt]: + for header_path in eb.module_header_dirs: + if get_module_syntax() == 'Tcl': + tcl_ref_pattern = rf"^prepend-path\s+{env_var}\s+\$root/{header_path}$" + self.assertTrue(re.search(tcl_ref_pattern, guess, re.M)) + elif get_module_syntax() == 'Lua': + lua_ref_pattern = rf'^prepend_path\("{env_var}", pathJoin\(root, "{header_path}"\)\)$' + self.assertTrue(re.search(lua_ref_pattern, guess, re.M)) + + # test with easyconfig parameter + for ec_param in sp_headers_mode: + self.contents += f'\nmodule_search_path_headers = "{ec_param}"' + self.writeEC() + eb = EasyBlock(EasyConfig(self.eb_file)) + eb.installdir = config.install_path() + + for build_opt in sp_headers_mode: + init_config(build_options={"module_search_path_headers": build_opt, "silent": True}) + with eb.module_generator.start_module_creation(): + guess = eb.make_module_req() + if not sp_headers_mode[ec_param]: + # none option adds nothing to module file + for header_path in eb.module_header_dirs: + if get_module_syntax() == 'Tcl': + tcl_ref_pattern = rf"^prepend-path\s+CPATH\s+\$root/{header_path}$" + self.assertFalse(re.search(tcl_ref_pattern, guess, re.M)) + elif get_module_syntax() == 'Lua': + lua_ref_pattern = rf'^prepend_path\("CPATH", pathJoin\(root, "{header_path}"\)\)$' + self.assertFalse(re.search(lua_ref_pattern, guess, re.M)) + else: + for env_var in sp_headers_mode[ec_param]: + for header_path in eb.module_header_dirs: + if get_module_syntax() == 'Tcl': + tcl_ref_pattern = rf"^prepend-path\s+{env_var}\s+\$root/{header_path}$" + self.assertTrue(re.search(tcl_ref_pattern, guess, re.M)) + elif get_module_syntax() == 'Lua': + lua_ref_pattern = rf'^prepend_path\("{env_var}", pathJoin\(root, "{header_path}"\)\)$' + self.assertTrue(re.search(lua_ref_pattern, guess, re.M)) + + # test wrong easyconfig parameter + self.contents += '\nmodule_search_path_headers = "WRONG_OPT"' + self.writeEC() + eb = EasyBlock(EasyConfig(self.eb_file)) + eb.installdir = config.install_path() + + error_pattern = "Unknown value selected for option module_search_path_headers" + with eb.module_generator.start_module_creation(): + self.assertErrorRegex(EasyBuildError, error_pattern, eb.make_module_req) + + # cleanup + eb.close_log() + os.remove(eb.logfile) + def test_make_module_extra(self): """Test for make_module_extra.""" init_config(build_options={'silent': True})