Skip to content

Commit b5a1dd5

Browse files
committed
Added warnings for zero test, except for when doing --compile. Closes #99.
1 parent 0add5bd commit b5a1dd5

5 files changed

Lines changed: 56 additions & 17 deletions

File tree

vunit/test/acceptance/test_external_run_scripts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
44
#
5-
# Copyright (c) 2015, Lars Asplund lars.anders.asplund@gmail.com
5+
# Copyright (c) 2015-2016, Lars Asplund lars.anders.asplund@gmail.com
66

77
"""
88
Verify that all external run scripts work correctly
@@ -37,10 +37,10 @@ def test_verilog_uart_example_project(self):
3737
self.check(join(ROOT, "examples", "verilog", "uart", "run.py"))
3838

3939
def test_vhdl_logging_example_project(self):
40-
self.check(join(ROOT, "examples", "vhdl", "logging", "compile.py"))
40+
self.check(join(ROOT, "examples", "vhdl", "logging", "compile.py"), args=["--compile"])
4141

4242
def test_vhdl_check_example_project(self):
43-
self.check(join(ROOT, "examples", "vhdl", "check", "compile.py"))
43+
self.check(join(ROOT, "examples", "vhdl", "check", "compile.py"), args=["--compile"])
4444

4545
def test_vhdl_generate_tests_example_project(self):
4646
self.check(join(ROOT, "examples", "vhdl", "generate_tests", "run.py"))

vunit/test/unit/test_ui.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,7 @@ def side_effect():
287287
pre_config.side_effect = side_effect
288288

289289
obj.add_config(name="", pre_config=pre_config)
290-
try:
291-
ui.main()
292-
except SystemExit as exc:
293-
if retval is True:
294-
self.assertEqual(exc.code, 0)
295-
else:
296-
self.assertEqual(exc.code, 1)
290+
self._run_main(ui, 0 if retval else 1)
297291

298292
pre_config.assert_has_calls([call()])
299293

@@ -304,17 +298,46 @@ def test_entity_has_pre_config(self):
304298
def test_test_has_pre_config(self):
305299
self._test_pre_config_helper(True, test_not_entity=False)
306300

301+
@mock.patch("vunit.ui.LOGGER", autospec=True)
302+
def test_warning_on_no_tests(self, logger):
303+
ui = self._create_ui("--compile")
304+
self._run_main(ui)
305+
self.assertEqual(logger.warning.mock_calls, [])
306+
logger.reset_mock()
307+
308+
ui = self._create_ui("--list")
309+
self._run_main(ui)
310+
self.assertEqual(len(logger.warning.mock_calls), 1)
311+
self.assertTrue("found no test benches" in str(logger.warning.mock_calls))
312+
logger.reset_mock()
313+
314+
ui = self._create_ui()
315+
self._run_main(ui)
316+
self.assertEqual(len(logger.warning.mock_calls), 1)
317+
self.assertTrue("found no test benches" in str(logger.warning.mock_calls))
318+
logger.reset_mock()
319+
307320
def _create_ui(self, *args):
308321
""" Create an instance of the VUnit public interface class """
309322
ui = VUnit.from_argv(argv=["--output-path=%s" % self._output_path,
310-
"--clean"] + list(args))
323+
"--clean"] + list(args),
324+
compile_builtins=False)
311325
ui.add_library('lib')
312326

313327
factory = MockSimulatorFactory(self._output_path)
314328
self.mocksim = factory.mocksim
315329
ui._simulator_factory = factory # pylint: disable=protected-access
316330
return ui
317331

332+
def _run_main(self, ui, code=0):
333+
"""
334+
Run ui.main and expect exit code
335+
"""
336+
try:
337+
ui.main()
338+
except SystemExit as exc:
339+
self.assertEqual(exc.code, code)
340+
318341
def create_entity_file(self, idx=0, file_suffix='.vhd'):
319342
"""
320343
Create and a temporary file containing the same source code

vunit/test_list.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
44
#
5-
# Copyright (c) 2014-2015, Lars Asplund lars.anders.asplund@gmail.com
5+
# Copyright (c) 2014-2016, Lars Asplund lars.anders.asplund@gmail.com
66

77
"""
88
Functionality to handle lists of test suites and filtering of them
@@ -35,6 +35,15 @@ def keep_matches(self, test_filter):
3535
self._test_suites = [test for test in self._test_suites
3636
if test.keep_matches(test_filter)]
3737

38+
def num_tests(self):
39+
"""
40+
Return the number of tests within
41+
"""
42+
num_tests = 0
43+
for test_suite in self:
44+
num_tests += len(test_suite.test_cases)
45+
return num_tests
46+
3847
def __iter__(self):
3948
return iter(self._test_suites)
4049

vunit/test_scanner.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
44
#
5-
# Copyright (c) 2014-2015, Lars Asplund lars.anders.asplund@gmail.com
5+
# Copyright (c) 2014-2016, Lars Asplund lars.anders.asplund@gmail.com
66

77
"""
88
Functionality to automatically create test suites from a project
@@ -269,7 +269,10 @@ def find_pragmas(self, code, file_name):
269269

270270

271271
def tb_filter(entity):
272-
""" Filter entities with file name tb_* and entity_name tb_* """
272+
"""
273+
Filters entities with both file name and entity name matching tb_* or *_tb.
274+
"""
275+
# Above docstring can show up in ui.py warnings
273276
file_ok = basename(entity.file_name).startswith("tb_") or splitext(basename(entity.file_name))[0].endswith("_tb")
274277
entity_ok = entity.name.startswith("tb_") or entity.name.endswith("_tb")
275278

vunit/ui.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,11 @@ def _main_list_only(self):
432432
"""
433433
simulator_if = None
434434
test_suites = self._create_tests(simulator_if)
435-
num_tests = 0
435+
436436
for test_suite in test_suites:
437437
for name in test_suite.test_cases:
438438
print(name)
439-
num_tests += 1
440-
print("Listed %i tests" % num_tests)
439+
print("Listed %i tests" % test_suites.num_tests())
441440
return True
442441

443442
def _main_compile_only(self):
@@ -488,6 +487,11 @@ def _create_tests(self, simulator_if):
488487
scanner = TestScanner(simulator_if,
489488
self._configuration)
490489
test_list = scanner.from_project(self._project, entity_filter=self._tb_filter)
490+
491+
if test_list.num_tests() == 0:
492+
LOGGER.warning("Test scanner found no test benches using current filter rule:\n%s",
493+
self._tb_filter.__doc__)
494+
491495
test_list.keep_matches(self._test_filter)
492496
return test_list
493497

0 commit comments

Comments
 (0)