@@ -256,17 +256,28 @@ void TestsPrinter::initializeFiles(const Tests::MethodDescription &methodDescrip
256
256
fs::path pathToSourceFile =
257
257
Paths::sourcePathToTestPath (projectContext, methodDescription.sourceFilePath );
258
258
fs::path pathToTestDir = Paths::getPathDirRelativeToBuildDir (projectContext, pathToSourceFile);
259
+ int numInitFiles = 0 ;
259
260
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++;
260
266
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;
264
272
}
265
- ss << NL;
266
273
}
267
274
268
275
void TestsPrinter::openFiles (const Tests::MethodDescription &methodDescription,
269
276
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
+ }
270
281
char fileName = ' A' ;
271
282
fs::path pathToSourceFile =
272
283
Paths::sourcePathToTestPath (projectContext, methodDescription.sourceFilePath );
@@ -277,12 +288,15 @@ void TestsPrinter::openFiles(const Tests::MethodDescription &methodDescription,
277
288
continue ;
278
289
}
279
290
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\" " ;
281
294
strDeclareVar (param.type .typeName (), param.name ,
282
295
constrFunctionCall (
283
296
" (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++;
286
300
}
287
301
if (fileName != ' A' ) {
288
302
ss << NL;
0 commit comments