test: finish the temp-file cleanup (#14976)

Follow-up to #14785. Routes the tests that still hand-rolled temp paths through
the shared helpers and unifies the temp guards.

- Add ScopedTemporaryDir and a shared ScopedTemporaryPath base under it and
  ScopedTemporaryFile.
- Move test_3mf's round-trip .3mf output out of the TEST_DATA_DIR source tree
  (a fixed-name leak) and test_toolordering's fixed-name temp .gcode (a sharding
  collision) onto ScopedTemporaryFile.
- Move test_config, test_slicing_pipeline_bindings, the test_3mf backup dirs, and
  test_preset_bundle_loading onto the guards.
- Make slic3rutils ScopedDataDir compose ScopedTemporaryDir; dedupe
  test_network_versions' fixture and delete test_plugin_lifecycle's duplicate.
This commit is contained in:
Kris Austin
2026-08-07 11:33:37 -05:00
committed by GitHub
parent 8bff9aaf32
commit 74aed7a2bb
9 changed files with 106 additions and 153 deletions

View File

@@ -6,6 +6,8 @@
#include <string>
#include "test_utils.hpp"
namespace Slic3r {
// Point data_dir() at a throwaway directory for the lifetime of a test and
@@ -13,24 +15,20 @@ namespace Slic3r {
// disposable tree and tests don't leak state into each other.
struct ScopedDataDir
{
ScopedTemporaryDir tmp; // owns the temp dir (create + recursive remove)
boost::filesystem::path dir; // = tmp.path(); kept as a member for callers
std::string previous;
boost::filesystem::path dir;
explicit ScopedDataDir(const std::string& tag)
: tmp("orca-" + tag), dir(tmp.path()), previous(data_dir())
{
namespace fs = boost::filesystem;
previous = data_dir();
dir = fs::temp_directory_path() / fs::unique_path("orca-" + tag + "-%%%%-%%%%");
fs::create_directories(dir);
set_data_dir(dir.string());
}
~ScopedDataDir()
{
set_data_dir(previous);
boost::system::error_code ec;
boost::filesystem::remove_all(dir, ec);
}
~ScopedDataDir() { set_data_dir(previous); } // tmp removes the directory
// The plugin manager scans {data_dir}/orca_plugins.
boost::filesystem::path plugins_dir() const { return dir / "orca_plugins"; }
ScopedDataDir(const ScopedDataDir&) = delete;
ScopedDataDir& operator=(const ScopedDataDir&) = delete;