@@ -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,25 @@ 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+ if (!m_enforceCompileToEwasm || m_runWithEwasm)
126+ throw ;
127+ }
128+ }
118129 return result;
119130}
120131
@@ -139,6 +150,7 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
139150 }
140151
141152 m_compileViaYulCanBeSet = false ;
153+ m_compileToEwasmCanBeSet = false ;
142154
143155 if (_compileViaYul)
144156 AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Running via Yul:" << endl;
@@ -234,8 +246,23 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
234246 return TestResult::Failure;
235247 }
236248
249+ if (success && !m_runWithEwasm && _compileToEwasm)
250+ {
251+ if (m_revertStrings != RevertStrings::Default)
252+ return TestResult::Success;
253+
254+ m_compileToEwasmCanBeSet = true ;
255+ AnsiColorized (_stream, _formatted, {BOLD, YELLOW}) <<
256+ _linePrefix << endl <<
257+ _linePrefix << " Test can pass via Yul to ewasm and marked with compileToEwasm: false." << endl;
258+ return TestResult::Failure;
259+ }
260+
237261 if (!success && (m_runWithYul || !_compileViaYul))
238262 {
263+ if (!m_runWithEwasm && m_enforceCompileToEwasm)
264+ return TestResult::Success;
265+
239266 AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Expected result:" << endl;
240267 for (auto const & test: m_tests)
241268 {
@@ -353,11 +380,24 @@ void SemanticTest::printUpdatedSettings(ostream& _stream, string const& _linePre
353380 return ;
354381
355382 _stream << _linePrefix << " // ====" << endl;
356- if (m_compileViaYulCanBeSet)
383+ if (m_compileToEwasmCanBeSet)
384+ {
385+ if (m_runWithYul)
386+ {
387+ if (m_runWithoutYul)
388+ _stream << _linePrefix << " // compileViaYul: also\n " ;
389+ else
390+ _stream << _linePrefix << " // compileViaYul: true\n " ;
391+ }
392+
393+ _stream << _linePrefix << " // compileToEwasm: also\n " ;
394+ }
395+ else if (m_compileViaYulCanBeSet)
357396 _stream << _linePrefix << " // compileViaYul: also\n " ;
397+
358398 for (auto const & setting: settings)
359- if (!m_compileViaYulCanBeSet || setting.first != " compileViaYul" )
360- _stream << _linePrefix << " // " << setting.first << " : " << setting.second << endl;
399+ if (!( m_compileViaYulCanBeSet || m_compileToEwasmCanBeSet) || setting.first != " compileViaYul" )
400+ _stream << _linePrefix << " // " << setting.first << " : " << setting.second << endl;
361401}
362402
363403void SemanticTest::parseExpectations (istream& _stream)
0 commit comments