SyntaxTest::filterObtainedErrors(): Remove hard-coded preamble to match changes in setupCompiler()

This commit is contained in:
Kamil Śliwak 2021-01-15 14:45:53 +01:00
parent 6f1f0c5bbc
commit 5677211471
2 changed files with 27 additions and 7 deletions

View File

@ -113,20 +113,30 @@ void SyntaxTest::parseAndAnalyze()
void SyntaxTest::filterObtainedErrors()
{
string const preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n";
for (auto const& currentError: filterErrors(compiler().errors(), true))
{
int locationStart = -1, locationEnd = -1;
string sourceName;
if (auto location = boost::get_error_info<errinfo_sourceLocation>(*currentError))
{
solAssert(location->source, "");
sourceName = location->source->name();
solAssert(m_sources.count(sourceName) == 1, "");
int preambleSize = static_cast<int>(location->source->source().size()) - static_cast<int>(m_sources[sourceName].size());
solAssert(preambleSize >= 0, "");
// ignore the version & license pragma inserted by the testing tool when calculating locations.
if (location->start >= static_cast<int>(preamble.size()))
locationStart = location->start - static_cast<int>(preamble.size());
if (location->end >= static_cast<int>(preamble.size()))
locationEnd = location->end - static_cast<int>(preamble.size());
if (location->source)
sourceName = location->source->name();
if (location->start != -1)
{
solAssert(location->start >= preambleSize, "");
locationStart = location->start - preambleSize;
}
if (location->end != -1)
{
solAssert(location->end >= preambleSize, "");
locationEnd = location->end - preambleSize;
}
}
m_errorList.emplace_back(SyntaxTestError{
currentError->typeName(),

View File

@ -0,0 +1,10 @@
import "~~~some-long-unlikely-file-name-12";
import "~~~some-long-unlikely-file-name-456";
import "~~~some-long-unlikely-file-name-7890";
// This test is here to verify that the license/pragma preamble added by the test suite does not
// affect source locations in error messages. Positions in messages below should start at 0 and
// there should be no gaps between the ranges.
// ----
// ParserError 6275: (0-44): Source "~~~some-long-unlikely-file-name-12" not found: File not supplied initially.
// ParserError 6275: (45-90): Source "~~~some-long-unlikely-file-name-456" not found: File not supplied initially.
// ParserError 6275: (91-137): Source "~~~some-long-unlikely-file-name-7890" not found: File not supplied initially.