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
14 changes: 8 additions & 6 deletions .github/workflows/framework-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
branches:
- main
pull_request:
types: [ opened, edited, reopened ]
types: [ opened, edited, reopened, synchronize ]
jobs:
tests-windows:
runs-on: windows-latest
Expand All @@ -14,22 +14,24 @@ jobs:
- name: Configure and Build
uses: threeal/cmake-action@main
with:
options: "MOSTLY_HARMLESS_TESTS=ON"
build-args: "--target mostly-harmless-tests"
options: "MOSTLY_HARMLESS_TESTS=ON CMAKE_BUILD_TYPE=Release"
build-args: "--target mostly-harmless-tests --config Release"
- name: Run tests
run: "./build/debug/mostly-harmless-tests.exe"
run: "./build/release/mostly-harmless-tests.exe"

tests-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4.1.2
with:
submodules: true
- name: Clean Existing
run: "rm -rf ./build"
- name: Configure and Build
uses: threeal/cmake-action@main
with:
options: "MOSTLY_HARMLESS_TESTS=ON"
build-args: "--target mostly-harmless-tests"
options: "MOSTLY_HARMLESS_TESTS=ON CMAKE_BUILD_TYPE=Release"
build-args: "--target mostly-harmless-tests --config Release"
- name: Run tests
run: "./build/mostly-harmless-tests"

4 changes: 4 additions & 0 deletions include/mostly_harmless/data/mostlyharmless_DatabaseState.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <fmt/core.h>
#include <string>
#include <filesystem>
#include <variant>

namespace mostly_harmless::data {

Expand Down Expand Up @@ -78,6 +79,9 @@ namespace mostly_harmless::data {
}
};

if(!std::filesystem::exists(location.parent_path()) && location.string() != ":memory:") {
throw std::exception{};
}
// Try open existing
if (sqlite3_open_v2(location.string().c_str(), &m_databaseHandle, SQLITE_OPEN_READWRITE, nullptr) != SQLITE_OK) {
checkResult(sqlite3_open(location.string().c_str(), &m_databaseHandle)); // Didn't exist, try create
Expand Down
17 changes: 13 additions & 4 deletions tests/data/mostlyharmless_DatabaseStateTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@

namespace mostly_harmless::testing {
template <bool ShouldSucceed>
auto tryCreateDatabase(const std::filesystem::path& destination, const std::vector<std::pair<std::string, data::DatabaseValueVariant>>& initialValues) {
auto tryCreateDatabase(const std::filesystem::path& destination, const std::vector<std::pair<std::string, data::DatabaseValueVariant>>& initialValues) -> std::optional<data::DatabaseState> {
auto databaseOpt = data::DatabaseState::try_create(destination, initialValues);
REQUIRE(databaseOpt.has_value() == ShouldSucceed);
return std::move(databaseOpt);
if constexpr(!ShouldSucceed) {
REQUIRE(!databaseOpt);
return {};
}
else {
REQUIRE(databaseOpt);
return std::move(databaseOpt);
}
}

TEST_CASE("Test DatabaseState") {
Expand Down Expand Up @@ -53,7 +59,10 @@ namespace mostly_harmless::testing {
std::filesystem::remove(dbFile);
}
SECTION("Test Invalid Location") {
tryCreateDatabase<false>("/iamthelordofthebongo", {});
tryCreateDatabase<false>("INVALID LOCATION", {});
}
SECTION("Test In-Memory") {
tryCreateDatabase<true>(":memory:", {});
}
}

Expand Down