Skip to content

Commit d290434

Browse files
authored
Merge pull request #1424 from LLNL/bugfix/han12/removeFile_Windows
removeFile() Usage
2 parents 24751dd + e528819 commit d290434

9 files changed

+38
-22
lines changed

src/axom/mint/tests/mint_su2_io.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ TEST(mint_su2_io, write_read_mixed_cell_topology_mesh)
155155

156156
// cleanup
157157
delete test_mesh;
158-
axom::utilities::filesystem::removeFile(su2File);
158+
EXPECT_EQ(axom::utilities::filesystem::removeFile(su2File), 0);
159159
}
160160

161161
//------------------------------------------------------------------------------
@@ -212,7 +212,7 @@ TEST(mint_su2_io, write_read_single_cell_topology_mesh)
212212

213213
// cleanup
214214
delete test_mesh;
215-
axom::utilities::filesystem::removeFile(su2File);
215+
EXPECT_EQ(axom::utilities::filesystem::removeFile(su2File), 0);
216216
}
217217

218218
//------------------------------------------------------------------------------

src/axom/mint/tests/mint_util_write_vtk.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ void test_mesh(MeshType* mesh, const std::string& path)
820820
file.close();
821821
delete mesh;
822822
#if DELETE_VTK_FILES
823-
axom::utilities::filesystem::removeFile(path);
823+
EXPECT_EQ(axom::utilities::filesystem::removeFile(path), 0);
824824
#endif
825825
}
826826

src/axom/quest/tests/quest_intersection_shaper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ void IntersectionWithErrorTolerances(const std::string &filebase,
502502
// Clean up files.
503503
for(const auto &filename : filenames)
504504
{
505-
axom::utilities::filesystem::removeFile(filename);
505+
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
506506
}
507507
}
508508

src/axom/quest/tests/quest_pro_e_reader.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ TEST(quest_pro_e_reader, read_to_invalid_mesh)
9292
EXPECT_DEATH_IF_SUPPORTED(reader.getMesh(&hexmesh), IGNORE_OUTPUT);
9393

9494
// STEP 4: remove Pro/E file
95-
axom::utilities::filesystem::removeFile(filename);
95+
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
9696
}
9797

9898
//------------------------------------------------------------------------------
@@ -143,7 +143,7 @@ TEST(quest_pro_e_reader, read_pro_e)
143143
} // END for all nodes
144144

145145
// STEP 4: remove temporary Pro/E file
146-
axom::utilities::filesystem::removeFile(filename);
146+
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
147147
}
148148

149149
//------------------------------------------------------------------------------
@@ -197,7 +197,7 @@ TEST(quest_pro_e_reader, read_pro_e_invbbox)
197197
} // END for all nodes
198198

199199
// STEP 4: remove temporary Pro/E file
200-
axom::utilities::filesystem::removeFile(filename);
200+
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
201201
}
202202

203203
//------------------------------------------------------------------------------
@@ -253,7 +253,7 @@ TEST(quest_pro_e_reader, read_pro_e_bbox_all)
253253
} // END for all nodes
254254

255255
// STEP 4: remove temporary Pro/E file
256-
axom::utilities::filesystem::removeFile(filename);
256+
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
257257
}
258258

259259
//------------------------------------------------------------------------------
@@ -310,7 +310,7 @@ TEST(quest_pro_e_reader, read_pro_e_bbox_some)
310310
} // END for all nodes
311311

312312
// STEP 4: remove temporary Pro/E file
313-
axom::utilities::filesystem::removeFile(filename);
313+
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
314314
}
315315

316316
//------------------------------------------------------------------------------
@@ -367,7 +367,7 @@ TEST(quest_pro_e_reader, read_pro_e_bbox_some_incl)
367367
} // END for all nodes
368368

369369
// STEP 4: remove temporary Pro/E file
370-
axom::utilities::filesystem::removeFile(filename);
370+
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
371371
}
372372

