@@ -256,17 +256,28 @@ void TestsPrinter::initializeFiles(const Tests::MethodDescription &methodDescrip
256256 fs::path pathToSourceFile =
257257 Paths::sourcePathToTestPath (projectContext, methodDescription.sourceFilePath );
258258 fs::path pathToTestDir = Paths::getPathDirRelativeToBuildDir (projectContext, pathToSourceFile);
259+ int numInitFiles = 0 ;
259260 for (char fileName = ' A' ; fileName < ' A' + types::Type::symFilesCount; fileName++) {
261+ if (testCase.filesValues .value ()[fileName - ' A' ].readBytes == 0 ) {
262+ continue ;
263+ }
264+
265+ numInitFiles++;
260266 std::string strFileName (1 , fileName);
261- strFunctionCall (" write_to_file" ,
262- { StringUtils::wrapQuotations (pathToTestDir / strFileName),
263- testCase.filesValues .value ()[fileName - ' A' ].view ->getEntryValue (this ) });
267+ strFunctionCall (" write_to_file" , { StringUtils::wrapQuotations (pathToTestDir / strFileName),
268+ testCase.filesValues .value ()[fileName - ' A' ].data });
269+ }
270+ if (numInitFiles != 0 ) {
271+ ss << NL;
264272 }
265- ss << NL;
266273}
267274
268275void TestsPrinter::openFiles (const Tests::MethodDescription &methodDescription,
269276 const Tests::MethodTestCase &testCase) {
277+ if (!testCase.filesValues .has_value ()) {
278+ LOG_S (WARNING) << " There are not symbolic files in the test." ;
279+ return ;
280+ }
270281 char fileName = ' A' ;
271282 fs::path pathToSourceFile =
272283 Paths::sourcePathToTestPath (projectContext, methodDescription.sourceFilePath );
@@ -277,12 +288,15 @@ void TestsPrinter::openFiles(const Tests::MethodDescription &methodDescription,
277288 continue ;
278289 }
279290
280- std::string strFileName (1 , fileName++);
291+ std::string strFileName (1 , fileName);
292+ std::string fileMode =
293+ testCase.filesValues .value ()[fileName - ' A' ].writeBytes > 0 ? " \" w\" " : " \" r\" " ;
281294 strDeclareVar (param.type .typeName (), param.name ,
282295 constrFunctionCall (
283296 " (UTBot::FILE *) fopen" ,
284- { StringUtils::wrapQuotations (pathToTestDir / strFileName), " \" r\" " }, " " ,
285- std::nullopt , false ));
297+ { StringUtils::wrapQuotations (pathToTestDir / strFileName), fileMode },
298+ " " , std::nullopt , false ));
299+ fileName++;
286300 }
287301 if (fileName != ' A' ) {
288302 ss << NL;
0 commit comments