diff options
| author | Stefan Boberg <[email protected]> | 2021-09-19 18:36:50 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-19 18:36:50 +0200 |
| commit | f920793c7585a11c60346d306108f90368878d32 (patch) | |
| tree | 9c246fb3dba5556ff9e6a24e1cb270051ae7a43b /zencore/include | |
| parent | Changed BasicFile implementation (diff) | |
| download | zen-f920793c7585a11c60346d306108f90368878d32.tar.xz zen-f920793c7585a11c60346d306108f90368878d32.zip | |
Added testutils for use in writing tests
Currently contains helpers for managing temporary directories used in tests
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/testutils.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/zencore/include/zencore/testutils.h b/zencore/include/zencore/testutils.h new file mode 100644 index 000000000..72d985d5c --- /dev/null +++ b/zencore/include/zencore/testutils.h @@ -0,0 +1,31 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include <filesystem> + +namespace zen { + +std::filesystem::path CreateTemporaryDirectory(); + +class ScopedTemporaryDirectory +{ +public: + ScopedTemporaryDirectory(); + ~ScopedTemporaryDirectory(); + + std::filesystem::path& Path() { return m_RootPath; } + +private: + std::filesystem::path m_RootPath; +}; + +struct ScopedCurrentDirectoryChange +{ + std::filesystem::path OldPath{std::filesystem::current_path()}; + + ScopedCurrentDirectoryChange() { std::filesystem::current_path(CreateTemporaryDirectory()); } + ~ScopedCurrentDirectoryChange() { std::filesystem::current_path(OldPath); } +}; + +} // namespace zen |