373373
//------------------------------------------------------------------------------
@@ -426,7 +426,7 @@ TEST(quest_pro_e_reader, read_pro_e_external)
426426
} // END for all nodes
427427

428428
// STEP 4: remove temporary Pro/E file
429-
axom::utilities::filesystem::removeFile(filename);
429+
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
430430
}
431431

432432
#ifdef AXOM_DATA_DIR

src/axom/quest/tests/quest_sampling_shaper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ScopedTemporaryFile
6767

6868
~ScopedTemporaryFile()
6969
{
70-
axom::utilities::filesystem::removeFile(m_filename);
70+
EXPECT_EQ(axom::utilities::filesystem::removeFile(m_filename), 0);
7171
}
7272

7373
const std::string& getFileName() const { return m_filename; }

src/axom/quest/tests/quest_signed_distance_interface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void check_analytic_plane(bool use_shared = false)
233233
EXPECT_FALSE(quest::signed_distance_initialized());
234234

235235
#ifdef REMOVE_FILES
236-
axom::utilities::filesystem::removeFile(file);
236+
EXPECT_EQ(axom::utilities::filesystem::removeFile(file), 0);
237237
#endif
238238
}
239239

@@ -373,7 +373,7 @@ TEST(quest_signed_distance_interface, initialize)
373373

374374
// remove temp STL file
375375
#ifdef REMOVE_FILES
376-
axom::utilities::filesystem::removeFile(fileName);
376+
EXPECT_EQ(axom::utilities::filesystem::removeFile(fileName), 0);
377377
#endif
378378
}
379379

src/axom/quest/tests/quest_stl_reader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ TEST(quest_stl_reader_DeathTest, read_to_invalid_mesh)
8282
EXPECT_DEATH_IF_SUPPORTED(reader.getMesh(&hexmesh), IGNORE_OUTPUT);
8383

8484
// STEP 4: remove STL file
85-
axom::utilities::filesystem::removeFile(filename);
85+
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
8686
}
8787

8888
//------------------------------------------------------------------------------

src/axom/slic/tests/slic_macros.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ TEST(slic_macros, test_macros_file_output)
425425
std::string with_fmt = "file_with_fmt.txt";
426426

427427
slic::addStreamToAllMsgLevels(new slic::GenericOutputStream(no_fmt));
428-
429428
slic::addStreamToAllMsgLevels(new slic::GenericOutputStream(with_fmt, msgfmt));
430429

431430
EXPECT_FALSE(axom::utilities::filesystem::pathExists(no_fmt));
@@ -457,7 +456,7 @@ TEST(slic_macros, test_macros_file_output)
457456
std::string no_fmt_expected;
458457
no_fmt_expected += "*****\n[INFO]\n\n Test \n\n ";
459458
no_fmt_expected += __FILE__;
460-
no_fmt_expected += "\n441\n****\n";
459+
no_fmt_expected += "\n440\n****\n";
461460

462461
EXPECT_EQ(no_fmt_buffer.str(), no_fmt_expected);
463462

@@ -467,11 +466,17 @@ TEST(slic_macros, test_macros_file_output)
467466

468467
EXPECT_EQ(with_fmt_buffer.str(), "Test");
469468

470-
// Cleanup generated files (not working Windows)
471-
#ifndef WIN32
469+
no_fmt_contents.close();
470+
with_fmt_contents.close();
471+
472+
// Closes open file streams associated with Slic streams when destructors
473+
// called during slic::finalize().
474+
// Windows _unlink file deletion fails if file is still in use.
475+
slic::finalize();
476+
477+
// Cleanup generated files
472478
EXPECT_EQ(axom::utilities::filesystem::removeFile(no_fmt), 0);
473479
EXPECT_EQ(axom::utilities::filesystem::removeFile(with_fmt), 0);
474-
#endif
475480
}
476481

477482
//------------------------------------------------------------------------------

