Skip to content

Commit d55bbd4

Browse files
authored
Merge pull request #8508 from a3d4/again-refactor-testcase-classes
More refactoring of TestCase classes
2 parents b5e11e7 + f4d9f67 commit d55bbd4

File tree

420 files changed

+847
-838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

420 files changed

+847
-838
lines changed

test/TestCase.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace solidity;
2828
using namespace solidity::frontend;
2929
using namespace solidity::frontend::test;
3030

31-
void TestCase::printUpdatedSettings(ostream& _stream, const string& _linePrefix, const bool)
31+
void TestCase::printSettings(ostream& _stream, const string& _linePrefix, const bool)
3232
{
3333
auto& settings = m_reader.settings();
3434
if (settings.empty())
@@ -63,11 +63,10 @@ void TestCase::expect(string::iterator& _it, string::iterator _end, string::valu
6363
EVMVersionRestrictedTestCase::EVMVersionRestrictedTestCase(string const& _filename):
6464
TestCase(_filename)
6565
{
66-
if (!m_reader.hasSetting("EVMVersion"))
66+
string versionString = m_reader.stringSetting("EVMVersion", "any");
67+
if (versionString == "any")
6768
return;
6869

69-
string versionString = m_reader.stringSetting("EVMVersion", "");
70-
7170
string comparator;
7271
size_t versionBegin = 0;
7372
for (auto character: versionString)

test/TestCase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class TestCase
5757
/// If @arg _formatted is true, color-coding may be used to indicate
5858
/// error locations in the contract, if applicable.
5959
virtual void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const = 0;
60-
/// Outputs the updated settings.
61-
virtual void printUpdatedSettings(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false);
60+
/// Outputs settings.
61+
virtual void printSettings(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false);
6262
/// Outputs test expectations to @arg _stream that match the actual results of the test.
6363
/// Each line of output is prefixed with @arg _linePrefix.
6464
virtual void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const = 0;

test/TestCaseReader.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,9 @@ string TestCaseReader::simpleExpectations()
4949
return parseSimpleExpectations(m_file);
5050
}
5151

52-
bool TestCaseReader::hasSetting(std::string const& _name) const
53-
{
54-
return m_settings.count(_name) != 0;
55-
}
56-
5752
bool TestCaseReader::boolSetting(std::string const& _name, bool _defaultValue)
5853
{
59-
if (!hasSetting(_name))
54+
if (m_settings.count(_name) == 0)
6055
return _defaultValue;
6156

6257
m_unreadSettings.erase(_name);
@@ -71,7 +66,7 @@ bool TestCaseReader::boolSetting(std::string const& _name, bool _defaultValue)
7166

7267
size_t TestCaseReader::sizetSetting(std::string const& _name, size_t _defaultValue)
7368
{
74-
if (!hasSetting(_name))
69+
if (m_settings.count(_name) == 0)
7570
return _defaultValue;
7671

7772
m_unreadSettings.erase(_name);
@@ -82,18 +77,13 @@ size_t TestCaseReader::sizetSetting(std::string const& _name, size_t _defaultVal
8277

8378
string TestCaseReader::stringSetting(string const& _name, string const& _defaultValue)
8479
{
85-
if (!hasSetting(_name))
80+
if (m_settings.count(_name) == 0)
8681
return _defaultValue;
8782

8883
m_unreadSettings.erase(_name);
8984
return m_settings.at(_name);
9085
}
9186

92-
void TestCaseReader::setSetting(std::string const& _name, std::string const& _value)
93-
{
94-
m_settings[_name] = _value;
95-
}
96-
9787
void TestCaseReader::ensureAllSettingsRead() const
9888
{
9989
if (!m_unreadSettings.empty())

test/TestCaseReader.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ class TestCaseReader
4040

4141
std::string simpleExpectations();
4242

43-
bool hasSetting(std::string const& _name) const;
4443
bool boolSetting(std::string const& _name, bool _defaultValue);
4544
size_t sizetSetting(std::string const& _name, size_t _defaultValue);
4645
std::string stringSetting(std::string const& _name, std::string const& _defaultValue);
47-
void setSetting(std::string const& _name, std::string const& _value);
4846

4947
void ensureAllSettingsRead() const;
5048

test/libsolidity/SemanticTest.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,24 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer
4343
m_source = m_reader.source();
4444
m_lineOffset = m_reader.lineNumber();
4545

46-
if (m_reader.hasSetting("compileViaYul"))
46+
string choice = m_reader.stringSetting("compileViaYul", "false");
47+
if (choice == "also")
4748
{
48-
string choice = m_reader.stringSetting("compileViaYul", "");
49-
if (choice == "also")
50-
{
51-
m_runWithYul = true;
52-
m_runWithoutYul = true;
53-
}
54-
else
55-
{
56-
m_reader.setSetting("compileViaYul", "only");
57-
m_runWithYul = true;
58-
m_runWithoutYul = false;
59-
}
49+
m_runWithYul = true;
50+
m_runWithoutYul = true;
51+
}
52+
else if (choice == "true")
53+
{
54+
m_runWithYul = true;
55+
m_runWithoutYul = false;
56+
}
57+
else if (choice == "false")
58+
{
59+
m_runWithYul = false;
60+
m_runWithoutYul = true;
6061
}
62+
else
63+
BOOST_THROW_EXCEPTION(runtime_error("Invalid compileViaYul value: " + choice + "."));
6164

6265
m_runWithABIEncoderV1Only = m_reader.boolSetting("ABIEncoderV1Only", false);
6366
if (m_runWithABIEncoderV1Only && solidity::test::CommonOptions::get().useABIEncoderV2)

test/libsolidity/semanticTests/viaYul/detect_mod_zero.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ contract C {
77
}
88
}
99
// ====
10-
// compileViaYul: only
10+
// compileViaYul: true
1111
// ----
1212
// f(uint256,uint256): 10, 3 -> 1
1313
// f(uint256,uint256): 10, 2 -> 0

test/libsolidity/semanticTests/viaYul/detect_mod_zero_signed.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ contract C {
77
}
88
}
99
// ====
10-
// compileViaYul: only
10+
// compileViaYul: true
1111
// ----
1212
// f(int256,int256): 10, 3 -> 1
1313
// f(int256,int256): 10, 2 -> 0

test/libsolidity/semanticTests/viaYul/keccak.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ contract C {
88
}
99
}
1010
// ====
11-
// compileViaYul: only
11+
// compileViaYul: true
1212
// ----
1313
// keccak1() -> 0x64e604787cbf194841e7b68d7cd28786f6c9a0a3ab9f8b0a0e87cb4387ab0107
1414
// keccak2() -> 0x64e604787cbf194841e7b68d7cd28786f6c9a0a3ab9f8b0a0e87cb4387ab0107

test/libsolidity/semanticTests/viaYul/string_format.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ contract C {
55
function h() external pure returns (bytes4) { return 0xcafecafe; }
66
}
77
// ====
8-
// compileViaYul: only
8+
// compileViaYul: true
99
// ----
1010
// f1() -> 0x20, 6, left(0x616263616263)
1111
// f2() -> 32, 47, 44048183223289766195424279195050628400112610419087780792899004030957505095210, 18165586057823232067963737336409268114628061002662705707816940456850361417728

test/libyul/YulOptimizerTest.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ YulOptimizerTest::YulOptimizerTest(string const& _filename):
103103
auto dialectName = m_reader.stringSetting("dialect", "evm");
104104
m_dialect = &dialect(dialectName, solidity::test::CommonOptions::get().evmVersion());
105105

106-
m_step = m_reader.stringSetting("step", "");
107-
108106
m_expectation = m_reader.simpleExpectations();
109107
}
110108

@@ -352,21 +350,8 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
352350
return TestResult::FatalError;
353351
}
354352

355-
m_obtainedResult = AsmPrinter{*m_dialect}(*m_ast) + "\n";
353+
m_obtainedResult = "step: " + m_optimizerStep + "\n\n" + AsmPrinter{ *m_dialect }(*m_ast) + "\n";
356354

357-
if (m_optimizerStep != m_step)
358-
{
359-
string nextIndentLevel = _linePrefix + " ";
360-
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::CYAN}) <<
361-
_linePrefix <<
362-
"Invalid optimizer step. Given: \"" <<
363-
m_step <<
364-
"\", should be: \"" <<
365-
m_optimizerStep <<
366-
"\"." <<
367-
endl;
368-
return TestResult::FatalError;
369-
}
370355
if (m_expectation != m_obtainedResult)
371356
{
372357
string nextIndentLevel = _linePrefix + " ";
@@ -385,13 +370,6 @@ void YulOptimizerTest::printSource(ostream& _stream, string const& _linePrefix,
385370
printIndented(_stream, m_source, _linePrefix);
386371
}
387372

388-
void YulOptimizerTest::printUpdatedSettings(ostream& _stream, const string& _linePrefix, const bool _formatted)
389-
{
390-
m_step = m_optimizerStep;
391-
m_reader.setSetting("step", m_step);
392-
EVMVersionRestrictedTestCase::printUpdatedSettings(_stream, _linePrefix, _formatted);
393-
}
394-
395373
void YulOptimizerTest::printUpdatedExpectations(ostream& _stream, string const& _linePrefix) const
396374
{
397375
printIndented(_stream, m_obtainedResult, _linePrefix);

0 commit comments

Comments
 (0)