From 1fa6a3e3354bd98707303476b5a54147ccdd533a Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Fri, 29 Mar 2024 20:26:38 -0700 Subject: Fix various clang-tidy lints * some things that can throw are marked noexcept yet the linter seems to think not. Maybe they can't throw in practice. I would rather not have the UB possibility in pretty obvious cold paths. * various default-case-missing complaints * a fair pile of casts from integer to character, which are in fact deliberate. * an instance of * bugprone-not-null-terminated-result on handing a string to curl in chunks of bytes. our usage is fine. * reassigning a unique_ptr by CRIMES instead of using release(), then using release() and ignoring the result. wild. let's use release() for its intended purpose. Change-Id: Ic3e7affef12383576213a8a7c8145c27e662513d --- tests/unit/libstore-support/tests/path.cc | 6 ++--- tests/unit/libstore/outputs-spec.cc | 30 ++++++++++++---------- .../libutil-support/tests/terminal-code-eater.cc | 1 + 3 files changed, 20 insertions(+), 17 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/libstore-support/tests/path.cc b/tests/unit/libstore-support/tests/path.cc index 8bf501ab6..ffc4fc607 100644 --- a/tests/unit/libstore-support/tests/path.cc +++ b/tests/unit/libstore-support/tests/path.cc @@ -32,13 +32,13 @@ Gen Arbitrary::arbitrary() for (size_t c = 0; c < len; ++c) { switch (auto i = *gen::inRange(0, 10 + 2 * 26 + 6)) { case 0 ... 9: - pre += '0' + i; + pre += static_cast('0' + i); break; case 10 ... 35: - pre += 'A' + (i - 10); + pre += static_cast('A' + (i - 10)); break; case 36 ... 61: - pre += 'a' + (i - 36); + pre += static_cast('a' + (i - 36)); break; case 62: pre += '+'; diff --git a/tests/unit/libstore/outputs-spec.cc b/tests/unit/libstore/outputs-spec.cc index 63cde681b..72a7da974 100644 --- a/tests/unit/libstore/outputs-spec.cc +++ b/tests/unit/libstore/outputs-spec.cc @@ -170,20 +170,22 @@ TEST(ExtendedOutputsSpec, many_carrot) { } -#define TEST_JSON(TYPE, NAME, STR, VAL) \ - \ - TEST(TYPE, NAME ## _to_json) { \ - using nlohmann::literals::operator "" _json; \ - ASSERT_EQ( \ - STR ## _json, \ - ((nlohmann::json) TYPE { VAL })); \ - } \ - \ - TEST(TYPE, NAME ## _from_json) { \ - using nlohmann::literals::operator "" _json; \ - ASSERT_EQ( \ - TYPE { VAL }, \ - (STR ## _json).get()); \ +#define TEST_JSON(TYPE, NAME, STR, VAL) \ + \ + TEST(TYPE, NAME ## _to_json) { \ + using nlohmann::literals::operator "" _json; \ + ASSERT_EQ( \ + STR ## _json, \ + /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ + ((nlohmann::json) TYPE { VAL })); \ + } \ + \ + TEST(TYPE, NAME ## _from_json) { \ + using nlohmann::literals::operator "" _json; \ + ASSERT_EQ( \ + /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ + TYPE { VAL }, \ + (STR ## _json).get()); \ } TEST_JSON(OutputsSpec, all, R"(["*"])", OutputsSpec::All { }) diff --git a/tests/unit/libutil-support/tests/terminal-code-eater.cc b/tests/unit/libutil-support/tests/terminal-code-eater.cc index ad05ed1f6..6e108009a 100644 --- a/tests/unit/libutil-support/tests/terminal-code-eater.cc +++ b/tests/unit/libutil-support/tests/terminal-code-eater.cc @@ -26,6 +26,7 @@ void TerminalCodeEater::feed(char c, std::function on_char) // Just eat \r, since it is part of clearing a line case '\r': return; + default: break; } if constexpr (DEBUG_EATER) { std::cerr << "eater uneat" << MaybeHexEscapedChar{c} << "\n"; -- cgit v1.2.3