From c9060c7f2d41a372600fc73f0de50ee9b1eb48b7 Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Sun, 16 Feb 2025 15:29:16 +0100 Subject: [PATCH] Increase test coverage (#1661) --- include/file.hpp | 18 +----------------- src/asm/rpn.cpp | 6 ++++-- test/asm/const-and.asm | 3 +++ test/asm/const-and.err | 4 +++- test/asm/const-and.out | 1 + 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/include/file.hpp b/include/file.hpp index 57a00757..aee0e969 100644 --- a/include/file.hpp +++ b/include/file.hpp @@ -18,12 +18,10 @@ #include "gfx/main.hpp" class File { - // Construct a `std::streambuf *` by default, since it's probably lighter than a `filebuf`. Either _file; public: - File() {} - ~File() { close(); } + File() : _file(nullptr) {} // This should only be called once, and before doing any `->` operations. // Returns `nullptr` on error, and a non-null pointer otherwise. @@ -61,20 +59,6 @@ public: return const_cast(this)->operator->(); } - File *close() { - if (_file.holds()) { - // This is called by the destructor, and an explicit `close` shouldn't close twice. - std::filebuf fileBuf = std::move(_file.get()); - _file.emplace(nullptr); - if (fileBuf.close() != nullptr) { - return this; - } - } else if (_file.get() != nullptr) { - return this; - } - return nullptr; - } - char const *c_str(std::string const &path) const { return _file.holds() ? path.c_str() : _file.get() == std::cin.rdbuf() ? "" diff --git a/src/asm/rpn.cpp b/src/asm/rpn.cpp index da61a246..aaee3a83 100644 --- a/src/asm/rpn.cpp +++ b/src/asm/rpn.cpp @@ -358,7 +358,8 @@ void Expression::makeUnaryOp(RPNCommand op, Expression &&src) { case RPN_BIT_INDEX: case RPN_CONST: case RPN_SYM: - fatalerror("%d is not an unary operator\n", op); + // `makeUnaryOp` should never be called with a non-unary operator! + unreachable_(); } } else if (op == RPN_LOGNOT && tryConstLogNot(src)) { data = 0; @@ -522,7 +523,8 @@ void Expression::makeBinaryOp(RPNCommand op, Expression &&src1, Expression const case RPN_TZCOUNT: case RPN_CONST: case RPN_SYM: - fatalerror("%d is not a binary operator\n", op); + // `makeBinaryOp` should never be called with a non-binary operator! + unreachable_(); } } else if (op == RPN_SUB && src1.isDiffConstant(src2.symbolOf())) { data = src1.symbolOf()->getValue() - src2.symbolOf()->getValue(); diff --git a/test/asm/const-and.asm b/test/asm/const-and.asm index a792e5a0..5ede55fc 100644 --- a/test/asm/const-and.asm +++ b/test/asm/const-and.asm @@ -15,3 +15,6 @@ SECTION "Unaligned", ROM0 println @ & 0 println @ & 1 ; Nope + +Floating: + println Floating & Aligned ; Neither defined diff --git a/test/asm/const-and.err b/test/asm/const-and.err index 74abe12c..b032e0ab 100644 --- a/test/asm/const-and.err +++ b/test/asm/const-and.err @@ -4,4 +4,6 @@ error: const-and.asm(11): Expected constant expression: 'Aligned' is not constant at assembly time error: const-and.asm(17): Expected constant expression: PC is not constant at assembly time -error: Assembly aborted (3 errors)! +error: const-and.asm(20): + Expected constant expression: 'Floating' is not constant at assembly time +error: Assembly aborted (4 errors)! diff --git a/test/asm/const-and.out b/test/asm/const-and.out index ab62ab83..78832964 100644 --- a/test/asm/const-and.out +++ b/test/asm/const-and.out @@ -5,3 +5,4 @@ $0 $A $0 $0 +$0