Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/analysis-reviewdog-cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ on:
pull_request:
paths:
- "src/**"
- "tests/**/*.cpp"
push:
paths:
- "src/**"
- "tests/**/*.cpp"

jobs:
cppcheck:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ on:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "src/**"
- "tests/**/*.cpp"
merge_group:
push:
paths:
- "src/**"
- "tests/**/*.cpp"
branches:
- main

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ on:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "src/**"
- "tests/**/*.cpp"
merge_group:
push:
paths:
- "src/**"
- "tests/**/*.cpp"
branches:
- main

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ on:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "src/**"
- "tests/**/*.cpp"
merge_group:
push:
paths:
- "src/**"
- "tests/**/*.cpp"
branches:
- main

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-windows-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "src/**"
- "tests/**/*.cpp"
merge_group:
push:
paths:
- "src/**"
- "tests/**/*.cpp"
branches:
- main
env:
Expand Down Expand Up @@ -57,7 +59,7 @@

- name: Restore artifacts and install vcpkg
id: vcpkg-step
run: |

Check failure on line 62 in .github/workflows/build-windows-cmake.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-cmake.yml#L62

shellcheck reported issue in this script: SC2281:error:1:1: Don't use $ on the left side of assignments [shellcheck]
Raw output
e:.github/workflows/build-windows-cmake.yml:62:9: shellcheck reported issue in this script: SC2281:error:1:1: Don't use $ on the left side of assignments [shellcheck]

Check failure on line 62 in .github/workflows/build-windows-cmake.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-cmake.yml#L62

shellcheck reported issue in this script: SC2281:error:2:1: Don't use $ on the left side of assignments [shellcheck]
Raw output
e:.github/workflows/build-windows-cmake.yml:62:9: shellcheck reported issue in this script: SC2281:error:2:1: Don't use $ on the left side of assignments [shellcheck]

Check notice on line 62 in .github/workflows/build-windows-cmake.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-cmake.yml#L62

shellcheck reported issue in this script: SC2086:info:2:16: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
i:.github/workflows/build-windows-cmake.yml:62:9: shellcheck reported issue in this script: SC2086:info:2:16: Double quote to prevent globbing and word splitting [shellcheck]

Check notice on line 62 in .github/workflows/build-windows-cmake.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-cmake.yml#L62

shellcheck reported issue in this script: SC2086:info:4:64: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
i:.github/workflows/build-windows-cmake.yml:62:9: shellcheck reported issue in this script: SC2086:info:4:64: Double quote to prevent globbing and word splitting [shellcheck]
$json=Get-Content vcpkg.json -Raw | ConvertFrom-Json
$vcpkgCommitId=$json.'builtin-baseline'
Write-Host "vcpkg commit ID: $vcpkgCommitId"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-windows-solution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "src/**"
- "tests/**/*.cpp"
merge_group:
push:
paths:
- "src/**"
- "tests/**/*.cpp"
branches:
- main

Expand Down Expand Up @@ -52,7 +54,7 @@
uses: actions/checkout@main

- name: Install vcpkg
run: |

Check failure on line 57 in .github/workflows/build-windows-solution.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-solution.yml#L57

shellcheck reported issue in this script: SC2283:error:1:12: Remove spaces around = to assign (or use [ ] to compare, or quote '=' if literal) [shellcheck]
Raw output
e:.github/workflows/build-windows-solution.yml:57:9: shellcheck reported issue in this script: SC2283:error:1:12: Remove spaces around = to assign (or use [ ] to compare, or quote '=' if literal) [shellcheck]

Check notice on line 57 in .github/workflows/build-windows-solution.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-solution.yml#L57

shellcheck reported issue in this script: SC1001:info:1:27: This \v will be a regular 'v' in this context [shellcheck]
Raw output
i:.github/workflows/build-windows-solution.yml:57:9: shellcheck reported issue in this script: SC1001:info:1:27: This \v will be a regular 'v' in this context [shellcheck]

Check failure on line 57 in .github/workflows/build-windows-solution.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-solution.yml#L57

shellcheck reported issue in this script: SC2283:error:2:16: Remove spaces around = to assign (or use [ ] to compare, or quote '=' if literal) [shellcheck]
Raw output
e:.github/workflows/build-windows-solution.yml:57:9: shellcheck reported issue in this script: SC2283:error:2:16: Remove spaces around = to assign (or use [ ] to compare, or quote '=' if literal) [shellcheck]

Check notice on line 57 in .github/workflows/build-windows-solution.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-solution.yml#L57

shellcheck reported issue in this script: SC2086:info:2:18: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
i:.github/workflows/build-windows-solution.yml:57:9: shellcheck reported issue in this script: SC2086:info:2:18: Double quote to prevent globbing and word splitting [shellcheck]

Check failure on line 57 in .github/workflows/build-windows-solution.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-solution.yml#L57

shellcheck reported issue in this script: SC1036:error:2:52: '(' is invalid here. Did you forget to escape it? [shellcheck]
Raw output
e:.github/workflows/build-windows-solution.yml:57:9: shellcheck reported issue in this script: SC1036:error:2:52: '(' is invalid here. Did you forget to escape it? [shellcheck]

Check failure on line 57 in .github/workflows/build-windows-solution.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-windows-solution.yml#L57

