MCPcopy Create free account
hub / github.com/argotorg/solidity / run

Method run

test/libyul/ControlFlowGraphTest.cpp:206–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204};
205
206TestCase::TestResult ControlFlowGraphTest::run(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted)
207{
208 YulStack yulStack = parseYul(m_source);
209 solUnimplementedAssert(yulStack.parserResult()->subObjects.empty(), "Tests with subobjects not supported.");
210 if (yulStack.hasErrors())
211 {
212 printYulErrors(yulStack, _stream, _linePrefix, _formatted);
213 return TestResult::FatalError;
214 }
215
216 std::ostringstream output;
217
218 std::unique_ptr<CFG> cfg = ControlFlowGraphBuilder::build(
219 *yulStack.parserResult()->analysisInfo,
220 yulStack.dialect(),
221 yulStack.parserResult()->code()->root()
222 );
223
224 output << "digraph CFG {\nnodesep=0.7;\nnode[shape=box];\n\n";
225 ControlFlowGraphPrinter printer{output, yulStack.dialect()};
226 printer(*cfg->entry);
227 for (auto function: cfg->functions)
228 printer(cfg->functionInfo.at(function));
229 output << "}\n";
230
231 m_obtainedResult = output.str();
232
233 auto result = checkResult(_stream, _linePrefix, _formatted);
234
235#ifdef ISOLTEST
236 char* graphDisplayer = nullptr;
237 // The environment variables specify an optional command that will receive the graph encoded in DOT through stdin.
238 // Examples for suitable commands are ``dot -Tx11:cairo`` or ``xdot -``.
239 if (result == TestResult::Failure)
240 // ISOLTEST_DISPLAY_GRAPHS_ON_FAILURE_COMMAND will run on all failing tests (intended for use during modifications).
241 graphDisplayer = getenv("ISOLTEST_DISPLAY_GRAPHS_ON_FAILURE_COMMAND");
242 else if (result == TestResult::Success)
243 // ISOLTEST_DISPLAY_GRAPHS_ON_FAILURE_COMMAND will run on all succeeding tests (intended for use during reviews).
244 graphDisplayer = getenv("ISOLTEST_DISPLAY_GRAPHS_ON_SUCCESS_COMMAND");
245
246 if (graphDisplayer)
247 {
248 if (result == TestResult::Success)
249 std::cout << std::endl << m_source << std::endl;
250 boost::process::opstream pipe;
251 boost::process::child child(graphDisplayer, boost::process::std_in < pipe);
252
253 pipe << output.str();
254 pipe.flush();
255 pipe.pipe().close();
256 if (result == TestResult::Success)
257 child.wait();
258 else
259 child.detach();
260 }
261#endif
262
263 return result;

Callers

nothing calls this directly

Calls 8

parserResultMethod · 0.80
dialectMethod · 0.80
atMethod · 0.80
strMethod · 0.80
flushMethod · 0.80
emptyMethod · 0.45
hasErrorsMethod · 0.45
codeMethod · 0.45

Tested by

no test coverage detected