@@ -39,12 +39,13 @@ using namespace boost::unit_test;
3939namespace fs = boost::filesystem;
4040
4141
42- SemanticTest::SemanticTest (string const & _filename, langutil::EVMVersion _evmVersion, vector<boost::filesystem::path> const & _vmPaths, bool enforceViaYul):
42+ SemanticTest::SemanticTest (string const & _filename, langutil::EVMVersion _evmVersion, vector<boost::filesystem::path> const & _vmPaths, bool enforceViaYul, bool enforceCompileToEwasm ):
4343 SolidityExecutionFramework(_evmVersion, _vmPaths),
4444 EVMVersionRestrictedTestCase(_filename),
4545 m_sources(m_reader.sources()),
4646 m_lineOffset(m_reader.lineNumber()),
47- m_enforceViaYul(enforceViaYul)
47+ m_enforceViaYul(enforceViaYul),
48+ m_enforceCompileToEwasm(enforceCompileToEwasm)
4849{
4950 string choice = m_reader.stringSetting (" compileViaYul" , " default" );
5051 if (choice == " also" )
@@ -63,6 +64,7 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer
6364 m_runWithoutYul = true ;
6465 // Do not try to run via yul if explicitly denied.
6566 m_enforceViaYul = false ;
67+ m_enforceCompileToEwasm = false ;
6668 }
6769 else if (choice == " default" )
6870 {
@@ -105,16 +107,26 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
105107{
106108 TestResult result = TestResult::Success;
107109 bool compileViaYul = m_runWithYul || m_enforceViaYul;
110+ bool compileToEwasm = m_runWithEwasm || m_enforceCompileToEwasm;
108111
109112 if (m_runWithoutYul)
110113 result = runTest (_stream, _linePrefix, _formatted, false , false );
111114
112115 if (compileViaYul && result == TestResult::Success)
113116 result = runTest (_stream, _linePrefix, _formatted, true , false );
114117
115- if (m_runWithEwasm && result == TestResult::Success)
116- result = runTest (_stream, _linePrefix, _formatted, true , true );
117-
118+ if (compileToEwasm && result == TestResult::Success)
119+ {
120+ try
121+ {
122+ result = runTest (_stream, _linePrefix, _formatted, true , true );
123+ }
124+ catch (...)
125+ {
126+ if (!m_enforceCompileToEwasm)
127+ throw ;
128+ }
129+ }
118130 return result;
119131}
120132
@@ -139,6 +151,7 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
139151 }
140152
141153 m_compileViaYulCanBeSet = false ;
154+ m_compileToEwasmCanBeSet = false ;
142155
143156 if (_compileViaYul)
144157 AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Running via Yul:" << endl;
@@ -236,8 +249,23 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
236249 return TestResult::Failure;
237250 }
238251
252+ if (success && !m_runWithEwasm && _compileToEwasm)
253+ {
254+ if (m_revertStrings != RevertStrings::Default)
255+ return TestResult::Success;
256+
257+ m_compileToEwasmCanBeSet = true ;
258+ AnsiColorized (_stream, _formatted, {BOLD, YELLOW}) <<
259+ _linePrefix << endl <<
260+ _linePrefix << " Test can pass via Yul (ewasm) and marked with compileToEwasm: false." << endl;
261+ return TestResult::Failure;
262+ }
263+
239264 if (!success && (m_runWithYul || !_compileViaYul))
240265 {
266+ if (!m_runWithEwasm && m_enforceCompileToEwasm)
267+ return TestResult::Success;
268+
241269 AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Expected result:" << endl;
242270 for (auto const & test: m_tests)
243271 {
@@ -355,11 +383,28 @@ void SemanticTest::printUpdatedSettings(ostream& _stream, string const& _linePre
355383 return ;
356384
357385 _stream << _linePrefix << " // ====" << endl;
358- if (m_compileViaYulCanBeSet)
386+ if (m_compileToEwasmCanBeSet)
387+ {
388+ // if test was already configured to run via yul,
389+ // we need to preserve the original settings.
390+ if (m_runWithYul)
391+ {
392+ // if test was also configured to run without yul.
393+ if (m_runWithoutYul)
394+ _stream << _linePrefix << " // compileViaYul: also\n " ;
395+ // if test was configured only to run with yul.
396+ else
397+ _stream << _linePrefix << " // compileViaYul: true\n " ;
398+ }
399+
400+ _stream << _linePrefix << " // compileToEwasm: also\n " ;
401+ }
402+ else if (m_compileViaYulCanBeSet)
359403 _stream << _linePrefix << " // compileViaYul: also\n " ;
404+
360405 for (auto const & setting: settings)
361- if (!m_compileViaYulCanBeSet || setting.first != " compileViaYul" )
362- _stream << _linePrefix << " // " << setting.first << " : " << setting.second << endl;
406+ if (!( m_compileViaYulCanBeSet || m_compileToEwasmCanBeSet) || setting.first != " compileViaYul" )
407+ _stream << _linePrefix << " // " << setting.first << " : " << setting.second << endl;
363408}
364409
365410void SemanticTest::parseExpectations (istream& _stream)
0 commit comments