mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Improve Error Reporting of SemVer Parser
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <liblangutil/SemVerHandler.h>
|
||||
#include <test/Common.h>
|
||||
#include <test/libsolidity/util/SoltestErrors.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
@@ -58,17 +59,41 @@ SemVerMatchExpression parseExpression(string const& _input)
|
||||
scanner.next();
|
||||
}
|
||||
|
||||
auto expression = SemVerMatchExpressionParser(tokens, literals).parse();
|
||||
BOOST_REQUIRE(expression.has_value());
|
||||
BOOST_CHECK_MESSAGE(
|
||||
expression->isValid(),
|
||||
"Expression \"" + _input + "\" did not parse properly."
|
||||
);
|
||||
return *expression;
|
||||
try
|
||||
{
|
||||
auto matchExpression = SemVerMatchExpressionParser(tokens, literals).parse();
|
||||
|
||||
BOOST_CHECK_MESSAGE(
|
||||
matchExpression.isValid(),
|
||||
"Expression \"" + _input + "\" did not parse properly."
|
||||
);
|
||||
|
||||
return matchExpression;
|
||||
}
|
||||
catch (SemVerError const&)
|
||||
{
|
||||
// Ignored, since a test case should have a parsable version
|
||||
soltestAssert(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exception_on_invalid_version_in_semverversion_constructor)
|
||||
{
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
SemVerVersion version("1.2"),
|
||||
SemVerError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == "Invalid versionString: 1.2"); return true; }
|
||||
);
|
||||
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
SemVerVersion version("-1.2.0"),
|
||||
SemVerError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == "Invalid versionString: -1.2.0"); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(positive_range)
|
||||
{
|
||||
// Positive range tests
|
||||
@@ -159,9 +184,9 @@ BOOST_AUTO_TEST_CASE(positive_range)
|
||||
for (auto const& t: tests)
|
||||
{
|
||||
SemVerVersion version(t.second);
|
||||
SemVerMatchExpression expression = parseExpression(t.first);
|
||||
SemVerMatchExpression matchExpression = parseExpression(t.first);
|
||||
BOOST_CHECK_MESSAGE(
|
||||
expression.matches(version),
|
||||
matchExpression.matches(version),
|
||||
"Version \"" + t.second + "\" did not satisfy expression \"" + t.first + "\""
|
||||
);
|
||||
}
|
||||
@@ -235,9 +260,9 @@ BOOST_AUTO_TEST_CASE(negative_range)
|
||||
for (auto const& t: tests)
|
||||
{
|
||||
SemVerVersion version(t.second);
|
||||
SemVerMatchExpression expression = parseExpression(t.first);
|
||||
auto matchExpression = parseExpression(t.first);
|
||||
BOOST_CHECK_MESSAGE(
|
||||
!expression.matches(version),
|
||||
!matchExpression.matches(version),
|
||||
"Version \"" + t.second + "\" did satisfy expression \"" + t.first + "\" " +
|
||||
"(although it should not)"
|
||||
);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
pragma solidity ;
|
||||
// ----
|
||||
// ParserError 1684: (0-17): Invalid version pragma. Empty version pragma.
|
||||
@@ -1,3 +1,3 @@
|
||||
pragma solidity pragma;
|
||||
// ----
|
||||
// ParserError 1684: (0-23): Found version pragma, but failed to parse it. Please ensure there is a trailing semicolon.
|
||||
// ParserError 1684: (0-23): Invalid version pragma. Expected the start of a version number but instead found character 'p'. Version number is invalid or the pragma is not terminated with a semicolon.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
pragma solidity (8.0.0);
|
||||
// ----
|
||||
// ParserError 1684: (0-24): Found version pragma, but failed to parse it. Please ensure there is a trailing semicolon.
|
||||
// ParserError 1684: (0-24): Invalid version pragma. Expected the start of a version number but instead found character '('. Version number is invalid or the pragma is not terminated with a semicolon.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
pragma solidity 88_;
|
||||
// ----
|
||||
// ParserError 1684: (0-20): Found version pragma, but failed to parse it. Please ensure there is a trailing semicolon.
|
||||
// ParserError 1684: (0-20): Invalid version pragma. Expected the start of a version number but instead found character '_'. Version number is invalid or the pragma is not terminated with a semicolon.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
pragma solidity v1.2.3;
|
||||
// ----
|
||||
// ParserError 1684: (0-23): Found version pragma, but failed to parse it. Please ensure there is a trailing semicolon.
|
||||
// ParserError 1684: (0-23): Invalid version pragma. Expected the start of a version number but instead found character 'v'. Version number is invalid or the pragma is not terminated with a semicolon.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
pragma solidity >0.5.0<;
|
||||
// ----
|
||||
// ParserError 1684: (0-24): Found version pragma, but failed to parse it. Please ensure there is a trailing semicolon.
|
||||
// ParserError 1684: (0-24): Invalid version pragma. Expected version number but reached end of pragma.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
pragma solidity;
|
||||
// ----
|
||||
// ParserError 1684: (0-16): Found version pragma, but failed to parse it. Please ensure there is a trailing semicolon.
|
||||
// ParserError 1684: (0-16): Invalid version pragma. Empty version pragma.
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
pragma solidity 0.4.1 - 0.6.2 0.8.17;
|
||||
// ----
|
||||
// ParserError 1684: (0-37): Invalid version pragma. You can only combine version ranges using the || operator.
|
||||
@@ -0,0 +1,3 @@
|
||||
pragma solidity 0.8.17 0.4.1 - 0.6.2;
|
||||
// ----
|
||||
// ParserError 1684: (0-37): Invalid version pragma. Expected the start of a version number but instead found character '-'. Version number is invalid or the pragma is not terminated with a semicolon.
|
||||
@@ -0,0 +1,3 @@
|
||||
pragma solidity 0.4.0 - 0.4.1 0.4.1 - 0.6.2;
|
||||
// ----
|
||||
// ParserError 1684: (0-44): Invalid version pragma. You can only combine version ranges using the || operator.
|
||||
@@ -1,4 +1,4 @@
|
||||
pragma solidity 0.4.3
|
||||
pragma abicoder v2;
|
||||
// ----
|
||||
// ParserError 1684: (0-41): Found version pragma, but failed to parse it. Please ensure there is a trailing semicolon.
|
||||
// ParserError 1684: (0-41): Invalid version pragma. Expected the start of a version number but instead found character 'p'. Version number is invalid or the pragma is not terminated with a semicolon.
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
pragma solidity 0.8.17 || 0.4.1 - 0.9.0;
|
||||
// ----
|
||||
@@ -0,0 +1,2 @@
|
||||
pragma solidity 0.4.0 - 0.9.0 || 0.4.1 - 0.6.2;
|
||||
// ----
|
||||
@@ -0,0 +1,3 @@
|
||||
pragma solidity 4294967296;
|
||||
// ----
|
||||
// ParserError 1684: (0-27): Invalid version pragma. Integer too large to be used in a version number.
|
||||
Reference in New Issue
Block a user