shellcheck reported issue in this script: SC1088:error:2:52: Parsing stopped here. Invalid use of parentheses? [shellcheck]
Raw output
e:.github/workflows/build-windows-solution.yml:57:9: shellcheck reported issue in this script: SC1088:error:2:52: Parsing stopped here. Invalid use of parentheses? [shellcheck]
$vcpkgJson = Get-Content .\vcpkg.json -Raw | ConvertFrom-Json
$vcpkgCommitId = $vcpkgJson.'builtin-baseline'.Trim()
Write-Host "vcpkg commit ID: $vcpkgCommitId"
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/clang-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
pull_request:
paths:
- "src/**"
- "tests/**/*.cpp"
merge_group:
push:
paths:
- "src/**"
- "tests/**/*.cpp"
jobs:
cancel-runs:
if: github.event_name == 'pull_request' && github.ref != 'refs/heads/main'
Expand All @@ -29,7 +31,7 @@

- name: Actions checkout
if: ${{ github.ref != 'refs/heads/main' }}
uses: actions/checkout@v3

Check failure on line 34 in .github/workflows/clang-lint.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/clang-lint.yml#L34

the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue [action]
Raw output
e:.github/workflows/clang-lint.yml:34:15: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue [action]
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
Expand All @@ -39,7 +41,7 @@
if: ${{ github.ref != 'refs/heads/main' }}
uses: DoozyX/[email protected]
with:
source: "src"
source: "src tests"
exclude: "src/protobuf"
extensions: "cpp,hpp,h"
clangFormatVersion: 17
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,9 @@ option(RUN_TESTS_AFTER_BUILD "Run tests when building" OFF) # By default, tests
add_subdirectory(src)

if(BUILD_TESTS OR PACKAGE_TESTS)
log_option_enabled("tests")
add_subdirectory(tests)
add_compile_definitions(BUILD_TESTS)
else()
log_option_disabled("tests")
endif()
27 changes: 17 additions & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,33 @@ enable_testing()
function(setup_test TARGET_NAME DIR)
add_executable(${TARGET_NAME} main.cpp)

target_compile_definitions(${TARGET_NAME} PUBLIC -DDEBUG_LOG)
target_compile_definitions(${TARGET_NAME} PUBLIC -DDEBUG_LOG -DBUILD_TESTS)
target_link_libraries(${TARGET_NAME} PRIVATE Boost::ut ${PROJECT_NAME}_lib)
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/tests/fixture PRIVATE ${CMAKE_SOURCE_DIR}/tests/${DIR})

if(SPEED_UP_BUILD_UNITY AND (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
set_target_properties(${TARGET_NAME} PROPERTIES UNITY_BUILD ON)
log_option_enabled("Build unity for speed up compilation for target ${TARGET_NAME}")
else()
log_option_disabled("Build unity")
endif()
setup_target(${TARGET_NAME})

set_target_properties(${TARGET_NAME} PROPERTIES
UNITY_BUILD OFF
INTERPROCEDURAL_OPTIMIZATION OFF
)
log_option_disabled("Build unity")

configure_linking(${TARGET_NAME})

add_test(NAME ${DIR} COMMAND ${TARGET_NAME})
add_test(NAME ${DIR} COMMAND ${TARGET_NAME} --reporter console --success)
set_tests_properties(${DIR} PROPERTIES
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/${DIR}
ENVIRONMENT "CATCH_CONFIG_CONSOLE_WIDTH=160"
TIMEOUT 120
)

if(RUN_TESTS_AFTER_BUILD)
add_custom_command(
TARGET ${TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_CTEST_COMMAND} --verbose
COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG> --output-on-failure --tests-regex "^${DIR}$"
COMMENT "Running ctest ${DIR} after building ${TARGET_NAME}"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/${DIR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif (RUN_TESTS_AFTER_BUILD)
endfunction()
Expand Down
3 changes: 3 additions & 0 deletions tests/fixture/account/in_memory_account_repository.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ namespace tests {
}

void addAccount(const std::string &descriptor, const AccountInfo &acc) {
phmap::erase_if(accounts, [&](const auto &entry) {
return entry.second.id == acc.id;
});
accounts[descriptor] = acc;
}

Expand Down
14 changes: 7 additions & 7 deletions tests/integration/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ int main() {
std::string database = "otservbr-global";
uint32_t port = 3306;
std::string sock;
};
Database db{};
DbConfig dbConfig{};
};
Database db {};
DbConfig dbConfig {};

db.connect(
&dbConfig.host,
Expand All @@ -70,8 +70,8 @@ int main() {
);

test("AccountRepositoryDB::loadByID") = databaseTest(db, [&db] {
InMemoryLogger logger{};
AccountRepositoryDB accRepo{};
InMemoryLogger logger {};
AccountRepositoryDB accRepo {};
createAccount(db);

auto acc = std::make_unique<AccountInfo>();
Expand Down Expand Up @@ -104,8 +104,8 @@ int main() {
});

test("AccountRepositoryDB load sets premium day purchased = remaining days, if needed") = databaseTest(db, [&db] {
InMemoryLogger logger{};
AccountRepositoryDB accRepo{};
InMemoryLogger logger {};
AccountRepositoryDB accRepo {};

auto acc = std::make_unique<AccountInfo>();
accRepo.loadByID(1, acc);
Expand Down
Loading
Loading