diff options
author | Tor Egge <Tor.Egge@online.no> | 2024-01-05 13:54:28 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2024-01-05 13:54:28 +0100 |
commit | 3d48f92ac9331eac33fa576bf99c5ddb911d7e6d (patch) | |
tree | fb6f549f479e56d7f02112704407d5532e575a75 /vespalib | |
parent | 60ff766692ba9a9431afddd5e3ef09d135b213cf (diff) |
Factor out TEST_PATH from vespalib::TestMaster.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/testkit/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/testkit/test_macros.h | 2 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/testkit/test_master.cpp | 12 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/testkit/test_master.h | 2 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/testkit/test_path.cpp | 24 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/testkit/test_path.h | 16 |
6 files changed, 42 insertions, 15 deletions
diff --git a/vespalib/src/vespa/vespalib/testkit/CMakeLists.txt b/vespalib/src/vespa/vespalib/testkit/CMakeLists.txt index 70423db221b..0ec3754b66d 100644 --- a/vespalib/src/vespa/vespalib/testkit/CMakeLists.txt +++ b/vespalib/src/vespa/vespalib/testkit/CMakeLists.txt @@ -4,6 +4,7 @@ vespa_add_library(vespalib_vespalib_testkit OBJECT test_comparators.cpp test_hook.cpp test_master.cpp + test_path.cpp test_state_guard.cpp testapp.cpp time_bomb.cpp diff --git a/vespalib/src/vespa/vespalib/testkit/test_macros.h b/vespalib/src/vespa/vespalib/testkit/test_macros.h index 214f7c6c1c1..257ca34cae2 100644 --- a/vespalib/src/vespa/vespalib/testkit/test_macros.h +++ b/vespalib/src/vespa/vespalib/testkit/test_macros.h @@ -4,12 +4,12 @@ #include "test_master.h" #include "test_comparators.h" +#include "test_path.h" #define TEST_STR(str) #str #define TEST_CAT_IMPL(a, b) a ## b #define TEST_CAT(a, b) TEST_CAT_IMPL(a, b) #define TEST_MASTER vespalib::TestMaster::master -#define TEST_PATH(local_file) TEST_MASTER.get_path(local_file) #define TEST_DEBUG(lhsFile, rhsFile) TEST_MASTER.openDebugFiles(lhsFile, rhsFile) #define TEST_STATE(msg) vespalib::TestStateGuard TEST_CAT(testStateGuard, __LINE__) (__FILE__, __LINE__, msg) #define TEST_DO(doit) do { TEST_STATE(TEST_STR(doit)); doit; } while(false) diff --git a/vespalib/src/vespa/vespalib/testkit/test_master.cpp b/vespalib/src/vespa/vespalib/testkit/test_master.cpp index a713438c38a..264d4f527a5 100644 --- a/vespalib/src/vespa/vespalib/testkit/test_master.cpp +++ b/vespalib/src/vespa/vespalib/testkit/test_master.cpp @@ -18,11 +18,6 @@ const char *skip_path(const char *file) { return (last == nullptr) ? file : (last + 1); } -std::string get_source_dir() { - const char *dir = getenv("SOURCE_DIRECTORY"); - return (dir ? dir : "."); -} - } // namespace vespalib::<unnamed> //----------------------------------------------------------------------------- @@ -170,7 +165,6 @@ TestMaster::reportConclusion(const lock_guard &) TestMaster::TestMaster() : _lock(), _name("<unnamed>"), - _path_prefix(get_source_dir() + "/"), _state(), _threadStorage() { @@ -195,12 +189,6 @@ TestMaster::getName() return _name; } -std::string -TestMaster::get_path(const std::string &local_file) -{ - return (_path_prefix + local_file); -} - void TestMaster::setThreadName(const char *name) { diff --git a/vespalib/src/vespa/vespalib/testkit/test_master.h b/vespalib/src/vespa/vespalib/testkit/test_master.h index 40ce9be3dc6..cd73103c49f 100644 --- a/vespalib/src/vespa/vespalib/testkit/test_master.h +++ b/vespalib/src/vespa/vespalib/testkit/test_master.h @@ -73,7 +73,6 @@ private: private: std::mutex _lock; std::string _name; - std::string _path_prefix; SharedState _state; std::vector<std::unique_ptr<ThreadState> > _threadStorage; using lock_guard = std::lock_guard<std::mutex>; @@ -97,7 +96,6 @@ private: public: void init(const char *name); std::string getName(); - std::string get_path(const std::string &local_file); void setThreadName(const char *name); const char *getThreadName(); void setThreadUnwind(bool unwind); diff --git a/vespalib/src/vespa/vespalib/testkit/test_path.cpp b/vespalib/src/vespa/vespalib/testkit/test_path.cpp new file mode 100644 index 00000000000..958a06449da --- /dev/null +++ b/vespalib/src/vespa/vespalib/testkit/test_path.cpp @@ -0,0 +1,24 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "test_path.h" + +namespace vespalib::testkit { + +namespace { + +std::string get_source_dir() { + const char *dir = getenv("SOURCE_DIRECTORY"); + return (dir ? dir : "."); +} + +std::string path_prefix = get_source_dir() + "/"; + +} + +std::string +test_path(const std::string &local_file) +{ + return path_prefix + local_file; +} + +} diff --git a/vespalib/src/vespa/vespalib/testkit/test_path.h b/vespalib/src/vespa/vespalib/testkit/test_path.h new file mode 100644 index 00000000000..526854cb9bb --- /dev/null +++ b/vespalib/src/vespa/vespalib/testkit/test_path.h @@ -0,0 +1,16 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <string> + +#define TEST_PATH(local_file) vespalib::testkit::test_path(local_file) + +namespace vespalib::testkit { + +/* + * Return the path to a test file. + */ +std::string test_path(const std::string& local_file); + +} |