@@ -50,6 +50,7 @@ SemanticTest::SemanticTest(
5050 langutil::EVMVersion _evmVersion,
5151 vector<boost::filesystem::path> const & _vmPaths,
5252 bool _enforceViaYul,
53+ bool _enforceCompileToEwasm,
5354 bool _enforceGasCost,
5455 u256 _enforceGasCostMinValue
5556):
@@ -58,6 +59,7 @@ SemanticTest::SemanticTest(
5859 m_sources(m_reader.sources()),
5960 m_lineOffset(m_reader.lineNumber()),
6061 m_enforceViaYul(_enforceViaYul),
62+ m_enforceCompileToEwasm(_enforceCompileToEwasm),
6163 m_enforceGasCost(_enforceGasCost),
6264 m_enforceGasCostMinValue(_enforceGasCostMinValue)
6365{
@@ -78,6 +80,7 @@ SemanticTest::SemanticTest(
7880 m_runWithoutYul = true ;
7981 // Do not try to run via yul if explicitly denied.
8082 m_enforceViaYul = false ;
83+ m_enforceCompileToEwasm = false ;
8184 }
8285 else if (choice == " default" )
8386 {
@@ -126,16 +129,26 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
126129{
127130 TestResult result = TestResult::Success;
128131 bool compileViaYul = m_runWithYul || m_enforceViaYul;
132+ bool compileToEwasm = m_runWithEwasm || m_enforceCompileToEwasm;
129133
130134 if (m_runWithoutYul)
131135 result = runTest (_stream, _linePrefix, _formatted, false , false );
132136
133137 if (compileViaYul && result == TestResult::Success)
134138 result = runTest (_stream, _linePrefix, _formatted, true , false );
135139
136- if (m_runWithEwasm && result == TestResult::Success)
137- result = runTest (_stream, _linePrefix, _formatted, true , true );
138-
140+ if (compileToEwasm && result == TestResult::Success)
141+ {
142+ try
143+ {
144+ result = runTest (_stream, _linePrefix, _formatted, true , true );
145+ }
146+ catch (...)
147+ {
148+ if (!m_enforceCompileToEwasm)
149+ throw ;
150+ }
151+ }
139152 return result;
140153}
141154
@@ -165,6 +178,7 @@ TestCase::TestResult SemanticTest::runTest(
165178 }
166179
167180 m_compileViaYulCanBeSet = false ;
181+ m_compileToEwasmCanBeSet = false ;
168182
169183 if (_compileViaYul)
170184 AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Running via Yul:" << endl;
@@ -288,8 +302,23 @@ TestCase::TestResult SemanticTest::runTest(
288302 return TestResult::Failure;
289303 }
290304
305+ if (success && !m_runWithEwasm && _compileToEwasm)
306+ {
307+ if (m_revertStrings != RevertStrings::Default)
308+ return TestResult::Success;
309+
310+ m_compileToEwasmCanBeSet = true ;
311+ AnsiColorized (_stream, _formatted, {BOLD, YELLOW})
312+ << _linePrefix << endl
313+ << _linePrefix << " Test can pass via Yul (ewasm), but marked with \" compileToEwasm: false.\" " << endl;
314+ return TestResult::Failure;
315+ }
316+
291317 if (!success && (m_runWithYul || !_compileViaYul))
292318 {
319+ if (!m_runWithEwasm && m_enforceCompileToEwasm)
320+ return TestResult::Success;
321+
293322 AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Expected result:" << endl;
294323 for (TestFunctionCall const & test: m_tests)
295324 {
@@ -424,11 +453,28 @@ void SemanticTest::printUpdatedSettings(ostream& _stream, string const& _linePre
424453 return ;
425454
426455 _stream << _linePrefix << " // ====" << endl;
427- if (m_compileViaYulCanBeSet)
456+ if (m_compileToEwasmCanBeSet)
457+ {
458+ // if test was already configured to run via yul,
459+ // we need to preserve the original settings.
460+ if (m_runWithYul)
461+ {
462+ // if test was also configured to run without yul.
463+ if (m_runWithoutYul)
464+ _stream << _linePrefix << " // compileViaYul: also\n " ;
465+ // if test was configured only to run with yul.
466+ else
467+ _stream << _linePrefix << " // compileViaYul: true\n " ;
468+ }
469+
470+ _stream << _linePrefix << " // compileToEwasm: also\n " ;
471+ }
472+ else if (m_compileViaYulCanBeSet)
428473 _stream << _linePrefix << " // compileViaYul: also\n " ;
474+
429475 for (auto const & setting: settings)
430- if (!m_compileViaYulCanBeSet || setting.first != " compileViaYul" )
431- _stream << _linePrefix << " // " << setting.first << " : " << setting.second << endl;
476+ if (!( m_compileViaYulCanBeSet || m_compileToEwasmCanBeSet) || setting.first != " compileViaYul" )
477+ _stream << _linePrefix << " // " << setting.first << " : " << setting.second << endl;
432478}
433479
434480void SemanticTest::parseExpectations (istream& _stream)
0 commit comments