aboutsummaryrefslogtreecommitdiff
path: root/backend/unittests/Support
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 04:30:34 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 04:30:34 +0800
commit81cf8b68eca2636574f3d0a9fa1cf0b428c163e9 (patch)
treef3a83496e71358123cc5f838269dc134d02b63f6 /backend/unittests/Support
parent72af0dedf9e18911da65b9a5c4906689e868d9fc (diff)
downloadrcc-project-81cf8b68eca2636574f3d0a9fa1cf0b428c163e9.tar.gz
rcc-project-81cf8b68eca2636574f3d0a9fa1cf0b428c163e9.tar.xz
[Backend] Establish standalone build infrastructure
Add the thin monorepo CMake entry point and an independently configurable backend project. Enforce the Clang/C++23 toolchain, expose Make/Ninja-neutral tests and developer checks, export an installable RCCBackend package, and introduce the first Support error abstraction.
Diffstat (limited to 'backend/unittests/Support')
-rw-r--r--backend/unittests/Support/CMakeLists.txt16
-rw-r--r--backend/unittests/Support/ErrorTest.cpp33
2 files changed, 49 insertions, 0 deletions
diff --git a/backend/unittests/Support/CMakeLists.txt b/backend/unittests/Support/CMakeLists.txt
new file mode 100644
index 0000000..0c0aabc
--- /dev/null
+++ b/backend/unittests/Support/CMakeLists.txt
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+set(RCCBackendSupportTestSources ErrorTest.cpp)
+
+add_executable(RCCBackendSupportTests ${RCCBackendSupportTestSources})
+rcc_backend_configure_target(RCCBackendSupportTests)
+target_link_libraries(RCCBackendSupportTests PRIVATE RCCBackend::Support)
+
+add_test(NAME RCCBackend.Support.Error COMMAND RCCBackendSupportTests)
+
+rcc_backend_register_format_files(
+ "${CMAKE_CURRENT_SOURCE_DIR}/ErrorTest.cpp"
+)
+rcc_backend_register_tidy_files(
+ "${CMAKE_CURRENT_SOURCE_DIR}/ErrorTest.cpp"
+)
diff --git a/backend/unittests/Support/ErrorTest.cpp b/backend/unittests/Support/ErrorTest.cpp
new file mode 100644
index 0000000..23140e3
--- /dev/null
+++ b/backend/unittests/Support/ErrorTest.cpp
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "rcc/Support/Error.h"
+
+#include <iostream>
+#include <string>
+
+namespace {
+
+int fail(const char *Message) {
+ std::cerr << Message << '\n';
+ return 1;
+}
+
+} // namespace
+
+int main() {
+ rcc::Expected<int> Value = 42;
+ if (!Value || *Value != 42)
+ return fail("Expected must preserve a successful value");
+
+ rcc::Expected<int> Failure = rcc::makeUnexpected(rcc::ErrorCode::ParseError, "bad MIR");
+ if (Failure)
+ return fail("Expected must preserve an error");
+ if (Failure.error().code() != rcc::ErrorCode::ParseError)
+ return fail("Error must preserve its code");
+ if (Failure.error().message() != "bad MIR")
+ return fail("Error must preserve its message");
+ if (rcc::getErrorCodeName(Failure.error().code()) != "parse error")
+ return fail("Error code must have a stable name");
+
+ return 0;
+}