diff options
Diffstat (limited to 'test/libsolidity/Imports.cpp')
-rw-r--r-- | test/libsolidity/Imports.cpp | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index 6aa96fb8..00f093b7 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -20,11 +20,15 @@ * Tests for high level features like import. */ -#include <string> -#include <boost/test/unit_test.hpp> +#include <test/libsolidity/ErrorCheck.h> + #include <libsolidity/interface/Exceptions.h> #include <libsolidity/interface/CompilerStack.h> +#include <boost/test/unit_test.hpp> + +#include <string> + using namespace std; namespace dev @@ -202,6 +206,67 @@ BOOST_AUTO_TEST_CASE(context_dependent_remappings_order_independent) BOOST_CHECK(d.compile()); } +BOOST_AUTO_TEST_CASE(shadowing_via_import) +{ + CompilerStack c; + c.addSource("a", "library A {} pragma solidity >=0.0;"); + c.addSource("b", "library A {} pragma solidity >=0.0;"); + c.addSource("c", "import {A} from \"./a\"; import {A} from \"./b\";"); + BOOST_CHECK(!c.compile()); +} + +BOOST_AUTO_TEST_CASE(shadowing_builtins_with_imports) +{ + CompilerStack c; + c.addSource("B.sol", "contract X {} pragma solidity >=0.0;"); + c.addSource("b", R"( + pragma solidity >=0.0; + import * as msg from "B.sol"; + contract C { + } + )"); + BOOST_CHECK(c.compile()); + auto numErrors = c.errors().size(); + // Sometimes we get the prerelease warning, sometimes not. + BOOST_CHECK(2 <= numErrors && numErrors <= 3); + for (auto const& e: c.errors()) + { + string const* msg = e->comment(); + BOOST_REQUIRE(msg); + BOOST_CHECK( + msg->find("pre-release") != string::npos || + msg->find("shadows a builtin symbol") != string::npos + ); + } +} + +BOOST_AUTO_TEST_CASE(shadowing_builtins_with_multiple_imports) +{ + CompilerStack c; + c.addSource("B.sol", "contract msg {} contract block{} pragma solidity >=0.0;"); + c.addSource("b", R"( + pragma solidity >=0.0; + import {msg, block} from "B.sol"; + contract C { + } + )"); + BOOST_CHECK(c.compile()); + auto numErrors = c.errors().size(); + // Sometimes we get the prerelease warning, sometimes not. + BOOST_CHECK(4 <= numErrors && numErrors <= 5); + for (auto const& e: c.errors()) + { + string const* msg = e->comment(); + BOOST_REQUIRE(msg); + BOOST_CHECK( + msg->find("pre-release") != string::npos || + msg->find("shadows a builtin symbol") != string::npos + ); + } +} + + + BOOST_AUTO_TEST_SUITE_END() } |