aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-03-27 21:23:36 +0800
committerGitHub <noreply@github.com>2018-03-27 21:23:36 +0800
commitaf26228159d6fbf3240291d356878505ba42e33a (patch)
tree4c7123c939d6674ca741382aa9698df1031593c6 /test/libsolidity
parent32f08989dbacb7d839ebc916ac995ecc08eee6eb (diff)
parentc9db105ad7c8cb4913d0e0ed859ce4808aae288a (diff)
downloaddexon-solidity-af26228159d6fbf3240291d356878505ba42e33a.tar.gz
dexon-solidity-af26228159d6fbf3240291d356878505ba42e33a.tar.zst
dexon-solidity-af26228159d6fbf3240291d356878505ba42e33a.zip
Merge pull request #3748 from ethereum/extractScopingTests
Extract scoping tests
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp223
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_function_declaration.sol6
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol8
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol10
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol8
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol10
-rw-r--r--test/libsolidity/syntaxTests/scoping/name_shadowing.sol7
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping.sol11
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_activation.sol9
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_activation_old.sol6
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_for.sol8
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_for2.sol7
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_for3.sol11
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol10
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_old.sol6
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_self_use.sol5
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol8
17 files changed, 130 insertions, 223 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index e4e7b8d8..565168a2 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -43,229 +43,6 @@ namespace test
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)
{
char const* text = R"(
diff --git a/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol b/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol
new file mode 100644
index 00000000..2841fd38
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol
@@ -0,0 +1,6 @@
+contract test {
+ function fun() public { }
+ function fun() public { }
+}
+// ----
+// DeclarationError: Function with same name and arguments defined twice.
diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol
new file mode 100644
index 00000000..ea61d0f3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol
@@ -0,0 +1,8 @@
+contract test {
+ function f() pure public {
+ { uint x; }
+ { uint x; }
+ }
+}
+// ----
+// DeclarationError: Identifier already declared.
diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol
new file mode 100644
index 00000000..22195963
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol
new file mode 100644
index 00000000..6af89c93
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol
@@ -0,0 +1,8 @@
+contract test {
+ function f() pure public {
+ { uint x; }
+ uint x;
+ }
+}
+// ----
+// DeclarationError: Identifier already declared.
diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol
new file mode 100644
index 00000000..73cddfed
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/scoping/name_shadowing.sol b/test/libsolidity/syntaxTests/scoping/name_shadowing.sol
new file mode 100644
index 00000000..d16877f9
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/name_shadowing.sol
@@ -0,0 +1,7 @@
+contract test {
+ uint256 variable;
+ function f() pure public { uint32 variable; variable = 2; }
+}
+// ----
+// Warning: This declaration shadows an existing declaration.
+
diff --git a/test/libsolidity/syntaxTests/scoping/scoping.sol b/test/libsolidity/syntaxTests/scoping/scoping.sol
new file mode 100644
index 00000000..f47a3e99
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping.sol
@@ -0,0 +1,11 @@
+pragma experimental "v0.5.0";
+contract test {
+ function f() public {
+ {
+ uint256 x;
+ }
+ x = 2;
+ }
+}
+// ----
+// DeclarationError: Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_activation.sol b/test/libsolidity/syntaxTests/scoping/scoping_activation.sol
new file mode 100644
index 00000000..0ed74a00
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping_activation.sol
@@ -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"?
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_activation_old.sol b/test/libsolidity/syntaxTests/scoping/scoping_activation_old.sol
new file mode 100644
index 00000000..d893a889
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping_activation_old.sol
@@ -0,0 +1,6 @@
+contract test {
+ function f() pure public {
+ x = 3;
+ uint x;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for.sol b/test/libsolidity/syntaxTests/scoping/scoping_for.sol
new file mode 100644
index 00000000..6e5b7095
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping_for.sol
@@ -0,0 +1,8 @@
+pragma experimental "v0.5.0";
+contract test {
+ function f() pure public {
+ for (uint x = 0; x < 10; x ++){
+ x = 2;
+ }
+ }
+}
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for2.sol b/test/libsolidity/syntaxTests/scoping/scoping_for2.sol
new file mode 100644
index 00000000..eb74b8ab
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping_for2.sol
@@ -0,0 +1,7 @@
+pragma experimental "v0.5.0";
+contract test {
+ function f() pure public {
+ for (uint x = 0; x < 10; x ++)
+ x = 2;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for3.sol b/test/libsolidity/syntaxTests/scoping/scoping_for3.sol
new file mode 100644
index 00000000..9bc7d569
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping_for3.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol b/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol
new file mode 100644
index 00000000..07503983
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol
@@ -0,0 +1,10 @@
+pragma experimental "v0.5.0";
+contract test {
+ function f() pure public {
+ for (;; y++){
+ uint y = 3;
+ }
+ }
+}
+// ----
+// DeclarationError: Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_old.sol b/test/libsolidity/syntaxTests/scoping/scoping_old.sol
new file mode 100644
index 00000000..83f6b60b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping_old.sol
@@ -0,0 +1,6 @@
+contract test {
+ function f() pure public {
+ x = 4;
+ uint256 x = 2;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_self_use.sol b/test/libsolidity/syntaxTests/scoping/scoping_self_use.sol
new file mode 100644
index 00000000..9e2c0171
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping_self_use.sol
@@ -0,0 +1,5 @@
+contract test {
+ function f() pure public {
+ uint a = a;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol b/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol
new file mode 100644
index 00000000..e942020e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol
@@ -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"?