Ninja
Public Member Functions | Private Attributes | List of all members
ScopedFilePath Struct Reference

A class that records a file path and ensures that it is removed on destruction. More...

#include <test.h>

Public Member Functions

const char * c_str () const
 
ScopedFilePathoperator= (ScopedFilePath &&) noexcept
 It would be nice to use '= default' here instead but some old compilers such as GCC from Ubuntu 16.06 will not compile it with "noexcept", so just write it manually. More...
 
const std::string & path () const
 
void Release ()
 Release the file, the destructor will not remove the file. More...
 
bool released () const
 
 ScopedFilePath (const char *path)
 
 ScopedFilePath (const std::string &path)
 Constructor just records the file path. More...
 
 ScopedFilePath (ScopedFilePath &&) noexcept
 Allow move operations. More...
 
 ~ScopedFilePath ()
 Destructor destroys the file, unless Release() was called. More...
 

Private Attributes

std::string path_
 
bool released_ = false
 

Detailed Description

A class that records a file path and ensures that it is removed on destruction.

This ensures that tests do not keep stale files in the current directory where they run, even in case of assertion failure.

Definition at line 106 of file test.h.

Constructor & Destructor Documentation

◆ ScopedFilePath() [1/3]

ScopedFilePath::ScopedFilePath ( const std::string &  path)
inline

Constructor just records the file path.

Definition at line 108 of file test.h.

◆ ScopedFilePath() [2/3]

ScopedFilePath::ScopedFilePath ( const char *  path)
inline

Definition at line 109 of file test.h.

◆ ScopedFilePath() [3/3]

ScopedFilePath::ScopedFilePath ( ScopedFilePath &&  other)
noexcept

Allow move operations.

Definition at line 240 of file test.cc.

◆ ~ScopedFilePath()

ScopedFilePath::~ScopedFilePath ( )

Destructor destroys the file, unless Release() was called.

Definition at line 256 of file test.cc.

References platformAwareUnlink().

Member Function Documentation

◆ c_str()

const char* ScopedFilePath::c_str ( ) const
inline

Definition at line 121 of file test.h.

References path_.

Referenced by TEST_F().

◆ operator=()

ScopedFilePath & ScopedFilePath::operator= ( ScopedFilePath &&  other)
noexcept

It would be nice to use '= default' here instead but some old compilers such as GCC from Ubuntu 16.06 will not compile it with "noexcept", so just write it manually.

Definition at line 248 of file test.cc.

◆ path()

const std::string& ScopedFilePath::path ( ) const
inline

Definition at line 122 of file test.h.

References path_.

◆ Release()

void ScopedFilePath::Release ( )

Release the file, the destructor will not remove the file.

Definition at line 262 of file test.cc.

◆ released()

bool ScopedFilePath::released ( ) const
inline

Definition at line 123 of file test.h.

References released_.

Member Data Documentation

◆ path_

std::string ScopedFilePath::path_
private

Definition at line 126 of file test.h.

Referenced by c_str(), and path().

◆ released_

bool ScopedFilePath::released_ = false
private

Definition at line 127 of file test.h.

Referenced by released().


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