Add a helper class to generate temp paths for tests
This commit is contained in:
parent
b7b2822082
commit
773e7db14d
|
@ -1,11 +1,17 @@
|
|||
include_directories(../external/catch/single_include)
|
||||
include_directories(../external/catch/single_include .)
|
||||
|
||||
set(HEADERS
|
||||
util/test_file.hpp
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
index_set.cpp
|
||||
main.cpp
|
||||
parser.cpp)
|
||||
parser.cpp
|
||||
util/test_file.cpp
|
||||
)
|
||||
|
||||
add_executable(tests ${SOURCES})
|
||||
add_executable(tests ${SOURCES} ${HEADERS})
|
||||
target_link_libraries(tests realm-object-store)
|
||||
|
||||
add_custom_target(run-tests USES_TERMINAL DEPENDS tests COMMAND ./tests)
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#include "util/test_file.hpp"
|
||||
|
||||
#include <realm/disable_sync_to_disk.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
|
||||
TestFile::TestFile()
|
||||
{
|
||||
static std::string tmpdir = [] {
|
||||
realm::disable_sync_to_disk();
|
||||
|
||||
const char* dir = getenv("TMPDIR");
|
||||
if (dir && *dir)
|
||||
return dir;
|
||||
return "/tmp";
|
||||
}();
|
||||
path = tmpdir + "/realm.XXXXXX";
|
||||
mktemp(&path[0]);
|
||||
unlink(path.c_str());
|
||||
}
|
||||
|
||||
TestFile::~TestFile()
|
||||
{
|
||||
unlink(path.c_str());
|
||||
}
|
||||
|
||||
InMemoryTestFile::InMemoryTestFile()
|
||||
{
|
||||
in_memory = true;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef REALM_TEST_UTIL_TEST_FILE_HPP
|
||||
#define REALM_TEST_UTIL_TEST_FILE_HPP
|
||||
|
||||
#include "shared_realm.hpp"
|
||||
|
||||
struct TestFile : realm::Realm::Config {
|
||||
TestFile();
|
||||
~TestFile();
|
||||
};
|
||||
|
||||
struct InMemoryTestFile : TestFile {
|
||||
InMemoryTestFile();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue