@@ -187,151 +187,6 @@ Status Server::TestsGenServiceImpl::CreateTestsCoverageAndResult(
187187    return  status;
188188}
189189
190- //  TODO: move to testgen base classes
191- Status Server::TestsGenServiceImpl::ProcessBaseTestRequest (BaseTestGen &testGen,
192-                                                            TestsWriter *testsWriter) {
193-     try  {
194-         MEASURE_FUNCTION_EXECUTION_TIME
195-         auto  preprocessingStartTime = std::chrono::steady_clock::now ();
196-         types::TypesHandler::SizeContext sizeContext;
197- 
198-         static  std::string logMessage = " Traversing sources AST tree and fetching declarations." 
199-         LOG_S (DEBUG) << logMessage;
200-         Fetcher fetcher (Fetcher::Options::Value::ALL,
201-                         testGen.buildDatabase ->compilationDatabase , testGen.tests , &testGen.types ,
202-                         &sizeContext.pointerSize , &sizeContext.maximumAlignment ,
203-                         testGen.compileCommandsJsonPath , false );
204-         fetcher.fetchWithProgress (testGen.progressWriter , logMessage);
205-         SourceToHeaderRewriter (testGen.projectContext , testGen.buildDatabase ->compilationDatabase ,
206-                                fetcher.getStructsToDeclare (), testGen.serverBuildDir )
207-             .generateTestHeaders (testGen.tests , testGen.progressWriter );
208-         types::TypesHandler typesHandler{ testGen.types , sizeContext };
209-         testGen.progressWriter ->writeProgress (" Generating stub files" 0.0 );
210-         StubGen stubGen (testGen);
211- 
212-         Synchronizer synchronizer (&testGen, &stubGen, &sizeContext);
213-         synchronizer.synchronize (typesHandler);
214- 
215-         std::shared_ptr<LineInfo> lineInfo = nullptr ;
216-         auto  lineTestGen = dynamic_cast <LineTestGen *>(&testGen);
217- 
218-         if  (lineTestGen != nullptr ) {
219-             if  (isSameType<ClassTestGen>(testGen) && Paths::isHeaderFile (lineTestGen->filePath )) {
220-                 BordersFinder classFinder (lineTestGen->filePath , lineTestGen->line ,
221-                                           lineTestGen->buildDatabase ->compilationDatabase ,
222-                                           lineTestGen->compileCommandsJsonPath );
223-                 classFinder.findClass ();
224-                 lineInfo = std::make_shared<LineInfo>(classFinder.getLineInfo ());
225-                 lineInfo->filePath  = lineTestGen->getSourcePath ();
226-                 CollectionUtils::erase_if (testGen.tests .at (lineInfo->filePath ).methods ,
227-                                           [&lineInfo](const  tests::Tests::MethodDescription &methodDescription) {
228-                                               return  methodDescription.isClassMethod () &&
229-                                                      methodDescription.classObj ->type .typeName () != lineInfo->scopeName ;
230-                                           });
231-             } else  {
232-                 lineInfo = getLineInfo (*lineTestGen);
233-                 CollectionUtils::erase_if (testGen.tests .at (lineInfo->filePath ).methods ,
234-                                           [&lineInfo](const  auto  &methodDescription) {
235-                                               return  methodDescription.name  != lineInfo->methodName ;
236-                                           });
237-             }
238-         }
239- 
240-         FeaturesFilter::filter (testGen.settingsContext , typesHandler, testGen.tests );
241-         StubsCollector (typesHandler).collect (testGen.tests );
242- 
243-         PathSubstitution pathSubstitution = {};
244-         if  (lineTestGen != nullptr ) {
245-             lineInfo->forMethod  = isSameType<FunctionTestGen>(testGen);
246-             lineInfo->forClass  = isSameType<ClassTestGen>(testGen);
247-             lineInfo->forAssert  = isSameType<AssertionTestGen>(testGen);
248-             if  (lineTestGen->needToAddPathFlag ()) {
249-                 LOG_S (DEBUG) << " Added test line flag for file " filePath ;
250-                 fs::path flagFilePath =
251-                     printer::KleePrinter (&typesHandler, nullptr , Paths::getSourceLanguage (lineInfo->filePath ))
252-                         .addTestLineFlag (lineInfo, lineInfo->forAssert , testGen.projectContext );
253-                 pathSubstitution = { lineTestGen->filePath , flagFilePath };
254-             }
255-         }
256-         auto  generator = std::make_shared<KleeGenerator>(testGen, typesHandler, pathSubstitution);
257- 
258-         ReturnTypesFetcher returnTypesFetcher{ &testGen };
259-         returnTypesFetcher.fetch (testGen.progressWriter , synchronizer.getAllFiles ());
260-         LOG_S (DEBUG) << " Temporary build directory path: " serverBuildDir ;
261-         generator->buildKleeFiles (testGen.tests , lineInfo);
262-         generator->handleFailedFunctions (testGen.tests );
263-         testGen.progressWriter ->writeProgress (" Building files" 0.0 );
264-         Linker linker{ testGen, stubGen, lineInfo, generator };
265-         linker.prepareArtifacts ();
266-         auto  testMethods = linker.getTestMethods ();
267-         KleeRunner kleeRunner{ testGen.projectContext , testGen.settingsContext ,
268-                                testGen.serverBuildDir  };
269-         bool  interactiveMode = (dynamic_cast <ProjectTestGen *>(&testGen) != nullptr );
270-         auto  generationStartTime = std::chrono::steady_clock::now ();
271-         StatsUtils::TestsGenerationStatsFileMap generationStatsMap (testGen.projectContext ,
272-                 std::chrono::duration_cast<std::chrono::milliseconds>(generationStartTime - preprocessingStartTime));
273-         kleeRunner.runKlee (testMethods, testGen.tests , generator, testGen.methodNameToReturnTypeMap ,
274-                            lineInfo, testsWriter, testGen.isBatched (), interactiveMode, generationStatsMap);
275-         LOG_S (INFO) << " KLEE time: " 
276-                         (generationStatsMap.getTotal ().kleeStats .getKleeTime ()).count () << "  ms\n " 
277-         printer::CSVPrinter printer = generationStatsMap.toCSV ();
278-         FileSystemUtils::writeToFile (Paths::getGenerationStatsCSVPath (testGen.projectContext ),
279-                                      printer.getStream ().str ());
280-         LOG_S (INFO) << StringUtils::stringFormat (" See generation stats here: %s" 
281-                                                  Paths::getGenerationStatsCSVPath (testGen.projectContext ));
282-     } catch  (const  ExecutionProcessException &e) {
283-         std::string command = e.what ();
284-         return  Status (StatusCode::FAILED_PRECONDITION,
285-                       " Executing command\n " substr (0 , 100 ) +
286-                           " ...\n failed. See more info in console logs." 
287-     } catch  (const  NoTestGeneratedException &e) {
288-         return  Status (StatusCode::FAILED_PRECONDITION, e.what ());
289-     } catch  (const  CancellationException &e) {
290-         return  Status::CANCELLED;
291-     } catch  (const  NoSuchTypeException &e) {
292-         return  Status (StatusCode::UNIMPLEMENTED, e.what ());
293-     } catch  (const  EnvironmentException &e) {
294-         return  Status (StatusCode::FAILED_PRECONDITION, e.what ());
295-     } catch  (const  CompilationDatabaseException &e) {
296-         return  Status (StatusCode::FAILED_PRECONDITION, e.what ());
297-     } catch  (const  FileNotPresentedInCommandsException &e) {
298-         return  Status (StatusCode::FAILED_PRECONDITION,
299-                       FileNotPresentedInCommandsException::MESSAGE, e.getFilePath ());
300-     } catch  (const  FileNotPresentedInArtifactException &e) {
301-         return  Status (StatusCode::FAILED_PRECONDITION,
302-                       FileNotPresentedInArtifactException::MESSAGE, e.getFilePath ());
303-     } catch  (const  BaseException &e) {
304-         return  Status (StatusCode::INTERNAL, e.what ());
305-     }
306-     return  Status::OK;
307- }
308- 
309- std::shared_ptr<LineInfo> Server::TestsGenServiceImpl::getLineInfo (LineTestGen &lineTestGen) {
310-     BordersFinder stmtFinder (lineTestGen.filePath , lineTestGen.line ,
311-                              lineTestGen.buildDatabase ->compilationDatabase ,
312-                              lineTestGen.compileCommandsJsonPath );
313-     stmtFinder.findFunction ();
314-     if  (!stmtFinder.getLineInfo ().initialized ) {
315-         throw  NoTestGeneratedException (
316-             " Maybe you tried to generate tests placing cursor on invalid line." 
317-     }
318-     if  (isSameType<AssertionTestGen>(lineTestGen) &&
319-         !StringUtils::contains (stmtFinder.getLineInfo ().stmtString , " assert" 
320-         throw  NoTestGeneratedException (" No assert found on this line." 
321-     }
322-     auto  lineInfo = std::make_shared<LineInfo>(stmtFinder.getLineInfo ());
323-     if  (auto  predicateInfo = dynamic_cast <PredicateTestGen *>(&lineTestGen)) {
324-         lineInfo->predicateInfo  = LineInfo::PredicateInfo (
325-             { predicateInfo->type , predicateInfo->predicate , predicateInfo->returnValue  });
326-     }
327-     auto  &methods = lineTestGen.tests .at (lineInfo->filePath ).methods ;
328-     CollectionUtils::erase_if (methods, [&lineInfo](auto  const  &method) {
329-         return  (lineInfo->forMethod  && method.name  != lineInfo->methodName ) ||
330-                (lineInfo->forClass  && method.isClassMethod () && method.classObj ->type .typeName () != lineInfo->scopeName );
331-     });
332-     return  lineInfo;
333- }
334- 
335190std::string extractMessage (const  loguru::Message &message) {
336191    return  std::string (message.preamble ) + std::string (message.prefix ) + message.message  + " \n " 
337192}
@@ -498,7 +353,7 @@ Status Server::TestsGenServiceImpl::GetFunctionReturnType(ServerContext *context
498353    MEASURE_FUNCTION_EXECUTION_TIME
499354
500355    LineTestGen testGen (request->linerequest (), nullptr , testMode);
501-     auto  lineInfo = getLineInfo (testGen );
356+     auto  lineInfo = testGen. getLineInfo ();
502357    const  auto  &type = lineInfo->functionReturnType ;
503358    testsgen::ValidationType typeResponse = testsgen::UNSUPPORTED;
504359    if  (types::TypesHandler::isIntegerType (type)) {
0 commit comments