def test(): objects = static_check._getObjectsFromText(it.text) it.assertCountEqual( [LibraryShouldBeOmited(line_number=3, column_number=8, library="work")], static_check._getMiscChecks(objects), )
def _getMiscChecks(objects): """ Get generic code hints (or it should do that sometime in the future...) """ if "library" not in [x["type"] for x in objects.values()]: return for library, obj in objects.items(): if obj["type"] != "library": continue if library == "work": yield LibraryShouldBeOmited(line_number=obj["lnum"], column_number=obj["start"], library=library)
def test(): filename = Path(p.join(TEST_TEMP_PATH, "some_file.vhd")) writeListToFile(str(filename), ["entity some_entity is end;"]) content = "\n".join([ "library work;", "use work.all;", "entity some_entity is end;" ]) diagnostics = it.project.getMessagesWithText(filename, content) _logger.debug("Records received:") for diagnostic in diagnostics: _logger.debug("- %s", diagnostic) it.assertIn( LibraryShouldBeOmited(library="work", filename=filename, column_number=8, line_number=0), diagnostics, ) it.assertIn(PathNotInProjectFile(filename), diagnostics)
def test(_): with PatchBuilder(): it.project.setConfig(Path(p.join(TEST_PROJECT, "vimhdl.prj"))) it.project._updateConfigIfNeeded() entity_a = _SourceMock( filename=_path("entity_a.vhd"), library="some_lib", design_units=[{ "name": "entity_a", "type": "entity" }], dependencies={("work", "foo")}, ) path_to_foo = Path( p.join(TEST_PROJECT, "another_library", "foo.vhd")) diags = { # entity_a.vhd is the path we're compiling, inject a diagnostic # from the builder str(entity_a.filename): [[ CheckerDiagnostic(filename=entity_a.filename, checker=None, text="some text") ]], # foo.vhd is on the build sequence, check that diagnostics from # the build sequence are only included when their severity is # DiagType.ERROR str(path_to_foo): [[ CheckerDiagnostic( filename=path_to_foo, checker=None, text="should not be included", severity=DiagType.WARNING, ), CheckerDiagnostic( filename=path_to_foo, checker=None, text="style error should be included", severity=DiagType.STYLE_ERROR, ), CheckerDiagnostic( filename=path_to_foo, checker=None, text="should be included", severity=DiagType.ERROR, ), ]], } def build( # pylint: disable=unused-argument path, library, scope, forced=False): _logger.debug("Building library=%s, path=%s", library, path) path_diags = diags.get(str(path), []) if path_diags: return path_diags.pop(), [] return [], [] with patch.object(it.project.builder, "build", build): _logger.info("Project paths: %s", it.project.database._paths) messages = list(it.project.getMessagesByPath( entity_a.filename)) logIterable("Messages", messages, _logger.info) it.assertCountEqual( messages, [ LibraryShouldBeOmited( library="work", filename=entity_a.filename, column_number=8, line_number=0, ), PathNotInProjectFile(entity_a.filename), CheckerDiagnostic(filename=entity_a.filename, checker=None, text="some text"), CheckerDiagnostic( filename=path_to_foo, checker=None, text="style error should be included", severity=DiagType.STYLE_ERROR, ), CheckerDiagnostic( filename=path_to_foo, checker=None, text="should be included", severity=DiagType.ERROR, ), ], )