src/axom/slic/tests/slic_macros_parallel.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,7 @@ TEST_P(SlicMacrosParallel, test_macros_file_output)
10791079
std::ifstream no_fmt_contents(no_fmt);
10801080
std::stringstream no_fmt_buffer;
10811081
no_fmt_buffer << no_fmt_contents.rdbuf();
1082+
no_fmt_contents.close();
10821083

10831084
std::string no_fmt_expected;
10841085
no_fmt_expected += "*****\n[INFO]\n\n Test \n\n ";
@@ -1090,6 +1091,7 @@ TEST_P(SlicMacrosParallel, test_macros_file_output)
10901091
std::ifstream with_fmt_contents(with_fmt);
10911092
std::stringstream with_fmt_buffer;
10921093
with_fmt_buffer << with_fmt_contents.rdbuf();
1094+
with_fmt_contents.close();
10931095

10941096
EXPECT_EQ(with_fmt_buffer.str(), "Test");
10951097
}
@@ -1116,6 +1118,7 @@ TEST_P(SlicMacrosParallel, test_macros_file_output)
11161118
std::ifstream no_fmt_output(no_fmt);
11171119
std::stringstream no_fmt_out_buf;
11181120
no_fmt_out_buf << no_fmt_output.rdbuf();
1121+
no_fmt_output.close();
11191122

11201123
std::string no_fmt_output_expected;
11211124
no_fmt_output_expected += "*****\n[INFO]\n\n Test \n\n ";
@@ -1124,13 +1127,14 @@ TEST_P(SlicMacrosParallel, test_macros_file_output)
11241127
no_fmt_output_expected +=
11251128
"*****\n[INFO]\n\n Test outputLocalMessages() \n\n ";
11261129
no_fmt_output_expected += __FILE__;
1127-
no_fmt_output_expected += "\n1107\n****\n";
1130+
no_fmt_output_expected += "\n1109\n****\n";
11281131

11291132
EXPECT_EQ(no_fmt_out_buf.str(), no_fmt_output_expected);
11301133

11311134
std::ifstream with_fmt_output(with_fmt);
11321135
std::stringstream with_fmt_out_buf;
11331136
with_fmt_out_buf << with_fmt_output.rdbuf();
1137+
with_fmt_output.close();
11341138

11351139
EXPECT_EQ(with_fmt_out_buf.str(), "TestTest outputLocalMessages()");
11361140
}
@@ -1141,22 +1145,29 @@ TEST_P(SlicMacrosParallel, test_macros_file_output)
11411145
std::ifstream no_fmt_output(no_fmt);
11421146
std::stringstream no_fmt_out_buf;
11431147
no_fmt_out_buf << no_fmt_output.rdbuf();
1148+
no_fmt_output.close();
11441149

11451150
std::string no_fmt_output_expected;
11461151
no_fmt_output_expected +=
11471152
"*****\n[INFO]\n\n Test outputLocalMessages() \n\n ";
11481153
no_fmt_output_expected += __FILE__;
1149-
no_fmt_output_expected += "\n1107\n****\n";
1154+
no_fmt_output_expected += "\n1109\n****\n";
11501155

11511156
EXPECT_EQ(no_fmt_out_buf.str(), no_fmt_output_expected);
11521157

11531158
std::ifstream with_fmt_output(with_fmt);
11541159
std::stringstream with_fmt_out_buf;
11551160
with_fmt_out_buf << with_fmt_output.rdbuf();
1161+
with_fmt_output.close();
11561162

11571163
EXPECT_EQ(with_fmt_out_buf.str(), "Test outputLocalMessages()");
11581164
}
11591165

1166+
// Closes open file streams associated with Slic streams when destructors
1167+
// called during slic::finalize().
1168+
// Windows _unlink file deletion fails if file is still in use.
1169+
slic::finalize();
1170+
11601171
// Cleanup generated files
11611172
EXPECT_EQ(axom::utilities::filesystem::removeFile(no_fmt), 0);
11621173
EXPECT_EQ(axom::utilities::filesystem::removeFile(with_fmt), 0);

0 commit comments

Comments
 (0)