Skip to content

Commit

Permalink
Merge pull request #1424 from LLNL/bugfix/han12/removeFile_Windows
Browse files Browse the repository at this point in the history
removeFile() Usage
  • Loading branch information
rhornung67 authored Sep 25, 2024
2 parents 24751dd + e528819 commit d290434
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/axom/mint/tests/mint_su2_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ TEST(mint_su2_io, write_read_mixed_cell_topology_mesh)

// cleanup
delete test_mesh;
axom::utilities::filesystem::removeFile(su2File);
EXPECT_EQ(axom::utilities::filesystem::removeFile(su2File), 0);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -212,7 +212,7 @@ TEST(mint_su2_io, write_read_single_cell_topology_mesh)

// cleanup
delete test_mesh;
axom::utilities::filesystem::removeFile(su2File);
EXPECT_EQ(axom::utilities::filesystem::removeFile(su2File), 0);
}

//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/axom/mint/tests/mint_util_write_vtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ void test_mesh(MeshType* mesh, const std::string& path)
file.close();
delete mesh;
#if DELETE_VTK_FILES
axom::utilities::filesystem::removeFile(path);
EXPECT_EQ(axom::utilities::filesystem::removeFile(path), 0);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/axom/quest/tests/quest_intersection_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void IntersectionWithErrorTolerances(const std::string &filebase,
// Clean up files.
for(const auto &filename : filenames)
{
axom::utilities::filesystem::removeFile(filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/axom/quest/tests/quest_pro_e_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TEST(quest_pro_e_reader, read_to_invalid_mesh)
EXPECT_DEATH_IF_SUPPORTED(reader.getMesh(&hexmesh), IGNORE_OUTPUT);

// STEP 4: remove Pro/E file
axom::utilities::filesystem::removeFile(filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -143,7 +143,7 @@ TEST(quest_pro_e_reader, read_pro_e)
} // END for all nodes

// STEP 4: remove temporary Pro/E file
axom::utilities::filesystem::removeFile(filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -197,7 +197,7 @@ TEST(quest_pro_e_reader, read_pro_e_invbbox)
} // END for all nodes

// STEP 4: remove temporary Pro/E file
axom::utilities::filesystem::removeFile(filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -253,7 +253,7 @@ TEST(quest_pro_e_reader, read_pro_e_bbox_all)
} // END for all nodes

// STEP 4: remove temporary Pro/E file
axom::utilities::filesystem::removeFile(filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -310,7 +310,7 @@ TEST(quest_pro_e_reader, read_pro_e_bbox_some)
} // END for all nodes

// STEP 4: remove temporary Pro/E file
axom::utilities::filesystem::removeFile(filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -367,7 +367,7 @@ TEST(quest_pro_e_reader, read_pro_e_bbox_some_incl)
} // END for all nodes

// STEP 4: remove temporary Pro/E file
axom::utilities::filesystem::removeFile(filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -426,7 +426,7 @@ TEST(quest_pro_e_reader, read_pro_e_external)
} // END for all nodes

// STEP 4: remove temporary Pro/E file
axom::utilities::filesystem::removeFile(filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
}

#ifdef AXOM_DATA_DIR
Expand Down
2 changes: 1 addition & 1 deletion src/axom/quest/tests/quest_sampling_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ScopedTemporaryFile

~ScopedTemporaryFile()
{
axom::utilities::filesystem::removeFile(m_filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(m_filename), 0);
}

const std::string& getFileName() const { return m_filename; }
Expand Down
4 changes: 2 additions & 2 deletions src/axom/quest/tests/quest_signed_distance_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void check_analytic_plane(bool use_shared = false)
EXPECT_FALSE(quest::signed_distance_initialized());

#ifdef REMOVE_FILES
axom::utilities::filesystem::removeFile(file);
EXPECT_EQ(axom::utilities::filesystem::removeFile(file), 0);
#endif
}

Expand Down Expand Up @@ -373,7 +373,7 @@ TEST(quest_signed_distance_interface, initialize)

// remove temp STL file
#ifdef REMOVE_FILES
axom::utilities::filesystem::removeFile(fileName);
EXPECT_EQ(axom::utilities::filesystem::removeFile(fileName), 0);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/axom/quest/tests/quest_stl_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ TEST(quest_stl_reader_DeathTest, read_to_invalid_mesh)
EXPECT_DEATH_IF_SUPPORTED(reader.getMesh(&hexmesh), IGNORE_OUTPUT);

// STEP 4: remove STL file
axom::utilities::filesystem::removeFile(filename);
EXPECT_EQ(axom::utilities::filesystem::removeFile(filename), 0);
}

//------------------------------------------------------------------------------
Expand Down
15 changes: 10 additions & 5 deletions src/axom/slic/tests/slic_macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ TEST(slic_macros, test_macros_file_output)
std::string with_fmt = "file_with_fmt.txt";

slic::addStreamToAllMsgLevels(new slic::GenericOutputStream(no_fmt));

slic::addStreamToAllMsgLevels(new slic::GenericOutputStream(with_fmt, msgfmt));

EXPECT_FALSE(axom::utilities::filesystem::pathExists(no_fmt));
Expand Down Expand Up @@ -457,7 +456,7 @@ TEST(slic_macros, test_macros_file_output)
std::string no_fmt_expected;
no_fmt_expected += "*****\n[INFO]\n\n Test \n\n ";
no_fmt_expected += __FILE__;
no_fmt_expected += "\n441\n****\n";
no_fmt_expected += "\n440\n****\n";

EXPECT_EQ(no_fmt_buffer.str(), no_fmt_expected);

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

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

// Cleanup generated files (not working Windows)
#ifndef WIN32
no_fmt_contents.close();
with_fmt_contents.close();

// Closes open file streams associated with Slic streams when destructors
// called during slic::finalize().
// Windows _unlink file deletion fails if file is still in use.
slic::finalize();

// Cleanup generated files
EXPECT_EQ(axom::utilities::filesystem::removeFile(no_fmt), 0);
EXPECT_EQ(axom::utilities::filesystem::removeFile(with_fmt), 0);
#endif
}

