lsp: Adding test for custom include paths.

This commit is contained in:
Christian Parpart 2022-07-11 13:30:04 +02:00
parent 31227e442e
commit d89008da0a
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import "otherlib/otherlib.sol";
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @NotFound
contract MyContract
{
}
// ----
// using-custom-includes: @NotFound 6275

View File

@ -0,0 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
library OtherLib
{
function f(uint n) public returns (uint) { return n + 1; }
}

View File

@ -1381,6 +1381,34 @@ class SolidityLSPTestSuite: # {{{
return markers
def test_custom_includes(self, solc: JsonRpcProcess) -> None:
self.setup_lsp(solc, expose_project_root=False)
solc.send_notification(
'workspace/didChangeConfiguration', {
'settings': {
'include-paths': [
f"{self.project_root_dir}/other-include-dir"
]
}
}
)
published_diagnostics = self.open_file_and_wait_for_diagnostics(solc, 'include-paths/using-custom-includes')
self.expect_equal(len(published_diagnostics), 2, "Diagnostic reports for 2 files")
# test file
report = published_diagnostics[0]
self.expect_equal(report['uri'], self.get_test_file_uri('using-custom-includes', 'include-paths'))
diagnostics = report['diagnostics']
self.expect_equal(len(diagnostics), 0, "no diagnostics")
# imported file
report = published_diagnostics[1]
self.expect_equal(report['uri'], f"{self.project_root_uri}/other-include-dir/otherlib/otherlib.sol")
diagnostics = report['diagnostics']
self.expect_equal(len(diagnostics), 1, "no diagnostics")
self.expect_diagnostic(diagnostics[0], code=2018, lineNo=5, startEndColumns=(4, 62))
def test_didChange_in_A_causing_error_in_B(self, solc: JsonRpcProcess) -> None:
# Reusing another test but now change some file that generates an error in the other.
self.test_textDocument_didOpen_with_relative_import(solc)