Skip to content

Commit

Permalink
Added warnings for zero test, except for when doing --compile. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
kraigher committed Jan 28, 2016
1 parent 0add5bd commit b5a1dd5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
6 changes: 3 additions & 3 deletions vunit/test/acceptance/test_external_run_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2015, Lars Asplund lars.anders.asplund@gmail.com
# Copyright (c) 2015-2016, Lars Asplund lars.anders.asplund@gmail.com

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

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

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

def test_vhdl_generate_tests_example_project(self):
self.check(join(ROOT, "examples", "vhdl", "generate_tests", "run.py"))
Expand Down
39 changes: 31 additions & 8 deletions vunit/test/unit/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,7 @@ def side_effect():
pre_config.side_effect = side_effect

obj.add_config(name="", pre_config=pre_config)
try:
ui.main()
except SystemExit as exc:
if retval is True:
self.assertEqual(exc.code, 0)
else:
self.assertEqual(exc.code, 1)
self._run_main(ui, 0 if retval else 1)

pre_config.assert_has_calls([call()])

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

@mock.patch("vunit.ui.LOGGER", autospec=True)
def test_warning_on_no_tests(self, logger):
ui = self._create_ui("--compile")
self._run_main(ui)
self.assertEqual(logger.warning.mock_calls, [])
logger.reset_mock()

ui = self._create_ui("--list")
self._run_main(ui)
self.assertEqual(len(logger.warning.mock_calls), 1)
self.assertTrue("found no test benches" in str(logger.warning.mock_calls))
logger.reset_mock()

ui = self._create_ui()
self._run_main(ui)
self.assertEqual(len(logger.warning.mock_calls), 1)
self.assertTrue("found no test benches" in str(logger.warning.mock_calls))
logger.reset_mock()

def _create_ui(self, *args):
""" Create an instance of the VUnit public interface class """
ui = VUnit.from_argv(argv=["--output-path=%s" % self._output_path,
"--clean"] + list(args))
"--clean"] + list(args),
compile_builtins=False)
ui.add_library('lib')

factory = MockSimulatorFactory(self._output_path)
self.mocksim = factory.mocksim
ui._simulator_factory = factory # pylint: disable=protected-access
return ui

def _run_main(self, ui, code=0):
"""
Run ui.main and expect exit code
"""
try:
ui.main()
except SystemExit as exc:
self.assertEqual(exc.code, code)

def create_entity_file(self, idx=0, file_suffix='.vhd'):
"""
Create and a temporary file containing the same source code
Expand Down
11 changes: 10 additions & 1 deletion vunit/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2014-2015, Lars Asplund lars.anders.asplund@gmail.com
# Copyright (c) 2014-2016, Lars Asplund lars.anders.asplund@gmail.com

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

def num_tests(self):
"""
Return the number of tests within
"""
num_tests = 0
for test_suite in self:
num_tests += len(test_suite.test_cases)
return num_tests

def __iter__(self):
return iter(self._test_suites)

Expand Down
7 changes: 5 additions & 2 deletions vunit/test_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2014-2015, Lars Asplund lars.anders.asplund@gmail.com
# Copyright (c) 2014-2016, Lars Asplund lars.anders.asplund@gmail.com

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


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

Expand Down
10 changes: 7 additions & 3 deletions vunit/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,11 @@ def _main_list_only(self):
"""
simulator_if = None
test_suites = self._create_tests(simulator_if)
num_tests = 0

for test_suite in test_suites:
for name in test_suite.test_cases:
print(name)
num_tests += 1
print("Listed %i tests" % num_tests)
print("Listed %i tests" % test_suites.num_tests())
return True

def _main_compile_only(self):
Expand Down Expand Up @@ -488,6 +487,11 @@ def _create_tests(self, simulator_if):
scanner = TestScanner(simulator_if,
self._configuration)
test_list = scanner.from_project(self._project, entity_filter=self._tb_filter)

if test_list.num_tests() == 0:
LOGGER.warning("Test scanner found no test benches using current filter rule:\n%s",
self._tb_filter.__doc__)

test_list.keep_matches(self._test_filter)
return test_list

Expand Down

0 comments on commit b5a1dd5

Please sign in to comment.