Extract tests.

This commit is contained in:
chriseth 2018-05-04 16:10:25 +02:00 committed by Alex Beregszaszi
parent fe12f05c08
commit 07e862a145
6 changed files with 47 additions and 74 deletions

View File

@ -5833,80 +5833,6 @@ BOOST_AUTO_TEST_CASE(pure_statement_check_for_regular_for_loop)
CHECK_SUCCESS(text); CHECK_SUCCESS(text);
} }
BOOST_AUTO_TEST_CASE(warn_multiple_storage_storage_copies)
{
char const* text = R"(
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() public {
(x, y) = (y, x);
}
}
)";
CHECK_WARNING(text, "This assignment performs two copies to storage.");
}
BOOST_AUTO_TEST_CASE(warn_multiple_storage_storage_copies_fill_right)
{
char const* text = R"(
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() public {
(x, y, ) = (y, x, 1, 2);
}
}
)";
CHECK_WARNING(text, "This assignment performs two copies to storage.");
}
BOOST_AUTO_TEST_CASE(warn_multiple_storage_storage_copies_fill_left)
{
char const* text = R"(
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() public {
(,x, y) = (1, 2, y, x);
}
}
)";
CHECK_WARNING(text, "This assignment performs two copies to storage.");
}
BOOST_AUTO_TEST_CASE(nowarn_swap_memory)
{
char const* text = R"(
contract C {
struct S { uint a; uint b; }
function f() pure public {
S memory x;
S memory y;
(x, y) = (y, x);
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(nowarn_swap_storage_pointers)
{
char const* text = R"(
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() public {
S storage x_local = x;
S storage y_local = y;
S storage z_local = x;
(x, y_local, x_local, z_local) = (y, x_local, y_local, y);
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(warn_unused_local) BOOST_AUTO_TEST_CASE(warn_unused_local)
{ {
char const* text = R"( char const* text = R"(

View File

@ -0,0 +1,8 @@
contract C {
struct S { uint a; uint b; }
function f() pure public {
S memory x;
S memory y;
(x, y) = (y, x);
}
}

View File

@ -0,0 +1,10 @@
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() public {
S storage x_local = x;
S storage y_local = y;
S storage z_local = x;
(x, y_local, x_local, z_local) = (y, x_local, y_local, y);
}
}

View File

@ -0,0 +1,9 @@
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() public {
(x, y) = (y, x);
}
}
// ----
// Warning: (79-94): This assignment performs two copies to storage. Since storage copies do not first copy to a temporary location, one of them might be overwritten before the second is executed and thus may have unexpected effects. It is safer to perform the copies separately or assign to storage pointers first.

View File

@ -0,0 +1,10 @@
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() public {
(,x, y) = (1, 2, y, x);
}
}
// ----
// Warning: (79-101): This assignment performs two copies to storage. Since storage copies do not first copy to a temporary location, one of them might be overwritten before the second is executed and thus may have unexpected effects. It is safer to perform the copies separately or assign to storage pointers first.
// Warning: (79-101): Different number of components on the left hand side (3) than on the right hand side (4).

View File

@ -0,0 +1,10 @@
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() public {
(x, y, ) = (y, x, 1, 2);
}
}
// ----
// Warning: (79-102): This assignment performs two copies to storage. Since storage copies do not first copy to a temporary location, one of them might be overwritten before the second is executed and thus may have unexpected effects. It is safer to perform the copies separately or assign to storage pointers first.
// Warning: (79-102): Different number of components on the left hand side (3) than on the right hand side (4).