Extract scoping tests.

This commit is contained in:
chriseth 2018-03-16 00:47:12 +01:00
parent 6589555790
commit c9db105ad7
17 changed files with 130 additions and 223 deletions

View File

@ -43,229 +43,6 @@ namespace test
BOOST_FIXTURE_TEST_SUITE(SolidityNameAndTypeResolution, AnalysisFramework) BOOST_FIXTURE_TEST_SUITE(SolidityNameAndTypeResolution, AnalysisFramework)
BOOST_AUTO_TEST_CASE(double_function_declaration)
{
char const* text = R"(
contract test {
function fun() public { }
function fun() public { }
}
)";
CHECK_ERROR(text, DeclarationError, "Function with same name and arguments defined twice.");
}
BOOST_AUTO_TEST_CASE(double_variable_declaration_disjoint_scope)
{
string text = R"(
contract test {
function f() pure public {
{ uint x; }
{ uint x; }
}
}
)";
CHECK_ERROR(text, DeclarationError, "Identifier already declared");
}
BOOST_AUTO_TEST_CASE(double_variable_declaration_disjoint_scope_050)
{
string text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
{ uint x; }
{ uint x; }
}
}
)";
CHECK_WARNING_ALLOW_MULTI(text, (vector<string>{
"Unused local variable",
"Unused local variable"
}));
}
BOOST_AUTO_TEST_CASE(double_variable_declaration_disjoint_scope_activation)
{
string text = R"(
contract test {
function f() pure public {
{ uint x; }
uint x;
}
}
)";
CHECK_ERROR(text, DeclarationError, "Identifier already declared");
}
BOOST_AUTO_TEST_CASE(double_variable_declaration_disjoint_scope_activation_050)
{
string text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
{ uint x; }
uint x;
}
}
)";
CHECK_WARNING_ALLOW_MULTI(text, (vector<string>{
"Unused local variable",
"Unused local variable"
}));
}
BOOST_AUTO_TEST_CASE(scoping_old)
{
char const* text = R"(
contract test {
function f() pure public {
x = 4;
uint256 x = 2;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(scoping)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() public {
{
uint256 x;
}
x = 2;
}
}
)";
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(scoping_activation_old)
{
char const* text = R"(
contract test {
function f() pure public {
x = 3;
uint x;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(scoping_activation)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
x = 3;
uint x;
}
}
)";
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(scoping_self_use)
{
char const* text = R"(
contract test {
function f() pure public {
uint a = a;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(scoping_self_use_050)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
uint a = a;
}
}
)";
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(scoping_for)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (uint x = 0; x < 10; x ++){
x = 2;
}
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(scoping_for2)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (uint x = 0; x < 10; x ++)
x = 2;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(scoping_for3)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (uint x = 0; x < 10; x ++){
x = 2;
}
x = 4;
}
}
)";
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(scoping_for_decl_in_body)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (;; y++){
uint y = 3;
}
}
}
)";
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(name_shadowing)
{
char const* text = R"(
contract test {
uint256 variable;
function f() public { uint32 variable; variable = 2; }
}
)";
CHECK_SUCCESS(text);
}
BOOST_AUTO_TEST_CASE(name_references) BOOST_AUTO_TEST_CASE(name_references)
{ {
char const* text = R"( char const* text = R"(

View File

@ -0,0 +1,6 @@
contract test {
function fun() public { }
function fun() public { }
}
// ----
// DeclarationError: Function with same name and arguments defined twice.

View File

@ -0,0 +1,8 @@
contract test {
function f() pure public {
{ uint x; }
{ uint x; }
}
}
// ----
// DeclarationError: Identifier already declared.

View File

@ -0,0 +1,10 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
{ uint x; }
{ uint x; }
}
}
// ----
// Warning: Unused local variable.
// Warning: Unused local variable.

View File

@ -0,0 +1,8 @@
contract test {
function f() pure public {
{ uint x; }
uint x;
}
}
// ----
// DeclarationError: Identifier already declared.

View File

@ -0,0 +1,10 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
{ uint x; }
uint x;
}
}
// ----
// Warning: Unused local variable.
// Warning: Unused local variable.

View File

@ -0,0 +1,7 @@
contract test {
uint256 variable;
function f() pure public { uint32 variable; variable = 2; }
}
// ----
// Warning: This declaration shadows an existing declaration.

View File

@ -0,0 +1,11 @@
pragma experimental "v0.5.0";
contract test {
function f() public {
{
uint256 x;
}
x = 2;
}
}
// ----
// DeclarationError: Undeclared identifier.

View File

@ -0,0 +1,9 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
x = 3;
uint x;
}
}
// ----
// DeclarationError: Undeclared identifier. Did you mean "x"?

View File

@ -0,0 +1,6 @@
contract test {
function f() pure public {
x = 3;
uint x;
}
}

View File

@ -0,0 +1,8 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (uint x = 0; x < 10; x ++){
x = 2;
}
}
}

View File

@ -0,0 +1,7 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (uint x = 0; x < 10; x ++)
x = 2;
}
}

View File

@ -0,0 +1,11 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (uint x = 0; x < 10; x ++){
x = 2;
}
x = 4;
}
}
// ----
// DeclarationError: Undeclared identifier.

View File

@ -0,0 +1,10 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (;; y++){
uint y = 3;
}
}
}
// ----
// DeclarationError: Undeclared identifier.

View File

@ -0,0 +1,6 @@
contract test {
function f() pure public {
x = 4;
uint256 x = 2;
}
}

View File

@ -0,0 +1,5 @@
contract test {
function f() pure public {
uint a = a;
}
}

View File

@ -0,0 +1,8 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
uint a = a;
}
}
// ----
// DeclarationError: Undeclared identifier. Did you mean "a"?