KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KI_TEST::SCOPED_TEMP_DIR Class Reference

#include <file_utils.h>

Public Member Functions

 SCOPED_TEMP_DIR (const wxString &aPrefix)
 Create a temporary directory with a unique name based on the given prefix.
 
 ~SCOPED_TEMP_DIR ()
 
 SCOPED_TEMP_DIR (const SCOPED_TEMP_DIR &)=delete
 
SCOPED_TEMP_DIRoperator= (const SCOPED_TEMP_DIR &)=delete
 
const std::filesystem::path & Path () const
 Get the path to the temporary directory as a std::filesystem::path.
 
wxString PathStr () const
 Get the path to the temporary directory as a wxString.
 
wxString ChildPathStr (const wxString &aName) const
 Get the path to a direct child of the temporary directory as a wxString, without creating the child.
 
std::filesystem::path CreateChildDir (const wxString &aName) const
 Create and return the path to a direct child directory.
 
wxString CreateChildDirStr (const wxString &aName) const
 Create and return the path to a direct child directory as a wxString.
 
std::filesystem::path CreateChildFile (const wxString &aName) const
 Create and return the path to a direct child file.
 
wxString CreateChildFileStr (const wxString &aName) const
 Create and return the path to a direct child file as a wxString.
 
void Retain ()
 Keep this directory after all.
 

Static Public Member Functions

static bool AnyTempDirRetained ()
 

Private Attributes

std::filesystem::path m_path
 
bool m_keep = false
 

Static Private Attributes

static bool s_anyTempDirRetained = false
 

Detailed Description

Definition at line 37 of file file_utils.h.

Constructor & Destructor Documentation

◆ SCOPED_TEMP_DIR() [1/2]

SCOPED_TEMP_DIR::SCOPED_TEMP_DIR ( const wxString & aPrefix)

Create a temporary directory with a unique name based on the given prefix.

The directory is removed on destruction unless the environment variable KICAD_QA_KEEP_TEMP, when interpreted as a comma-separated list of prefixes, contains the given prefix. The special value "ALL" will keep all temporary directories created by this class.

Parameters
aPrefixPrefix for the temporary directory name

Definition at line 103 of file file_utils.cpp.

References createTempDir(), m_keep, m_path, s_anyTempDirRetained, and shouldKeepTemp().

Referenced by operator=(), and SCOPED_TEMP_DIR().

◆ ~SCOPED_TEMP_DIR()

SCOPED_TEMP_DIR::~SCOPED_TEMP_DIR ( )

Definition at line 112 of file file_utils.cpp.

References m_keep, m_path, and reportTempDir().

◆ SCOPED_TEMP_DIR() [2/2]

KI_TEST::SCOPED_TEMP_DIR::SCOPED_TEMP_DIR ( const SCOPED_TEMP_DIR & )
delete

References SCOPED_TEMP_DIR().

Member Function Documentation

◆ AnyTempDirRetained()

static bool KI_TEST::SCOPED_TEMP_DIR::AnyTempDirRetained ( )
inlinestatic

◆ ChildPathStr()

wxString SCOPED_TEMP_DIR::ChildPathStr ( const wxString & aName) const

Get the path to a direct child of the temporary directory as a wxString, without creating the child.

Note you don't need a ChildPath() as you can just use Path() / "childname" to get a std::filesystem::path.

Also note that this is the easiest/less-racy way to get a temp file with a given extension rather than using wxFileName::CreateTempFileName() and then renaming it, which is easy to leak or race.

Parameters
aNameName of the child file or directory, must be a single path component
Exceptions
std::invalid_argumentif aName is not a single path component

Definition at line 139 of file file_utils.cpp.

References m_path.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), and RasterizePdfCountDark().

◆ CreateChildDir()

std::filesystem::path SCOPED_TEMP_DIR::CreateChildDir ( const wxString & aName) const

◆ CreateChildDirStr()

wxString SCOPED_TEMP_DIR::CreateChildDirStr ( const wxString & aName) const

Create and return the path to a direct child directory as a wxString.

Exceptions
std::runtime_errorif the directory cannot be created

Definition at line 156 of file file_utils.cpp.

References CreateChildDir().

Referenced by BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), and BOOST_FIXTURE_TEST_CASE().

◆ CreateChildFile()

std::filesystem::path SCOPED_TEMP_DIR::CreateChildFile ( const wxString & aName) const

Create and return the path to a direct child file.

Exceptions
std::runtime_errorif the file cannot be created

Definition at line 162 of file file_utils.cpp.

References m_path.

Referenced by CreateChildFileStr().

◆ CreateChildFileStr()

◆ operator=()

SCOPED_TEMP_DIR & KI_TEST::SCOPED_TEMP_DIR::operator= ( const SCOPED_TEMP_DIR & )
delete

References SCOPED_TEMP_DIR().

◆ Path()

◆ PathStr()

◆ Retain()

void SCOPED_TEMP_DIR::Retain ( )

Keep this directory after all.

It is nearly always wrong to use this in actual tests, but it can be helpful for debugging purposes (e.g. conditionally keeping the directory if a certain test fails).

If a SCOPED_PROCESS_TEMP_DIR is in use, the process-wide temporary directory is kept as well.

Definition at line 129 of file file_utils.cpp.

References m_keep, m_path, reportTempDir(), and s_anyTempDirRetained.

Member Data Documentation

◆ m_keep

bool KI_TEST::SCOPED_TEMP_DIR::m_keep = false
private

Definition at line 124 of file file_utils.h.

Referenced by Retain(), SCOPED_TEMP_DIR(), and ~SCOPED_TEMP_DIR().

◆ m_path

std::filesystem::path KI_TEST::SCOPED_TEMP_DIR::m_path
private

◆ s_anyTempDirRetained

bool SCOPED_TEMP_DIR::s_anyTempDirRetained = false
staticprivate

Definition at line 127 of file file_utils.h.

Referenced by AnyTempDirRetained(), Retain(), and SCOPED_TEMP_DIR().


The documentation for this class was generated from the following files: