@@ -142,43 +142,34 @@ def metafunc(self, backend, *args, **kwargs):
142
142
return metafunc
143
143
144
144
145
- def requires_ninja(func ):
146
- assert callable(func )
145
+ def requires_tool(tool ):
146
+ assert not callable(tool )
147
147
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)
153
150
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)
155
159
160
+ return decorated
156
161
157
- def requires_ccache(func):
158
- assert callable(func)
162
+ return decorate
159
163
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)
165
164
166
- return decorated
165
+ def requires_ninja(func):
166
+ assert callable(func)
167
+ return requires_tool('ninja')(func)
167
168
168
169
169
170
def requires_scons(func):
170
171
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)
182
173
183
174
184
175
def requires_pkg_config(func):
@@ -12566,7 +12557,7 @@ def test_compiler_wrapper(self):
12566
12557
self.assertContained('wrapping compiler call: ', stdout)
12567
12558
self.assertExists('test_hello_world.o')
12568
12559
12569
- @requires_ccache
12560
+ @requires_tool('ccache')
12570
12561
@with_env_modify({'EM_COMPILER_WRAPPER': 'ccache'})
12571
12562
def test_compiler_wrapper_ccache(self):
12572
12563
self.do_runf('hello_world.c', 'hello, world!')
0 commit comments