unit-tests: modernize
Use TempDir, join_paths etc.
This commit is contained in:
@ -189,14 +189,16 @@ Logger::~Logger()
|
||||
#include <atomic>
|
||||
|
||||
#include "mu-test-utils.hh"
|
||||
#include "mu-utils-file.hh"
|
||||
|
||||
static void
|
||||
test_logger_threads(void)
|
||||
{
|
||||
const auto testpath{test_random_tmpdir() + "/test.log"};
|
||||
TempDir temp_dir;
|
||||
const auto testpath{join_paths(temp_dir.path(), "test.log")};
|
||||
mu_message("log-file: {}", testpath);
|
||||
|
||||
auto logger = Logger::make(testpath.c_str(), Logger::Options::File | Logger::Options::Debug);
|
||||
auto logger = Logger::make(testpath, Logger::Options::File | Logger::Options::Debug);
|
||||
assert_valid_result(logger);
|
||||
|
||||
const auto thread_num = 16;
|
||||
|
||||
@ -34,25 +34,15 @@
|
||||
#include "utils/mu-utils-file.hh"
|
||||
#include "utils/mu-error.hh"
|
||||
|
||||
|
||||
using namespace Mu;
|
||||
|
||||
std::string
|
||||
Mu::test_random_tmpdir()
|
||||
bool
|
||||
Mu::mu_test_mu_hacker()
|
||||
{
|
||||
auto&& dir = mu_format("{}{}mu-test-{}{}test-{:x}",
|
||||
g_get_tmp_dir(),
|
||||
G_DIR_SEPARATOR,
|
||||
getuid(),
|
||||
G_DIR_SEPARATOR,
|
||||
::random() * getpid() * ::time({}));
|
||||
|
||||
auto res = g_mkdir_with_parents(dir.c_str(), 0700);
|
||||
g_assert(res != -1);
|
||||
|
||||
return dir;
|
||||
return !!g_getenv("MU_HACKER");
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
Mu::set_tz(const char* tz)
|
||||
{
|
||||
@ -92,11 +82,11 @@ black_hole(void)
|
||||
void
|
||||
Mu::mu_test_init(int *argc, char ***argv)
|
||||
{
|
||||
const auto tmpdir{test_random_tmpdir()};
|
||||
TempDir temp_dir;
|
||||
|
||||
g_unsetenv("XAPIAN_CJK_NGRAM");
|
||||
g_setenv("MU_TEST", "yes", TRUE);
|
||||
g_setenv("XDG_CACHE_HOME", tmpdir.c_str(), TRUE);
|
||||
g_setenv("XDG_CACHE_HOME", temp_dir.path().c_str(), TRUE);
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
|
||||
@ -27,17 +27,6 @@
|
||||
|
||||
namespace Mu {
|
||||
|
||||
/**
|
||||
* get a dir name for a random temporary directory to do tests
|
||||
*
|
||||
* @return a random dir name
|
||||
*/
|
||||
std::string test_random_tmpdir(void);
|
||||
|
||||
inline gchar* test_mu_common_get_random_tmpdir() {
|
||||
return g_strdup(test_random_tmpdir().c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* mu wrapper for g_test_init. Sets environment variable MU_TEST to 1.
|
||||
*
|
||||
@ -46,6 +35,14 @@ inline gchar* test_mu_common_get_random_tmpdir() {
|
||||
*/
|
||||
void mu_test_init(int *argc, char ***argv);
|
||||
|
||||
|
||||
/**
|
||||
* Are we running in a MU_HACKER environment?
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
bool mu_test_mu_hacker();
|
||||
|
||||
/**
|
||||
* set the timezone
|
||||
*
|
||||
@ -62,6 +59,7 @@ const char* set_tz(const char* tz);
|
||||
*/
|
||||
bool set_en_us_utf8_locale();
|
||||
|
||||
|
||||
/**
|
||||
* For unit tests, assert two std::string's are equal.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user