feat(linear-static-3d-euler-beam): step 8 - core-diagnostics

This commit is contained in:
KOKO\Mimi
2026-08-09 11:11:13 +09:00
parent 639f4082c8
commit 4856f06869
11 changed files with 409 additions and 0 deletions
+3
View File
@@ -3,6 +3,9 @@ include(GoogleTest)
add_executable(
fesa_unit_tests
unit/build_info_test.cpp
unit/core/diagnostic_test.cpp
unit/core/source_identity_test.cpp
unit/core/status_test.cpp
)
target_link_libraries(
+59
View File
@@ -0,0 +1,59 @@
#include "fesa/core/diagnostic.hpp"
#include <gtest/gtest.h>
#include <filesystem>
#include <string>
#include <utility>
#include <vector>
namespace {
fesa::Diagnostic makeDiagnostic(
std::string file,
std::size_t line,
std::string keyword,
std::string entityIdentity,
std::string code,
std::string message) {
return fesa::Diagnostic{
fesa::Severity::error,
std::move(code),
{std::filesystem::path{std::move(file)}, line},
std::move(keyword),
std::move(entityIdentity),
std::move(message)};
}
} // namespace
TEST(CoreDiagnostics, DiagnosticsSortDeterministically) {
std::vector<fesa::Diagnostic> diagnostics{
makeDiagnostic("b.inp", 1U, "*NODE", "I.1", "a", "file-b"),
makeDiagnostic("a.inp", 3U, "*NODE", "I.1", "z", "code-z"),
makeDiagnostic("a.inp", 3U, "*NODE", "I.1", "a", "first-equal"),
makeDiagnostic("a.inp", 3U, "*NODE", "I.1", "a", "second-equal"),
makeDiagnostic("a.inp", 3U, "*NODE", "I.2", "a", "entity-2"),
makeDiagnostic("a.inp", 3U, "*BOUNDARY", "I.1", "a", "keyword"),
makeDiagnostic("a.inp", 2U, "*NODE", "I.1", "a", "line")};
fesa::sortDiagnostics(diagnostics);
ASSERT_EQ(diagnostics.size(), 7U);
EXPECT_EQ(diagnostics[0].message, "line");
EXPECT_EQ(diagnostics[1].message, "keyword");
EXPECT_EQ(diagnostics[2].message, "first-equal");
EXPECT_EQ(diagnostics[3].message, "second-equal");
EXPECT_EQ(diagnostics[4].message, "code-z");
EXPECT_EQ(diagnostics[5].message, "entity-2");
EXPECT_EQ(diagnostics[6].message, "file-b");
const fesa::Diagnostic& exact = diagnostics[2];
EXPECT_EQ(exact.severity, fesa::Severity::error);
EXPECT_EQ(exact.code, "a");
EXPECT_EQ(exact.location.file, std::filesystem::path{"a.inp"});
EXPECT_EQ(exact.location.line, 3U);
EXPECT_EQ(exact.keyword, "*NODE");
EXPECT_EQ(exact.entityIdentity, "I.1");
EXPECT_EQ(exact.message, "first-equal");
}
+20
View File
@@ -0,0 +1,20 @@
#include "fesa/core/source_identity.hpp"
#include <gtest/gtest.h>
#include <cstdint>
#include <filesystem>
#include <string>
TEST(CoreDiagnostics, SourceIdentityPreservesRawIdentity) {
const fesa::SourceLocation location{
std::filesystem::path{"models/My Beam.inp"}, 27U};
const fesa::SourceEntityId identity{
"Beam-Instance_A", std::int64_t{42}, "00042"};
EXPECT_EQ(location.file, std::filesystem::path{"models/My Beam.inp"});
EXPECT_EQ(location.line, 27U);
EXPECT_EQ(identity.instanceName, "Beam-Instance_A");
EXPECT_EQ(identity.sourceLabel, 42);
EXPECT_EQ(identity.sourceLabelText, "00042");
}
+66
View File
@@ -0,0 +1,66 @@
#include "fesa/core/status.hpp"
#include <gtest/gtest.h>
#include <filesystem>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
namespace {
fesa::Diagnostic modelDiagnostic() {
return fesa::Diagnostic{
fesa::Severity::error,
"invalid-beam-length",
{std::filesystem::path{"beam.inp"}, 12U},
"*ELEMENT",
"Beam-1.10",
"Beam length must be positive."};
}
} // namespace
TEST(CoreDiagnostics, ResultEnforcesValueErrorExclusivity) {
const fesa::Status ok = fesa::Status::ok();
EXPECT_TRUE(ok.isOk());
EXPECT_FALSE(ok.failureCategory().has_value());
EXPECT_TRUE(ok.diagnostics().empty());
const fesa::Status uncategorized =
fesa::Status::failure(std::vector<fesa::Diagnostic>{modelDiagnostic()});
EXPECT_FALSE(uncategorized.isOk());
EXPECT_FALSE(uncategorized.failureCategory().has_value());
ASSERT_EQ(uncategorized.diagnostics().size(), 1U);
EXPECT_EQ(uncategorized.diagnostics()[0].code, "invalid-beam-length");
const fesa::Status categorized = fesa::Status::failure(
fesa::FailureCategory::model,
std::vector<fesa::Diagnostic>{modelDiagnostic()});
EXPECT_FALSE(categorized.isOk());
ASSERT_TRUE(categorized.failureCategory().has_value());
EXPECT_EQ(*categorized.failureCategory(), fesa::FailureCategory::model);
const auto success = fesa::Result<std::string>::success("solved");
EXPECT_TRUE(success.hasValue());
EXPECT_TRUE(success.status().isOk());
EXPECT_EQ(success.value(), "solved");
auto copied = success;
EXPECT_EQ(copied.value(), "solved");
auto moved = std::move(copied);
EXPECT_EQ(moved.value(), "solved");
auto failure = fesa::Result<std::string>::failure(categorized);
EXPECT_FALSE(failure.hasValue());
EXPECT_FALSE(failure.status().isOk());
EXPECT_EQ(failure.status().failureCategory(), fesa::FailureCategory::model);
EXPECT_THROW(failure.value(), std::logic_error);
const auto& constFailure = failure;
EXPECT_THROW(constFailure.value(), std::logic_error);
EXPECT_THROW(
(void)fesa::Result<std::string>::failure(fesa::Status::ok()),
std::invalid_argument);
}