From 3d48f92ac9331eac33fa576bf99c5ddb911d7e6d Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Fri, 5 Jan 2024 13:54:28 +0100 Subject: Factor out TEST_PATH from vespalib::TestMaster. --- vespalib/src/vespa/vespalib/testkit/CMakeLists.txt | 1 + vespalib/src/vespa/vespalib/testkit/test_macros.h | 2 +- .../src/vespa/vespalib/testkit/test_master.cpp | 12 ----------- vespalib/src/vespa/vespalib/testkit/test_master.h | 2 -- vespalib/src/vespa/vespalib/testkit/test_path.cpp | 24 ++++++++++++++++++++++ vespalib/src/vespa/vespalib/testkit/test_path.h | 16 +++++++++++++++ 6 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 vespalib/src/vespa/vespalib/testkit/test_path.cpp create mode 100644 vespalib/src/vespa/vespalib/testkit/test_path.h (limited to 'vespalib') 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:: //----------------------------------------------------------------------------- @@ -170,7 +165,6 @@ TestMaster::reportConclusion(const lock_guard &) TestMaster::TestMaster() : _lock(), _name(""), - _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 > _threadStorage; using lock_guard = std::lock_guard; @@ -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 + +#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); + +} -- cgit v1.2.3