Ninja
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.
 
const std::string & path () const
 
void Release ()
 Release the file, the destructor will not remove the file.
 
bool released () const
 
 ScopedFilePath (const char *path)
 
 ScopedFilePath (const std::string &path)
 Constructor just records the file path.
 
 ScopedFilePath (ScopedFilePath &&) noexcept
 Allow move operations.
 
 ~ScopedFilePath ()
 Destructor destroys the file, unless Release() was called.
 

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.

References path(), and path_.

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

◆ ScopedFilePath() [2/3]

ScopedFilePath::ScopedFilePath ( const char * path)
inline

Definition at line 109 of file test.h.

References path(), and path_.

◆ ScopedFilePath() [3/3]

ScopedFilePath::ScopedFilePath ( ScopedFilePath && other)
noexcept

Allow move operations.

Definition at line 240 of file test.cc.

References path_, released_, and ScopedFilePath().

◆ ~ScopedFilePath()

ScopedFilePath::~ScopedFilePath ( )

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

Definition at line 256 of file test.cc.

References path_, platformAwareUnlink(), and released_.

Member Function Documentation

◆ c_str()

const char * ScopedFilePath::c_str ( ) const
inline

Definition at line 121 of file test.h.

References c_str(), and path_.

Referenced by c_str(), TEST_F(), and 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.

References ScopedFilePath().

◆ path()

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

Definition at line 122 of file test.h.

References path_.

Referenced by ScopedFilePath(), and ScopedFilePath().

◆ Release()

void ScopedFilePath::Release ( )

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

Definition at line 262 of file test.cc.

References released_.

◆ 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(), path(), ScopedFilePath(), ScopedFilePath(), ScopedFilePath(), and ~ScopedFilePath().

◆ released_

bool ScopedFilePath::released_ = false
private

Definition at line 127 of file test.h.

Referenced by Release(), released(), ScopedFilePath(), and ~ScopedFilePath().


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