Skip to content

Commit

Permalink
ci: Add test files into lint and format the test files
Browse files Browse the repository at this point in the history
  • Loading branch information
sitaowang1998 committed Nov 6, 2024
1 parent 044ce09 commit b0232a1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
10 changes: 10 additions & 0 deletions lint-tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ tasks:
- "{{.G_SRC_SPIDER_DIR}}/**/*.cpp"
- "{{.G_SRC_SPIDER_DIR}}/**/*.h"
- "{{.G_SRC_SPIDER_DIR}}/**/*.hpp"
- "{{.G_TEST_DIR}}/**/*.cpp"
- "{{.G_TEST_DIR}}/**/*.h"
- "{{.G_TEST_DIR}}/**/*.hpp"
- "{{.TASKFILE}}"
- "tools/yscope-dev-utils/lint-configs/.clang-format"
deps: ["cpp-configs", "venv"]
Expand All @@ -67,6 +70,10 @@ tasks:
vars:
FLAGS: "-i"
SRC_DIR: "{{.G_SRC_SPIDER_DIR}}"
- task: "clang-format"
vars:
FLAGS: "-i"
SRC_DIR: "{{.G_TEST_DIR}}"

cpp-static-check:
# Alias task to `cpp-static-fix` since we don't currently support automatic fixes.
Expand All @@ -79,6 +86,9 @@ tasks:
- "{{.G_SRC_SPIDER_DIR}}/**/*.cpp"
- "{{.G_SRC_SPIDER_DIR}}/**/*.h"
- "{{.G_SRC_SPIDER_DIR}}/**/*.hpp"
- "{{.G_TEST_DIR}}/**/*.cpp"
- "{{.G_TEST_DIR}}/**/*.h"
- "{{.G_TEST_DIR}}/**/*.hpp"
- "{{.G_SPIDER_CMAKE_CACHE}}"
- "{{.G_SPIDER_COMPILE_COMMANDS_DB}}"
- "{{.TASKFILE}}"
Expand Down
7 changes: 4 additions & 3 deletions tests/storage/StorageTestHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#define SPIDER_TEST_STORAGETETHELPER_HPP

namespace spider::test {
char const* const cStorageUrl = "jdbc:mariadb://localhost:3306/spider_test?user=root&password=password";
}
char const* const cStorageUrl
= "jdbc:mariadb://localhost:3306/spider_test?user=root&password=password";
} // namespace spider::test

#endif // SPIDER_TEST_STORAGETETHELPER_HPP
#endif // SPIDER_TEST_STORAGETETHELPER_HPP
30 changes: 17 additions & 13 deletions tests/storage/test-DataStorage.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
// NOLINTBEGIN(cert-err58-cpp,cppcoreguidelines-avoid-do-while,readability-function-cognitive-complexity)
#include "../../src/spider/core/Data.hpp"
#include "../../src/spider/core/Error.hpp"
#include "../../src/spider/storage/DataStorage.hpp"
#include "../../src/spider/storage/MysqlStorage.hpp"
#include "../../src/spider/core/Error.hpp"
#include "../../src/spider/core/Data.hpp"

#include <concepts>
#include <memory>
#include "../utils/CoreDataUtils.hpp"
#include "StorageTestHelper.hpp"

#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>

#include "StorageTestHelper.hpp"
#include "../utils/CoreDataUtils.hpp"
#include <concepts>
#include <memory>

namespace {
template <class T>
requires std::derived_from<T, spider::core::DataStorage>
auto create_data_storage() -> std::unique_ptr<spider::core::DataStorage> {
return std::unique_ptr<spider::core::DataStorage>(static_cast<spider::core::DataStorage*>(new T()));
return std::unique_ptr<spider::core::DataStorage>(static_cast<spider::core::DataStorage*>(new T(
)));
}


TEMPLATE_TEST_CASE("Add, get and remove data", "[storage]", spider::core::MySqlDataStorage) {
std::unique_ptr<spider::core::DataStorage> storage = create_data_storage<TestType>();
REQUIRE(storage->connect(spider::test::cStorageUrl).success());
Expand All @@ -43,10 +41,15 @@ TEMPLATE_TEST_CASE("Add, get and remove data", "[storage]", spider::core::MySqlD
REQUIRE(storage->remove_data(data.get_id()).success());

// Get data should fail
REQUIRE(spider::core::StorageErrType::KeyNotFoundErr == storage->get_data(data.get_id(), &result).type);
REQUIRE(spider::core::StorageErrType::KeyNotFoundErr
== storage->get_data(data.get_id(), &result).type);
}

TEMPLATE_TEST_CASE("Add, get and remove data with key", "[storage]", spider::core::MySqlDataStorage) {
TEMPLATE_TEST_CASE(
"Add, get and remove data with key",
"[storage]",
spider::core::MySqlDataStorage
) {
std::unique_ptr<spider::core::DataStorage> storage = create_data_storage<TestType>();
REQUIRE(storage->connect(spider::test::cStorageUrl).success());
REQUIRE(storage->initialize().success());
Expand All @@ -71,5 +74,6 @@ TEMPLATE_TEST_CASE("Add, get and remove data with key", "[storage]", spider::cor
REQUIRE(spider::core::StorageErrType::KeyNotFoundErr
== storage->get_data_by_key("key", &result).type);
}
}
} // namespace

// NOLINTEND(cert-err58-cpp,cppcoreguidelines-avoid-do-while,readability-function-cognitive-complexity)
2 changes: 1 addition & 1 deletion tests/utils/CoreDataUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ inline auto data_equal(Data const& d1, Data const& d2) -> bool {
return true;
}

}
} // namespace spider::core

0 comments on commit b0232a1

Please sign in to comment.