Esempio n. 1
0
        def test():
            it.project.database._clearLruCaches()
            filename = p.join(TEST_PROJECT, "basic_library",
                              "clk_en_generator.vhd")
            rebuilds = [[
                _RebuildLibraryUnit(name="clock_divider",
                                    library="basic_library")
            ]]

            logIterable("Design units", it.project.database.design_units,
                        _logger.info)
            calls = basicRebuildTest(filename, rebuilds)

            # Calls should be
            # - first to build the source we wanted
            # - second to build the file we said needed to be rebuilt
            # - third should build the original source after handling a rebuild
            it.assertEqual(
                calls,
                [
                    p.join(TEST_PROJECT, "basic_library",
                           "clk_en_generator.vhd"),
                    p.join(TEST_PROJECT, "basic_library", "clock_divider.vhd"),
                    p.join(TEST_PROJECT, "basic_library",
                           "clk_en_generator.vhd"),
                ],
            )
Esempio n. 2
0
    def test(parse_builtins):
        # type: (...) -> None
        root = tempfile.mkdtemp()
        server = DummyServer(Path(root))

        with tempfile.NamedTemporaryFile(suffix=".vhd") as filename:
            diags = server.getMessagesWithText(
                Path(filename.name),
                "library lib; use lib.pkg.all; library builtin; use builtin.foo;",
            )

            parse_builtins.assert_called()

            logIterable("Diags", diags, _logger.info)

            it.assertCountEqual(
                diags,
                [
                    UnresolvedDependency(
                        RequiredDesignUnit(
                            name=Identifier("pkg"),
                            library=Identifier("lib"),
                            owner=Path(filename.name),
                            locations=[Location(0, 17)],
                        ),
                        Location(0, 17),
                    )
                ],
            )
Esempio n. 3
0
        def test():
            it.assertTrue(it.project.database.paths)

            filename = Path(p.join(TEST_PROJECT, "another_library", "foo.vhd"))
            original_content = open(filename.name, "r").read().split("\n")

            content = "\n".join(original_content[:28] +
                                ["signal another_signal : std_logic;"] +
                                original_content[28:])

            _logger.debug("File content")
            for lnum, line in enumerate(content.split("\n")):
                _logger.debug("%2d| %s", (lnum + 1), line)

            diagnostics = set(it.project.getMessagesWithText(
                filename, content))

            logIterable("Diagnostics", diagnostics, _logger.info)

            it.assertTrue(it.project.config_file)

            expected = [
                ObjectIsNeverUsed(
                    filename=filename,
                    line_number=29,
                    column_number=11,
                    object_type="signal",
                    object_name="neat_signal",
                ),
                ObjectIsNeverUsed(
                    filename=filename,
                    line_number=28,
                    column_number=7,
                    object_type="signal",
                    object_name="another_signal",
                ),
            ]

            it.assertCountEqual(diagnostics, expected)
Esempio n. 4
0
        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,
                        ),
                    ],
                )