//------------------------------------------------------------------------------
Expand Down
15 changes: 13 additions & 2 deletions src/axom/slic/tests/slic_macros_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ TEST_P(SlicMacrosParallel, test_macros_file_output)
std::ifstream no_fmt_contents(no_fmt);
std::stringstream no_fmt_buffer;
no_fmt_buffer << no_fmt_contents.rdbuf();
no_fmt_contents.close();

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

EXPECT_EQ(with_fmt_buffer.str(), "Test");
}
Expand All @@ -1116,6 +1118,7 @@ TEST_P(SlicMacrosParallel, test_macros_file_output)
std::ifstream no_fmt_output(no_fmt);
std::stringstream no_fmt_out_buf;
no_fmt_out_buf << no_fmt_output.rdbuf();
no_fmt_output.close();

std::string no_fmt_output_expected;
no_fmt_output_expected += "*****\n[INFO]\n\n Test \n\n ";
Expand All @@ -1124,13 +1127,14 @@ TEST_P(SlicMacrosParallel, test_macros_file_output)
no_fmt_output_expected +=
"*****\n[INFO]\n\n Test outputLocalMessages() \n\n ";
no_fmt_output_expected += __FILE__;
no_fmt_output_expected += "\n1107\n****\n";
no_fmt_output_expected += "\n1109\n****\n";

EXPECT_EQ(no_fmt_out_buf.str(), no_fmt_output_expected);

std::ifstream with_fmt_output(with_fmt);
std::stringstream with_fmt_out_buf;
with_fmt_out_buf << with_fmt_output.rdbuf();
with_fmt_output.close();

EXPECT_EQ(with_fmt_out_buf.str(), "TestTest outputLocalMessages()");
}
Expand All @@ -1141,22 +1145,29 @@ TEST_P(SlicMacrosParallel, test_macros_file_output)
std::ifstream no_fmt_output(no_fmt);
std::stringstream no_fmt_out_buf;
no_fmt_out_buf << no_fmt_output.rdbuf();
no_fmt_output.close();

std::string no_fmt_output_expected;
no_fmt_output_expected +=
"*****\n[INFO]\n\n Test outputLocalMessages() \n\n ";
no_fmt_output_expected += __FILE__;
no_fmt_output_expected += "\n1107\n****\n";
no_fmt_output_expected += "\n1109\n****\n";

EXPECT_EQ(no_fmt_out_buf.str(), no_fmt_output_expected);

std::ifstream with_fmt_output(with_fmt);
std::stringstream with_fmt_out_buf;
with_fmt_out_buf << with_fmt_output.rdbuf();
with_fmt_output.close();

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

// Closes open file streams associated with Slic streams when destructors
// called during slic::finalize().
// Windows _unlink file deletion fails if file is still in use.
slic::finalize();

// Cleanup generated files
EXPECT_EQ(axom::utilities::filesystem::removeFile(no_fmt), 0);
EXPECT_EQ(axom::utilities::filesystem::removeFile(with_fmt), 0);
Expand Down

0 comments on commit d290434

Please sign in to comment.