Purge using namespace std from previously missed files

This commit is contained in:
Nikola Matic 2023-10-02 14:37:55 +02:00
parent 77912ab35d
commit 0d0a7fc1f5
5 changed files with 94 additions and 97 deletions

View File

@ -29,11 +29,11 @@
#include <vector> #include <vector>
using namespace std;
using namespace solidity::frontend::test; using namespace solidity::frontend::test;
using namespace solidity::util; using namespace solidity::util;
using namespace std::string_literals;
ostream& solidity::frontend::test::operator<<(ostream& _output, NatspecJSONKind _kind) std::ostream& solidity::frontend::test::operator<<(std::ostream& _output, NatspecJSONKind _kind)
{ {
switch (_kind) { switch (_kind) {
case NatspecJSONKind::Devdoc: _output << "devdoc"; break; case NatspecJSONKind::Devdoc: _output << "devdoc"; break;
@ -42,12 +42,12 @@ ostream& solidity::frontend::test::operator<<(ostream& _output, NatspecJSONKind
return _output; return _output;
} }
unique_ptr<TestCase> NatspecJSONTest::create(Config const& _config) std::unique_ptr<TestCase> NatspecJSONTest::create(Config const& _config)
{ {
return make_unique<NatspecJSONTest>(_config.filename, _config.evmVersion); return std::make_unique<NatspecJSONTest>(_config.filename, _config.evmVersion);
} }
void NatspecJSONTest::parseCustomExpectations(istream& _stream) void NatspecJSONTest::parseCustomExpectations(std::istream& _stream)
{ {
soltestAssert(m_expectedNatspecJSON.empty()); soltestAssert(m_expectedNatspecJSON.empty());
@ -56,21 +56,21 @@ void NatspecJSONTest::parseCustomExpectations(istream& _stream)
// // <qualified contract name> <devdoc|userdoc> // // <qualified contract name> <devdoc|userdoc>
// // <json> // // <json>
string line; std::string line;
while (getline(_stream, line)) while (getline(_stream, line))
{ {
string_view strippedLine = expectLinePrefix(line); std::string_view strippedLine = expectLinePrefix(line);
if (strippedLine.empty()) if (strippedLine.empty())
continue; continue;
auto [contractName, kind] = parseExpectationHeader(strippedLine); auto [contractName, kind] = parseExpectationHeader(strippedLine);
string rawJSON = extractExpectationJSON(_stream); std::string rawJSON = extractExpectationJSON(_stream);
string jsonErrors; std::string jsonErrors;
Json::Value parsedJSON; Json::Value parsedJSON;
bool jsonParsingSuccessful = jsonParseStrict(rawJSON, parsedJSON, &jsonErrors); bool jsonParsingSuccessful = jsonParseStrict(rawJSON, parsedJSON, &jsonErrors);
if (!jsonParsingSuccessful) if (!jsonParsingSuccessful)
BOOST_THROW_EXCEPTION(runtime_error(fmt::format( BOOST_THROW_EXCEPTION(std::runtime_error(fmt::format(
"Malformed JSON in {} expectation for contract {}.\n" "Malformed JSON in {} expectation for contract {}.\n"
"Note that JSON expectations must be pretty-printed to be split correctly. " "Note that JSON expectations must be pretty-printed to be split correctly. "
"The object is assumed to and at the first unindented closing brace.\n" "The object is assumed to and at the first unindented closing brace.\n"
@ -80,7 +80,7 @@ void NatspecJSONTest::parseCustomExpectations(istream& _stream)
rawJSON rawJSON
))); )));
m_expectedNatspecJSON[string(contractName)][kind] = parsedJSON; m_expectedNatspecJSON[std::string(contractName)][kind] = parsedJSON;
} }
} }
@ -94,51 +94,51 @@ bool NatspecJSONTest::expectationsMatch()
prettyPrinted(obtainedNatspec()) == prettyPrinted(m_expectedNatspecJSON); prettyPrinted(obtainedNatspec()) == prettyPrinted(m_expectedNatspecJSON);
} }
void NatspecJSONTest::printExpectedResult(ostream& _stream, string const& _linePrefix, bool _formatted) const void NatspecJSONTest::printExpectedResult(std::ostream& _stream, std::string const& _linePrefix, bool _formatted) const
{ {
SyntaxTest::printExpectedResult(_stream, _linePrefix, _formatted); SyntaxTest::printExpectedResult(_stream, _linePrefix, _formatted);
if (!m_expectedNatspecJSON.empty()) if (!m_expectedNatspecJSON.empty())
{ {
_stream << _linePrefix << "----" << endl; _stream << _linePrefix << "----" << std::endl;
printIndented(_stream, formatNatspecExpectations(m_expectedNatspecJSON), _linePrefix); printIndented(_stream, formatNatspecExpectations(m_expectedNatspecJSON), _linePrefix);
} }
} }
void NatspecJSONTest::printObtainedResult(ostream& _stream, string const& _linePrefix, bool _formatted) const void NatspecJSONTest::printObtainedResult(std::ostream& _stream, std::string const& _linePrefix, bool _formatted) const
{ {
SyntaxTest::printObtainedResult(_stream, _linePrefix, _formatted); SyntaxTest::printObtainedResult(_stream, _linePrefix, _formatted);
NatspecMap natspecJSON = obtainedNatspec(); NatspecMap natspecJSON = obtainedNatspec();
if (!natspecJSON.empty()) if (!natspecJSON.empty())
{ {
_stream << _linePrefix << "----" << endl; _stream << _linePrefix << "----" << std::endl;
// TODO: Diff both versions and highlight differences. // TODO: Diff both versions and highlight differences.
// We should have a helper for doing that in newly defined test cases without much effort. // We should have a helper for doing that in newly defined test cases without much effort.
printIndented(_stream, formatNatspecExpectations(natspecJSON), _linePrefix); printIndented(_stream, formatNatspecExpectations(natspecJSON), _linePrefix);
} }
} }
tuple<string_view, NatspecJSONKind> NatspecJSONTest::parseExpectationHeader(string_view _line) std::tuple<std::string_view, NatspecJSONKind> NatspecJSONTest::parseExpectationHeader(std::string_view _line)
{ {
for (NatspecJSONKind kind: {NatspecJSONKind::Devdoc, NatspecJSONKind::Userdoc}) for (NatspecJSONKind kind: {NatspecJSONKind::Devdoc, NatspecJSONKind::Userdoc})
{ {
string kindSuffix = " " + toString(kind); std::string kindSuffix = " " + toString(kind);
if (boost::algorithm::ends_with(_line, kindSuffix)) if (boost::algorithm::ends_with(_line, kindSuffix))
return {_line.substr(0, _line.size() - kindSuffix.size()), kind}; return {_line.substr(0, _line.size() - kindSuffix.size()), kind};
} }
BOOST_THROW_EXCEPTION(runtime_error( BOOST_THROW_EXCEPTION(std::runtime_error(
"Natspec kind (devdoc/userdoc) not present in the expectation: "s.append(_line) "Natspec kind (devdoc/userdoc) not present in the expectation: "s.append(_line)
)); ));
} }
string NatspecJSONTest::extractExpectationJSON(istream& _stream) std::string NatspecJSONTest::extractExpectationJSON(std::istream& _stream)
{ {
string rawJSON; std::string rawJSON;
string line; std::string line;
while (getline(_stream, line)) while (getline(_stream, line))
{ {
string_view strippedLine = expectLinePrefix(line); std::string_view strippedLine = expectLinePrefix(line);
rawJSON += strippedLine; rawJSON += strippedLine;
rawJSON += "\n"; rawJSON += "\n";
@ -149,11 +149,11 @@ string NatspecJSONTest::extractExpectationJSON(istream& _stream)
return rawJSON; return rawJSON;
} }
string_view NatspecJSONTest::expectLinePrefix(string_view _line) std::string_view NatspecJSONTest::expectLinePrefix(std::string_view _line)
{ {
size_t startPosition = 0; size_t startPosition = 0;
if (!boost::algorithm::starts_with(_line, "//")) if (!boost::algorithm::starts_with(_line, "//"))
BOOST_THROW_EXCEPTION(runtime_error( BOOST_THROW_EXCEPTION(std::runtime_error(
"Expectation line is not a comment: "s.append(_line) "Expectation line is not a comment: "s.append(_line)
)); ));
@ -164,9 +164,9 @@ string_view NatspecJSONTest::expectLinePrefix(string_view _line)
return _line.substr(startPosition, _line.size() - startPosition); return _line.substr(startPosition, _line.size() - startPosition);
} }
string NatspecJSONTest::formatNatspecExpectations(NatspecMap const& _expectations) const std::string NatspecJSONTest::formatNatspecExpectations(NatspecMap const& _expectations) const
{ {
string output; std::string output;
bool first = true; bool first = true;
// NOTE: Not sorting explicitly because CompilerStack seems to put contracts roughly in the // NOTE: Not sorting explicitly because CompilerStack seems to put contracts roughly in the
// order in which they appear in the source, which is much better than alphabetical order. // order in which they appear in the source, which is much better than alphabetical order.
@ -190,7 +190,7 @@ NatspecMap NatspecJSONTest::obtainedNatspec() const
return {}; return {};
NatspecMap result; NatspecMap result;
for (string contractName: compiler().contractNames()) for (std::string contractName: compiler().contractNames())
{ {
result[contractName][NatspecJSONKind::Devdoc] = compiler().natspecDev(contractName); result[contractName][NatspecJSONKind::Devdoc] = compiler().natspecDev(contractName);
result[contractName][NatspecJSONKind::Userdoc] = compiler().natspecUser(contractName); result[contractName][NatspecJSONKind::Userdoc] = compiler().natspecUser(contractName);

View File

@ -31,7 +31,6 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using namespace std;
using namespace solidity::langutil; using namespace solidity::langutil;
namespace solidity::frontend::test namespace solidity::frontend::test
@ -50,7 +49,7 @@ ASTPointer<ContractDefinition> parseText(std::string const& _source, ErrorList&
if (!sourceUnit) if (!sourceUnit)
return ASTPointer<ContractDefinition>(); return ASTPointer<ContractDefinition>();
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes()) for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
if (ASTPointer<ContractDefinition> contract = dynamic_pointer_cast<ContractDefinition>(node)) if (ASTPointer<ContractDefinition> contract = std::dynamic_pointer_cast<ContractDefinition>(node))
return contract; return contract;
BOOST_FAIL("No contract found in source."); BOOST_FAIL("No contract found in source.");
return ASTPointer<ContractDefinition>(); return ASTPointer<ContractDefinition>();
@ -525,7 +524,7 @@ BOOST_AUTO_TEST_CASE(keyword_is_reserved)
for (auto const& keyword: keywords) for (auto const& keyword: keywords)
{ {
auto text = std::string("contract ") + keyword + " {}"; auto text = std::string("contract ") + keyword + " {}";
CHECK_PARSE_ERROR(text.c_str(), string("Expected identifier but got reserved keyword '") + keyword + "'"); CHECK_PARSE_ERROR(text.c_str(), std::string("Expected identifier but got reserved keyword '") + keyword + "'");
} }
} }
@ -591,7 +590,7 @@ BOOST_AUTO_TEST_CASE(inline_asm_end_location)
class CheckInlineAsmLocation: public ASTConstVisitor class CheckInlineAsmLocation: public ASTConstVisitor
{ {
public: public:
explicit CheckInlineAsmLocation(string _sourceCode): m_sourceCode(_sourceCode) {} explicit CheckInlineAsmLocation(std::string _sourceCode): m_sourceCode(_sourceCode) {}
bool visited = false; bool visited = false;
bool visit(InlineAssembly const& _inlineAsm) override bool visit(InlineAssembly const& _inlineAsm) override
{ {
@ -602,7 +601,7 @@ BOOST_AUTO_TEST_CASE(inline_asm_end_location)
return false; return false;
} }
string m_sourceCode; std::string m_sourceCode;
}; };
CheckInlineAsmLocation visitor{sourceCode}; CheckInlineAsmLocation visitor{sourceCode};

View File

@ -27,7 +27,6 @@
#include <libsolutil/Keccak256.h> #include <libsolutil/Keccak256.h>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using namespace std;
using namespace solidity::langutil; using namespace solidity::langutil;
namespace solidity::frontend::test namespace solidity::frontend::test
@ -86,9 +85,9 @@ BOOST_AUTO_TEST_CASE(storage_layout_simple)
BOOST_REQUIRE(members.memberStorageOffset("first") != nullptr); BOOST_REQUIRE(members.memberStorageOffset("first") != nullptr);
BOOST_REQUIRE(members.memberStorageOffset("second") != nullptr); BOOST_REQUIRE(members.memberStorageOffset("second") != nullptr);
BOOST_REQUIRE(members.memberStorageOffset("wraps") != nullptr); BOOST_REQUIRE(members.memberStorageOffset("wraps") != nullptr);
BOOST_CHECK(*members.memberStorageOffset("first") == make_pair(u256(0), unsigned(0))); BOOST_CHECK(*members.memberStorageOffset("first") == std::make_pair(u256(0), unsigned(0)));
BOOST_CHECK(*members.memberStorageOffset("second") == make_pair(u256(0), unsigned(16))); BOOST_CHECK(*members.memberStorageOffset("second") == std::make_pair(u256(0), unsigned(16)));
BOOST_CHECK(*members.memberStorageOffset("wraps") == make_pair(u256(1), unsigned(0))); BOOST_CHECK(*members.memberStorageOffset("wraps") == std::make_pair(u256(1), unsigned(0)));
} }
BOOST_AUTO_TEST_CASE(storage_layout_mapping) BOOST_AUTO_TEST_CASE(storage_layout_mapping)
@ -114,10 +113,10 @@ BOOST_AUTO_TEST_CASE(storage_layout_mapping)
BOOST_REQUIRE(members.memberStorageOffset("second") != nullptr); BOOST_REQUIRE(members.memberStorageOffset("second") != nullptr);
BOOST_REQUIRE(members.memberStorageOffset("third") != nullptr); BOOST_REQUIRE(members.memberStorageOffset("third") != nullptr);
BOOST_REQUIRE(members.memberStorageOffset("final") != nullptr); BOOST_REQUIRE(members.memberStorageOffset("final") != nullptr);
BOOST_CHECK(*members.memberStorageOffset("first") == make_pair(u256(0), unsigned(0))); BOOST_CHECK(*members.memberStorageOffset("first") == std::make_pair(u256(0), unsigned(0)));
BOOST_CHECK(*members.memberStorageOffset("second") == make_pair(u256(1), unsigned(0))); BOOST_CHECK(*members.memberStorageOffset("second") == std::make_pair(u256(1), unsigned(0)));
BOOST_CHECK(*members.memberStorageOffset("third") == make_pair(u256(2), unsigned(0))); BOOST_CHECK(*members.memberStorageOffset("third") == std::make_pair(u256(2), unsigned(0)));
BOOST_CHECK(*members.memberStorageOffset("final") == make_pair(u256(3), unsigned(0))); BOOST_CHECK(*members.memberStorageOffset("final") == std::make_pair(u256(3), unsigned(0)));
} }
BOOST_AUTO_TEST_CASE(storage_layout_arrays) BOOST_AUTO_TEST_CASE(storage_layout_arrays)
@ -162,7 +161,7 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
BOOST_CHECK_EQUAL(RationalNumberType(rational(2 * 200, 2 * 77)).identifier(), "t_rational_200_by_77"); BOOST_CHECK_EQUAL(RationalNumberType(rational(2 * 200, 2 * 77)).identifier(), "t_rational_200_by_77");
BOOST_CHECK_EQUAL(RationalNumberType(rational(-2 * 200, 2 * 77)).identifier(), "t_rational_minus_200_by_77"); BOOST_CHECK_EQUAL(RationalNumberType(rational(-2 * 200, 2 * 77)).identifier(), "t_rational_minus_200_by_77");
BOOST_CHECK_EQUAL( BOOST_CHECK_EQUAL(
StringLiteralType(Literal(++id, SourceLocation{}, Token::StringLiteral, make_shared<string>("abc - def"))).identifier(), StringLiteralType(Literal(++id, SourceLocation{}, Token::StringLiteral, std::make_shared<std::string>("abc - def"))).identifier(),
"t_stringliteral_196a9142ee0d40e274a6482393c762b16dd8315713207365e1e13d8d85b74fc4" "t_stringliteral_196a9142ee0d40e274a6482393c762b16dd8315713207365e1e13d8d85b74fc4"
); );
BOOST_CHECK_EQUAL(TypeProvider::fromElementaryTypeName("bytes1")->identifier(), "t_bytes1"); BOOST_CHECK_EQUAL(TypeProvider::fromElementaryTypeName("bytes1")->identifier(), "t_bytes1");
@ -183,15 +182,15 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
Type const* multiArray = TypeProvider::array(DataLocation::Storage, stringArray); Type const* multiArray = TypeProvider::array(DataLocation::Storage, stringArray);
BOOST_CHECK_EQUAL(multiArray->identifier(), "t_array$_t_array$_t_string_storage_$20_storage_$dyn_storage_ptr"); BOOST_CHECK_EQUAL(multiArray->identifier(), "t_array$_t_array$_t_string_storage_$20_storage_$dyn_storage_ptr");
ContractDefinition c(++id, SourceLocation{}, make_shared<string>("MyContract$"), SourceLocation{}, {}, {}, {}, ContractKind::Contract); ContractDefinition c(++id, SourceLocation{}, std::make_shared<std::string>("MyContract$"), SourceLocation{}, {}, {}, {}, ContractKind::Contract);
BOOST_CHECK_EQUAL(c.type()->identifier(), "t_type$_t_contract$_MyContract$$$_$2_$"); BOOST_CHECK_EQUAL(c.type()->identifier(), "t_type$_t_contract$_MyContract$$$_$2_$");
BOOST_CHECK_EQUAL(ContractType(c, true).identifier(), "t_super$_MyContract$$$_$2"); BOOST_CHECK_EQUAL(ContractType(c, true).identifier(), "t_super$_MyContract$$$_$2");
StructDefinition s(++id, {}, make_shared<string>("Struct"), {}, {}, {}); StructDefinition s(++id, {}, std::make_shared<std::string>("Struct"), {}, {}, {});
s.annotation().recursive = false; s.annotation().recursive = false;
BOOST_CHECK_EQUAL(s.type()->identifier(), "t_type$_t_struct$_Struct_$3_storage_ptr_$"); BOOST_CHECK_EQUAL(s.type()->identifier(), "t_type$_t_struct$_Struct_$3_storage_ptr_$");
EnumDefinition e(++id, {}, make_shared<string>("Enum"), {}, {}, {}); EnumDefinition e(++id, {}, std::make_shared<std::string>("Enum"), {}, {}, {});
BOOST_CHECK_EQUAL(e.type()->identifier(), "t_type$_t_enum$_Enum_$4_$"); BOOST_CHECK_EQUAL(e.type()->identifier(), "t_type$_t_enum$_Enum_$4_$");
TupleType t({e.type(), s.type(), stringArray, nullptr}); TupleType t({e.type(), s.type(), stringArray, nullptr});
@ -209,8 +208,8 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
// TypeType is tested with contract // TypeType is tested with contract
auto emptyParams = make_shared<ParameterList>(++id, SourceLocation(), std::vector<ASTPointer<VariableDeclaration>>()); auto emptyParams = std::make_shared<ParameterList>(++id, SourceLocation(), std::vector<ASTPointer<VariableDeclaration>>());
ModifierDefinition mod(++id, SourceLocation{}, make_shared<string>("modif"), SourceLocation{}, {}, emptyParams, {}, {}, {}); ModifierDefinition mod(++id, SourceLocation{}, std::make_shared<std::string>("modif"), SourceLocation{}, {}, emptyParams, {}, {}, {});
BOOST_CHECK_EQUAL(ModifierType(mod).identifier(), "t_modifier$__$"); BOOST_CHECK_EQUAL(ModifierType(mod).identifier(), "t_modifier$__$");
SourceUnit su(++id, {}, {}, {}, {}); SourceUnit su(++id, {}, {}, {}, {});
@ -250,34 +249,34 @@ BOOST_AUTO_TEST_CASE(helper_bool_result)
{ {
BoolResult r1{true}; BoolResult r1{true};
BoolResult r2 = BoolResult::err("Failure."); BoolResult r2 = BoolResult::err("Failure.");
r1.merge(r2, logical_and<bool>()); r1.merge(r2, std::logical_and<bool>());
BOOST_REQUIRE_EQUAL(r1.get(), false); BOOST_REQUIRE_EQUAL(r1.get(), false);
BOOST_REQUIRE_EQUAL(r1.message(), "Failure."); BOOST_REQUIRE_EQUAL(r1.message(), "Failure.");
BoolResult r3{false}; BoolResult r3{false};
BoolResult r4{true}; BoolResult r4{true};
r3.merge(r4, logical_and<bool>()); r3.merge(r4, std::logical_and<bool>());
BOOST_REQUIRE_EQUAL(r3.get(), false); BOOST_REQUIRE_EQUAL(r3.get(), false);
BOOST_REQUIRE_EQUAL(r3.message(), ""); BOOST_REQUIRE_EQUAL(r3.message(), "");
BoolResult r5{true}; BoolResult r5{true};
BoolResult r6{true}; BoolResult r6{true};
r5.merge(r6, logical_and<bool>()); r5.merge(r6, std::logical_and<bool>());
BOOST_REQUIRE_EQUAL(r5.get(), true); BOOST_REQUIRE_EQUAL(r5.get(), true);
BOOST_REQUIRE_EQUAL(r5.message(), ""); BOOST_REQUIRE_EQUAL(r5.message(), "");
} }
BOOST_AUTO_TEST_CASE(helper_string_result) BOOST_AUTO_TEST_CASE(helper_string_result)
{ {
using StringResult = util::Result<string>; using StringResult = util::Result<std::string>;
StringResult r1{string{"Success"}}; StringResult r1{std::string{"Success"}};
StringResult r2 = StringResult::err("Failure"); StringResult r2 = StringResult::err("Failure");
BOOST_REQUIRE_EQUAL(r1.get(), "Success"); BOOST_REQUIRE_EQUAL(r1.get(), "Success");
BOOST_REQUIRE_EQUAL(r2.get(), ""); BOOST_REQUIRE_EQUAL(r2.get(), "");
r1.merge(r2, [](string const&, string const& _rhs) { return _rhs; }); r1.merge(r2, [](std::string const&, std::string const& _rhs) { return _rhs; });
BOOST_REQUIRE_EQUAL(r1.get(), ""); BOOST_REQUIRE_EQUAL(r1.get(), "");
BOOST_REQUIRE_EQUAL(r1.message(), "Failure"); BOOST_REQUIRE_EQUAL(r1.message(), "Failure");

View File

@ -32,8 +32,8 @@
#include <algorithm> #include <algorithm>
#include <set> #include <set>
using namespace std;
using namespace solidity::evmasm; using namespace solidity::evmasm;
using namespace std::string_literals;
namespace solidity::frontend::test namespace solidity::frontend::test
{ {
@ -41,9 +41,9 @@ namespace solidity::frontend::test
namespace namespace
{ {
langutil::Error::Severity str2Severity(string const& _cat) langutil::Error::Severity str2Severity(std::string const& _cat)
{ {
map<string, langutil::Error::Severity> cats{ std::map<std::string, langutil::Error::Severity> cats{
{"info", langutil::Error::Severity::Info}, {"info", langutil::Error::Severity::Info},
{"Info", langutil::Error::Severity::Info}, {"Info", langutil::Error::Severity::Info},
{"warning", langutil::Error::Severity::Warning}, {"warning", langutil::Error::Severity::Warning},
@ -55,7 +55,7 @@ langutil::Error::Severity str2Severity(string const& _cat)
} }
/// Helper to match a specific error type and message /// Helper to match a specific error type and message
bool containsError(Json::Value const& _compilerResult, string const& _type, string const& _message) bool containsError(Json::Value const& _compilerResult, std::string const& _type, std::string const& _message)
{ {
if (!_compilerResult.isMember("errors")) if (!_compilerResult.isMember("errors"))
return false; return false;
@ -88,7 +88,7 @@ bool containsAtMostWarnings(Json::Value const& _compilerResult)
return true; return true;
} }
Json::Value getContractResult(Json::Value const& _compilerResult, string const& _file, string const& _name) Json::Value getContractResult(Json::Value const& _compilerResult, std::string const& _file, std::string const& _name)
{ {
if ( if (
!_compilerResult["contracts"].isObject() || !_compilerResult["contracts"].isObject() ||
@ -107,10 +107,10 @@ void checkLinkReferencesSchema(Json::Value const& _contractResult)
Json::Value const& linkReferenceResult = _contractResult["evm"]["bytecode"]["linkReferences"]; Json::Value const& linkReferenceResult = _contractResult["evm"]["bytecode"]["linkReferences"];
BOOST_TEST_REQUIRE(linkReferenceResult.isObject()); BOOST_TEST_REQUIRE(linkReferenceResult.isObject());
for (string const& fileName: linkReferenceResult.getMemberNames()) for (std::string const& fileName: linkReferenceResult.getMemberNames())
{ {
BOOST_TEST_REQUIRE(linkReferenceResult[fileName].isObject()); BOOST_TEST_REQUIRE(linkReferenceResult[fileName].isObject());
for (string const& libraryName: linkReferenceResult[fileName].getMemberNames()) for (std::string const& libraryName: linkReferenceResult[fileName].getMemberNames())
{ {
BOOST_TEST_REQUIRE(linkReferenceResult[fileName][libraryName].isArray()); BOOST_TEST_REQUIRE(linkReferenceResult[fileName][libraryName].isArray());
BOOST_TEST_REQUIRE(!linkReferenceResult[fileName][libraryName].empty()); BOOST_TEST_REQUIRE(!linkReferenceResult[fileName][libraryName].empty());
@ -125,7 +125,7 @@ void checkLinkReferencesSchema(Json::Value const& _contractResult)
} }
} }
void expectLinkReferences(Json::Value const& _contractResult, map<string, set<string>> const& _expectedLinkReferences) void expectLinkReferences(Json::Value const& _contractResult, std::map<std::string, std::set<std::string>> const& _expectedLinkReferences)
{ {
checkLinkReferencesSchema(_contractResult); checkLinkReferencesSchema(_contractResult);
@ -136,15 +136,15 @@ void expectLinkReferences(Json::Value const& _contractResult, map<string, set<st
{ {
BOOST_TEST(linkReferenceResult.isMember(fileName)); BOOST_TEST(linkReferenceResult.isMember(fileName));
BOOST_TEST(linkReferenceResult[fileName].size() == libraries.size()); BOOST_TEST(linkReferenceResult[fileName].size() == libraries.size());
for (string const& libraryName: libraries) for (std::string const& libraryName: libraries)
BOOST_TEST(linkReferenceResult[fileName].isMember(libraryName)); BOOST_TEST(linkReferenceResult[fileName].isMember(libraryName));
} }
} }
Json::Value compile(string _input) Json::Value compile(std::string _input)
{ {
StandardCompiler compiler; StandardCompiler compiler;
string output = compiler.compile(std::move(_input)); std::string output = compiler.compile(std::move(_input));
Json::Value ret; Json::Value ret;
BOOST_REQUIRE(util::jsonParseStrict(output, ret)); BOOST_REQUIRE(util::jsonParseStrict(output, ret));
return ret; return ret;
@ -383,7 +383,7 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
BOOST_CHECK(contract["evm"]["bytecode"]["object"].isString()); BOOST_CHECK(contract["evm"]["bytecode"]["object"].isString());
BOOST_CHECK_EQUAL( BOOST_CHECK_EQUAL(
solidity::test::bytecodeSansMetadata(contract["evm"]["bytecode"]["object"].asString()), solidity::test::bytecodeSansMetadata(contract["evm"]["bytecode"]["object"].asString()),
string("6080604052348015600e575f80fd5b5060") + std::string("6080604052348015600e575f80fd5b5060") +
(VersionIsRelease ? "3e" : util::toHex(bytes{uint8_t(60 + VersionStringStrict.size())})) + (VersionIsRelease ? "3e" : util::toHex(bytes{uint8_t(60 + VersionStringStrict.size())})) +
"80601a5f395ff3fe60806040525f80fdfe" "80601a5f395ff3fe60806040525f80fdfe"
); );
@ -483,7 +483,7 @@ BOOST_AUTO_TEST_CASE(compilation_error)
{ {
BOOST_REQUIRE(error.isObject()); BOOST_REQUIRE(error.isObject());
BOOST_REQUIRE(error["message"].isString()); BOOST_REQUIRE(error["message"].isString());
if (error["message"].asString().find("pre-release compiler") == string::npos) if (error["message"].asString().find("pre-release compiler") == std::string::npos)
{ {
BOOST_CHECK_EQUAL( BOOST_CHECK_EQUAL(
util::jsonCompactPrint(error), util::jsonCompactPrint(error),
@ -1010,7 +1010,7 @@ BOOST_AUTO_TEST_CASE(linking_yul_same_library_name_different_files)
BOOST_AUTO_TEST_CASE(evm_version) BOOST_AUTO_TEST_CASE(evm_version)
{ {
auto inputForVersion = [](string const& _version) auto inputForVersion = [](std::string const& _version)
{ {
return R"( return R"(
{ {
@ -1029,30 +1029,30 @@ BOOST_AUTO_TEST_CASE(evm_version)
}; };
Json::Value result; Json::Value result;
result = compile(inputForVersion("\"evmVersion\": \"homestead\",")); result = compile(inputForVersion("\"evmVersion\": \"homestead\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"homestead\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"homestead\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"tangerineWhistle\",")); result = compile(inputForVersion("\"evmVersion\": \"tangerineWhistle\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"tangerineWhistle\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"tangerineWhistle\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"spuriousDragon\",")); result = compile(inputForVersion("\"evmVersion\": \"spuriousDragon\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"spuriousDragon\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"spuriousDragon\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"byzantium\",")); result = compile(inputForVersion("\"evmVersion\": \"byzantium\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"byzantium\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"byzantium\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"constantinople\",")); result = compile(inputForVersion("\"evmVersion\": \"constantinople\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"constantinople\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"constantinople\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"petersburg\",")); result = compile(inputForVersion("\"evmVersion\": \"petersburg\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"petersburg\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"petersburg\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"istanbul\",")); result = compile(inputForVersion("\"evmVersion\": \"istanbul\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"istanbul\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"istanbul\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"berlin\",")); result = compile(inputForVersion("\"evmVersion\": \"berlin\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"berlin\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"berlin\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"london\",")); result = compile(inputForVersion("\"evmVersion\": \"london\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"london\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"london\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"paris\",")); result = compile(inputForVersion("\"evmVersion\": \"paris\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"paris\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"paris\"") != std::string::npos);
result = compile(inputForVersion("\"evmVersion\": \"shanghai\",")); result = compile(inputForVersion("\"evmVersion\": \"shanghai\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"shanghai\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"shanghai\"") != std::string::npos);
// test default // test default
result = compile(inputForVersion("")); result = compile(inputForVersion(""));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"shanghai\"") != string::npos); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"shanghai\"") != std::string::npos);
// test invalid // test invalid
result = compile(inputForVersion("\"evmVersion\": \"invalid\",")); result = compile(inputForVersion("\"evmVersion\": \"invalid\","));
BOOST_CHECK(result["errors"][0]["message"].asString() == "Invalid EVM version requested."); BOOST_CHECK(result["errors"][0]["message"].asString() == "Invalid EVM version requested.");
@ -1211,8 +1211,8 @@ BOOST_AUTO_TEST_CASE(optimizer_settings_details_different)
BOOST_CHECK(optimizer["details"]["yul"].asBool() == true); BOOST_CHECK(optimizer["details"]["yul"].asBool() == true);
BOOST_CHECK(optimizer["details"]["yulDetails"].isObject()); BOOST_CHECK(optimizer["details"]["yulDetails"].isObject());
BOOST_CHECK( BOOST_CHECK(
util::convertContainer<set<string>>(optimizer["details"]["yulDetails"].getMemberNames()) == util::convertContainer<std::set<std::string>>(optimizer["details"]["yulDetails"].getMemberNames()) ==
(set<string>{"stackAllocation", "optimizerSteps"}) (std::set<std::string>{"stackAllocation", "optimizerSteps"})
); );
BOOST_CHECK(optimizer["details"]["yulDetails"]["stackAllocation"].asBool() == true); BOOST_CHECK(optimizer["details"]["yulDetails"]["stackAllocation"].asBool() == true);
BOOST_CHECK( BOOST_CHECK(
@ -1259,7 +1259,7 @@ BOOST_AUTO_TEST_CASE(metadata_without_compilation)
BOOST_AUTO_TEST_CASE(license_in_metadata) BOOST_AUTO_TEST_CASE(license_in_metadata)
{ {
string const input = R"( std::string const input = R"(
{ {
"language": "Solidity", "language": "Solidity",
"sources": { "sources": {
@ -1387,7 +1387,7 @@ BOOST_AUTO_TEST_CASE(use_stack_optimization)
// Now disable stack optimizations and UnusedFunctionParameterPruner (p) // Now disable stack optimizations and UnusedFunctionParameterPruner (p)
// results in "stack too deep" // results in "stack too deep"
string optimiserSteps = OptimiserSettings::DefaultYulOptimiserSteps; std::string optimiserSteps = OptimiserSettings::DefaultYulOptimiserSteps;
optimiserSteps.erase( optimiserSteps.erase(
remove_if(optimiserSteps.begin(), optimiserSteps.end(), [](char ch) { return ch == 'p'; }), remove_if(optimiserSteps.begin(), optimiserSteps.end(), [](char ch) { return ch == 'p'; }),
optimiserSteps.end() optimiserSteps.end()
@ -1728,16 +1728,16 @@ BOOST_AUTO_TEST_CASE(dependency_tracking_of_abstract_contract_yul)
BOOST_REQUIRE(result["contracts"]["A.sol"]["C"].isObject()); BOOST_REQUIRE(result["contracts"]["A.sol"]["C"].isObject());
BOOST_REQUIRE(result["contracts"]["A.sol"]["C"]["ir"].isString()); BOOST_REQUIRE(result["contracts"]["A.sol"]["C"]["ir"].isString());
const string& irCode = result["contracts"]["A.sol"]["C"]["ir"].asString(); const std::string& irCode = result["contracts"]["A.sol"]["C"]["ir"].asString();
// Make sure C and B contracts are deployed // Make sure C and B contracts are deployed
BOOST_REQUIRE(irCode.find("object \"C") != string::npos); BOOST_REQUIRE(irCode.find("object \"C") != std::string::npos);
BOOST_REQUIRE(irCode.find("object \"B") != string::npos); BOOST_REQUIRE(irCode.find("object \"B") != std::string::npos);
// Make sure A and D are NOT deployed as they were not requested and are not // Make sure A and D are NOT deployed as they were not requested and are not
// in any dependency // in any dependency
BOOST_REQUIRE(irCode.find("object \"A") == string::npos); BOOST_REQUIRE(irCode.find("object \"A") == std::string::npos);
BOOST_REQUIRE(irCode.find("object \"D") == string::npos); BOOST_REQUIRE(irCode.find("object \"D") == std::string::npos);
BOOST_REQUIRE(result["sources"].isObject()); BOOST_REQUIRE(result["sources"].isObject());
@ -1770,15 +1770,15 @@ BOOST_AUTO_TEST_CASE(source_location_of_bare_block)
solidity::frontend::StandardCompiler compiler; solidity::frontend::StandardCompiler compiler;
Json::Value result = compiler.compile(parsedInput); Json::Value result = compiler.compile(parsedInput);
string sourceMap = result["contracts"]["A.sol"]["A"]["evm"]["bytecode"]["sourceMap"].asString(); std::string sourceMap = result["contracts"]["A.sol"]["A"]["evm"]["bytecode"]["sourceMap"].asString();
// Check that the bare block's source location is referenced. // Check that the bare block's source location is referenced.
string sourceRef = std::string sourceRef =
";" + ";" +
to_string(string{"contract A { constructor() { uint x = 2; "}.size()) + std::to_string(std::string{"contract A { constructor() { uint x = 2; "}.size()) +
":" + ":" +
to_string(string{"{ uint y = 3; }"}.size()); std::to_string(std::string{"{ uint y = 3; }"}.size());
BOOST_REQUIRE(sourceMap.find(sourceRef) != string::npos); BOOST_REQUIRE(sourceMap.find(sourceRef) != std::string::npos);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -28,7 +28,6 @@
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::util; using namespace solidity::util;
using namespace solidity::util::formatting; using namespace solidity::util::formatting;
@ -39,7 +38,7 @@ using namespace boost::unit_test;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
SyntaxTest::SyntaxTest( SyntaxTest::SyntaxTest(
string const& _filename, std::string const& _filename,
langutil::EVMVersion _evmVersion, langutil::EVMVersion _evmVersion,
Error::Severity _minSeverity Error::Severity _minSeverity
): ):
@ -80,14 +79,14 @@ void SyntaxTest::parseAndAnalyze()
// failing compilation after successful analysis is a rare case, // failing compilation after successful analysis is a rare case,
// it assumes that errors contain exactly one error, and the error is of type Error::Type::CodeGenerationError // it assumes that errors contain exactly one error, and the error is of type Error::Type::CodeGenerationError
if (codeGeneretionErrorCount != 1 || errorCount != 1) if (codeGeneretionErrorCount != 1 || errorCount != 1)
BOOST_THROW_EXCEPTION(runtime_error("Compilation failed even though analysis was successful.")); BOOST_THROW_EXCEPTION(std::runtime_error("Compilation failed even though analysis was successful."));
} }
} }
catch (UnimplementedFeatureError const& _e) catch (UnimplementedFeatureError const& _e)
{ {
m_errorList.emplace_back(SyntaxTestError{ m_errorList.emplace_back(SyntaxTestError{
"UnimplementedFeatureError", "UnimplementedFeatureError",
nullopt, std::nullopt,
errorMessage(_e), errorMessage(_e),
"", "",
-1, -1,
@ -107,7 +106,7 @@ void SyntaxTest::filterObtainedErrors()
int locationStart = -1; int locationStart = -1;
int locationEnd = -1; int locationEnd = -1;
string sourceName; std::string sourceName;
if (SourceLocation const* location = currentError->sourceLocation()) if (SourceLocation const* location = currentError->sourceLocation())
{ {
locationStart = location->start; locationStart = location->start;