@@ -142,43 +142,34 @@ def metafunc(self, backend, *args, **kwargs):
142142 return metafunc
143143
144144
145- def requires_ninja(func ):
146- assert callable(func )
145+ def requires_tool(tool ):
146+ assert not callable(tool )
147147
148- @wraps(func)
149- def decorated(self, *args, **kwargs):
150- if not shutil.which('ninja'):
151- self.fail('test requires ninja to be installed (available in PATH)')
152- return func(self, *args, **kwargs)
148+ def decorate(func):
149+ assert callable(func)
153150
154- return decorated
151+ @wraps(func)
152+ def decorated(self, *args, **kwargs):
153+ if not shutil.which(tool):
154+ if f'EMTEST_SKIP_{tool.upper()}' in os.environ:
155+ self.skipTest(f'test requires ccache and EMTEST_SKIP_{tool.upper()} is set')
156+ else:
157+ self.fail(f'{tool} required to run this test. Use EMTEST_SKIP_{tool.upper()} to skip')
158+ return func(self, *args, **kwargs)
155159
160+ return decorated
156161
157- def requires_ccache(func):
158- assert callable(func)
162+ return decorate
159163
160- @wraps(func)
161- def decorated(self, *args, **kwargs):
162- if not shutil.which('ccache'):
163- self.fail('test requires ccache to be installed (available in PATH)')
164- return func(self, *args, **kwargs)
165164
166- return decorated
165+ def requires_ninja(func):
166+ assert callable(func)
167+ return requires_tool('ninja')(func)
167168
168169
169170def requires_scons(func):
170171 assert callable(func)
171-
172- @wraps(func)
173- def decorated(self, *args, **kwargs):
174- if not shutil.which('scons'):
175- if 'EMTEST_SKIP_SCONS' in os.environ:
176- self.skipTest('test requires scons and EMTEST_SKIP_SCONS is set')
177- else:
178- self.fail('scons required to run this test. Use EMTEST_SKIP_SCONS to skip')
179- return func(self, *args, **kwargs)
180-
181- return decorated
172+ return requires_tool('scons')(func)
182173
183174
184175def requires_pkg_config(func):
@@ -12566,7 +12557,7 @@ def test_compiler_wrapper(self):
1256612557 self.assertContained('wrapping compiler call: ', stdout)
1256712558 self.assertExists('test_hello_world.o')
1256812559
12569- @requires_ccache
12560+ @requires_tool('ccache')
1257012561 @with_env_modify({'EM_COMPILER_WRAPPER': 'ccache'})
1257112562 def test_compiler_wrapper_ccache(self):
1257212563 self.do_runf('hello_world.c', 'hello, world!')
0 commit comments