Skip to content

Commit ac54fe1

Browse files
committed
Purge using namespace std from test
1 parent 172f3cf commit ac54fe1

File tree

10 files changed

+192
-198
lines changed

10 files changed

+192
-198
lines changed

scripts/check_style.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ NAMESPACE_STD_FREE_FILES=(
3939
libyul/backends/evm/*
4040
libyul/optimiser/*
4141
solc/*
42+
test/*
4243
test/contracts/*
4344
test/libevmasm/*
4445
test/liblangutil/*

test/Common.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
namespace fs = boost::filesystem;
3333
namespace po = boost::program_options;
3434

35-
using namespace std;
36-
3735
namespace solidity::test
3836
{
3937

@@ -147,15 +145,15 @@ void CommonOptions::validate() const
147145
);
148146

149147
if (!enforceGasTest)
150-
cout << endl << "WARNING :: Gas cost expectations are not being enforced" << endl << endl;
148+
std::cout << std::endl << "WARNING :: Gas cost expectations are not being enforced" << std::endl << std::endl;
151149
else if (evmVersion() != langutil::EVMVersion{} || useABIEncoderV1)
152150
{
153-
cout << endl << "WARNING :: Enforcing gas cost expectations with non-standard settings:" << endl;
151+
std::cout << std::endl << "WARNING :: Enforcing gas cost expectations with non-standard settings:" << std::endl;
154152
if (evmVersion() != langutil::EVMVersion{})
155-
cout << "- EVM version: " << evmVersion().name() << " (default: " << langutil::EVMVersion{}.name() << ")" << endl;
153+
std::cout << "- EVM version: " << evmVersion().name() << " (default: " << langutil::EVMVersion{}.name() << ")" << std::endl;
156154
if (useABIEncoderV1)
157-
cout << "- ABI coder: v1 (default: v2)" << endl;
158-
cout << endl << "DO NOT COMMIT THE UPDATED EXPECTATIONS." << endl << endl;
155+
std::cout << "- ABI coder: v1 (default: v2)" << std::endl;
156+
std::cout << std::endl << "DO NOT COMMIT THE UPDATED EXPECTATIONS." << std::endl << std::endl;
159157
}
160158
}
161159

@@ -176,7 +174,7 @@ bool CommonOptions::parse(int argc, char const* const* argv)
176174
// Request as uint64_t, since uint8_t will be parsed as character by boost.
177175
uint64_t eofVersion = arguments["eof-version"].as<uint64_t>();
178176
if (eofVersion != 1)
179-
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid EOF version: " + to_string(eofVersion)));
177+
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid EOF version: " + std::to_string(eofVersion)));
180178
m_eofVersion = 1;
181179
}
182180

@@ -213,18 +211,18 @@ bool CommonOptions::parse(int argc, char const* const* argv)
213211
return true;
214212
}
215213

216-
string CommonOptions::toString(vector<string> const& _selectedOptions) const
214+
std::string CommonOptions::toString(std::vector<std::string> const& _selectedOptions) const
217215
{
218216
if (_selectedOptions.empty())
219217
return "";
220218

221-
auto boolToString = [](bool _value) -> string { return _value ? "true" : "false"; };
219+
auto boolToString = [](bool _value) -> std::string { return _value ? "true" : "false"; };
222220
// Using std::map to avoid if-else/switch-case block
223-
map<string, string> optionValueMap = {
221+
std::map<std::string, std::string> optionValueMap = {
224222
{"evmVersion", evmVersion().name()},
225223
{"optimize", boolToString(optimize)},
226224
{"useABIEncoderV1", boolToString(useABIEncoderV1)},
227-
{"batch", to_string(selectedBatch + 1) + "/" + to_string(batches)},
225+
{"batch", std::to_string(selectedBatch + 1) + "/" + std::to_string(batches)},
228226
{"enforceGasTest", boolToString(enforceGasTest)},
229227
{"enforceGasTestMinValue", enforceGasTestMinValue.str()},
230228
{"disableSemanticTests", boolToString(disableSemanticTests)},
@@ -233,18 +231,18 @@ string CommonOptions::toString(vector<string> const& _selectedOptions) const
233231
{"showMetadata", boolToString(showMetadata)}
234232
};
235233

236-
soltestAssert(ranges::all_of(_selectedOptions, [&optionValueMap](string const& _option) { return optionValueMap.count(_option) > 0; }));
234+
soltestAssert(ranges::all_of(_selectedOptions, [&optionValueMap](std::string const& _option) { return optionValueMap.count(_option) > 0; }));
237235

238-
vector<string> optionsWithValues = _selectedOptions |
239-
ranges::views::transform([&optionValueMap](string const& _option) { return _option + "=" + optionValueMap.at(_option); }) |
240-
ranges::to<vector>();
236+
std::vector<std::string> optionsWithValues = _selectedOptions |
237+
ranges::views::transform([&optionValueMap](std::string const& _option) { return _option + "=" + optionValueMap.at(_option); }) |
238+
ranges::to<std::vector>();
241239

242240
return solidity::util::joinHumanReadable(optionsWithValues);
243241
}
244242

245-
void CommonOptions::printSelectedOptions(ostream& _stream, string const& _linePrefix, vector<string> const& _selectedOptions) const
243+
void CommonOptions::printSelectedOptions(std::ostream& _stream, std::string const& _linePrefix, std::vector<std::string> const& _selectedOptions) const
246244
{
247-
_stream << _linePrefix << "Run Settings: " << toString(_selectedOptions) << endl;
245+
_stream << _linePrefix << "Run Settings: " << toString(_selectedOptions) << std::endl;
248246
}
249247

250248
langutil::EVMVersion CommonOptions::evmVersion() const

test/CommonSyntaxTest.cpp

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <memory>
3535
#include <stdexcept>
3636

37-
using namespace std;
3837
using namespace solidity;
3938
using namespace solidity::util;
4039
using namespace solidity::util::formatting;
@@ -48,10 +47,10 @@ namespace fs = boost::filesystem;
4847
namespace
4948
{
5049

51-
int parseUnsignedInteger(string::iterator& _it, string::iterator _end)
50+
int parseUnsignedInteger(std::string::iterator& _it, std::string::iterator _end)
5251
{
5352
if (_it == _end || !util::isDigit(*_it))
54-
BOOST_THROW_EXCEPTION(runtime_error("Invalid test expectation. Source location expected."));
53+
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid test expectation. Source location expected."));
5554
int result = 0;
5655
while (_it != _end && util::isDigit(*_it))
5756
{
@@ -64,23 +63,23 @@ int parseUnsignedInteger(string::iterator& _it, string::iterator _end)
6463

6564
}
6665

67-
CommonSyntaxTest::CommonSyntaxTest(string const& _filename, langutil::EVMVersion _evmVersion):
66+
CommonSyntaxTest::CommonSyntaxTest(std::string const& _filename, langutil::EVMVersion _evmVersion):
6867
EVMVersionRestrictedTestCase(_filename),
6968
m_sources(m_reader.sources()),
7069
m_expectations(parseExpectations(m_reader.stream())),
7170
m_evmVersion(_evmVersion)
7271
{
7372
}
7473

75-
TestCase::TestResult CommonSyntaxTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
74+
TestCase::TestResult CommonSyntaxTest::run(std::ostream& _stream, std::string const& _linePrefix, bool _formatted)
7675
{
7776
parseCustomExpectations(m_reader.stream());
7877
parseAndAnalyze();
7978

8079
return conclude(_stream, _linePrefix, _formatted);
8180
}
8281

83-
TestCase::TestResult CommonSyntaxTest::conclude(ostream& _stream, string const& _linePrefix, bool _formatted)
82+
TestCase::TestResult CommonSyntaxTest::conclude(std::ostream& _stream, std::string const& _linePrefix, bool _formatted)
8483
{
8584
if (expectationsMatch())
8685
return TestResult::Success;
@@ -89,16 +88,16 @@ TestCase::TestResult CommonSyntaxTest::conclude(ostream& _stream, string const&
8988
return TestResult::Failure;
9089
}
9190

92-
void CommonSyntaxTest::printExpectationAndError(ostream& _stream, string const& _linePrefix, bool _formatted)
91+
void CommonSyntaxTest::printExpectationAndError(std::ostream& _stream, std::string const& _linePrefix, bool _formatted)
9392
{
94-
string nextIndentLevel = _linePrefix + " ";
95-
util::AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
93+
std::string nextIndentLevel = _linePrefix + " ";
94+
util::AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << std::endl;
9695
printExpectedResult(_stream, nextIndentLevel, _formatted);
97-
util::AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl;
96+
util::AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << std::endl;
9897
printObtainedResult(_stream, nextIndentLevel, _formatted);
9998
}
10099

101-
void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix, bool _formatted) const
100+
void CommonSyntaxTest::printSource(std::ostream& _stream, std::string const& _linePrefix, bool _formatted) const
102101
{
103102
if (m_sources.sources.empty())
104103
return;
@@ -113,8 +112,8 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
113112
continue;
114113

115114
if (outputSourceNames)
116-
_stream << _linePrefix << util::formatting::CYAN << "==== Source: " << name << " ====" << util::formatting::RESET << endl;
117-
vector<char const*> sourceFormatting(source.length(), util::formatting::RESET);
115+
_stream << _linePrefix << util::formatting::CYAN << "==== Source: " << name << " ====" << util::formatting::RESET << std::endl;
116+
std::vector<char const*> sourceFormatting(source.length(), util::formatting::RESET);
118117
for (auto const& error: m_errorList)
119118
if (error.sourceName == name && error.locationStart >= 0 && error.locationEnd >= 0)
120119
{
@@ -143,7 +142,7 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
143142
_stream << source[i];
144143
else
145144
{
146-
_stream << util::formatting::RESET << endl;
145+
_stream << util::formatting::RESET << std::endl;
147146
if (i + 1 < source.length())
148147
_stream << _linePrefix << sourceFormatting[i];
149148
}
@@ -158,9 +157,9 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
158157
}
159158
}
160159

161-
void CommonSyntaxTest::parseCustomExpectations(istream& _stream)
160+
void CommonSyntaxTest::parseCustomExpectations(std::istream& _stream)
162161
{
163-
string remainingExpectations = boost::trim_copy(readUntilEnd(_stream));
162+
std::string remainingExpectations = boost::trim_copy(readUntilEnd(_stream));
164163
soltestAssert(
165164
remainingExpectations.empty(),
166165
"Found custom expectations not supported by the test case:\n" + remainingExpectations
@@ -172,27 +171,27 @@ bool CommonSyntaxTest::expectationsMatch()
172171
return m_expectations == m_errorList;
173172
}
174173

175-
void CommonSyntaxTest::printExpectedResult(ostream& _stream, string const& _linePrefix, bool _formatted) const
174+
void CommonSyntaxTest::printExpectedResult(std::ostream& _stream, std::string const& _linePrefix, bool _formatted) const
176175
{
177176
printErrorList(_stream, m_expectations, _linePrefix, _formatted);
178177
}
179178

180-
void CommonSyntaxTest::printObtainedResult(ostream& _stream, string const& _linePrefix, bool _formatted) const
179+
void CommonSyntaxTest::printObtainedResult(std::ostream& _stream, std::string const& _linePrefix, bool _formatted) const
181180
{
182181
printErrorList(_stream, m_errorList, _linePrefix, _formatted);
183182
}
184183

185184
void CommonSyntaxTest::printErrorList(
186-
ostream& _stream,
187-
vector<SyntaxTestError> const& _errorList,
188-
string const& _linePrefix,
185+
std::ostream& _stream,
186+
std::vector<SyntaxTestError> const& _errorList,
187+
std::string const& _linePrefix,
189188
bool _formatted
190189
)
191190
{
192191
if (_errorList.empty())
193192
{
194193
if (_formatted)
195-
util::AnsiColorized(_stream, _formatted, {BOLD, GREEN}) << _linePrefix << "Success" << endl;
194+
util::AnsiColorized(_stream, _formatted, {BOLD, GREEN}) << _linePrefix << "Success" << std::endl;
196195
}
197196
else
198197
for (auto const& error: _errorList)
@@ -220,25 +219,25 @@ void CommonSyntaxTest::printErrorList(
220219
_stream << error.locationEnd;
221220
_stream << "): ";
222221
}
223-
_stream << error.message << endl;
222+
_stream << error.message << std::endl;
224223
}
225224
}
226225

227-
string CommonSyntaxTest::errorMessage(util::Exception const& _e)
226+
std::string CommonSyntaxTest::errorMessage(util::Exception const& _e)
228227
{
229228
if (_e.comment() && !_e.comment()->empty())
230229
return boost::replace_all_copy(*_e.comment(), "\n", "\\n");
231230
else
232231
return "NONE";
233232
}
234233

235-
vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
234+
std::vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(std::istream& _stream)
236235
{
237-
static string const customExpectationsDelimiter("// ----");
236+
static std::string const customExpectationsDelimiter("// ----");
238237

239-
vector<SyntaxTestError> expectations;
240-
string line;
241-
while (getline(_stream, line))
238+
std::vector<SyntaxTestError> expectations;
239+
std::string line;
240+
while (std::getline(_stream, line))
242241
{
243242
auto it = line.begin();
244243

@@ -254,17 +253,17 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
254253
if (it == line.end()) continue;
255254

256255
auto typeBegin = it;
257-
while (it != line.end() && isalpha(*it, locale::classic()))
256+
while (it != line.end() && isalpha(*it, std::locale::classic()))
258257
++it;
259258

260-
string errorTypeStr(typeBegin, it);
261-
optional<Error::Type> errorType = Error::parseErrorType(errorTypeStr);
259+
std::string errorTypeStr(typeBegin, it);
260+
std::optional<Error::Type> errorType = Error::parseErrorType(errorTypeStr);
262261
if (!errorType.has_value())
263-
BOOST_THROW_EXCEPTION(runtime_error("Invalid error type: " + errorTypeStr));
262+
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid error type: " + errorTypeStr));
264263

265264
skipWhitespace(it, line.end());
266265

267-
optional<ErrorId> errorId;
266+
std::optional<ErrorId> errorId;
268267
if (it != line.end() && util::isDigit(*it))
269268
errorId = ErrorId{static_cast<unsigned long long>(parseUnsignedInteger(it, line.end()))};
270269

@@ -295,7 +294,7 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
295294

296295
skipWhitespace(it, line.end());
297296

298-
string errorMessage(it, line.end());
297+
std::string errorMessage(it, line.end());
299298
expectations.emplace_back(SyntaxTestError{
300299
errorType.value(),
301300
std::move(errorId),

0 commit comments

Comments
 (0)