solidity/test/TemporaryDirectory.h

53 lines
1.5 KiB
C
Raw Normal View History

/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
/**
* Utility for creating temporary directories for use in tests.
*/
#pragma once
#include <string>
namespace solidity::test
{
/**
* An object that creates a unique temporary directory and automatically deletes it and its
* content upon being destroyed.
*
* The directory is guaranteed to be newly created and empty. Directory names are generated
* randomly. If a directory with the same name already exists (very unlikely but possible) the
* object won't reuse it and will fail with an exception instead.
*/
class TemporaryDirectory
{
public:
TemporaryDirectory(std::string const& _prefix = "solidity-test-");
~TemporaryDirectory();
std::string const& path() const { return m_path; }
/// Converts a path relative to the directory held by the object into an absolute one.
std::string memberPath(std::string const& _relativePath) const;
private:
std::string m_path;
};
}