Skip to content

Commit

Permalink
Merge pull request #29 from stlab/sean-parent/clang-tidy-cleanup
Browse files Browse the repository at this point in the history
Minimizing the clang-tidy exception list
  • Loading branch information
sean-parent authored Oct 22, 2024
2 parents 9c2b5e6 + bfd4fbb commit e7a2be8
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 49 deletions.
30 changes: 7 additions & 23 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
---
Checks:
- "*"
- "-abseil-*"
- "-altera-*"
- "-android-*"
- "-cppcoreguidelines-avoid-magic-numbers"
- "-cppcoreguidelines-non-private-member-variables-in-classes"
- "-cppcoreguidelines-pro-type-vararg"
- "-fuchsia-*"
- "-google-*"
- "-hicpp-vararg"
- "-llvm*"
- "-misc-non-private-member-variables-in-classes"
- "-modernize-use-trailing-return-type"
- "-readability-avoid-const-params-in-decls"
- "-readability-else-after-return"
- "-readability-function-cognitive-complexity"
- "-readability-identifier-length"
- "-readability-magic-numbers"
- "-readability-static-accessed-through-instance"
- "-zircon-*"
- "-altera-unroll-loops" # Required for gtest
- "-fuchsia-*" # Internal Zircon https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx
- "-llvmlibc-*" # Internal llvm libc flags
- "-readability-function-cognitive-complexity" # Required for gtest

WarningsAsErrors: ""
HeaderFilterRegex: ""
FormatStyle: none

CheckOptions:
- key: readability-identifier-length.IgnoredVariableNames
value: "x|y|z"
# CheckOptions:
# - key: readability-identifier-length.IgnoredVariableNames
# value: "x|y|z"
# Local Variables:
# mode: yaml
# End:
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ strings, or be left undefined, in which case it defaults to `verbose`.
of checking in a program.
- `ADOBE_CONTRACT_VIOLATION=custom_verbose`: When a contract violation is detected, a custom handler
is invoked. The client must define the handler at global scope with the signature:
is invoked. The client must define the handler in the `adobe` namespace with the signature:
```cpp
[[noreturn]] void adobe_contract_violation_verbose(const char *condition,
[[noreturn]] void ::adobe::contract_violated_verbose(const char *condition,
adobe::contract_violation_kind kind, const char *file, std::uint32_t line,
const char *message) {
// implementation
Expand All @@ -250,10 +250,10 @@ strings, or be left undefined, in which case it defaults to `verbose`.
application, and must not return to its caller.

- `ADOBE_CONTRACT_VIOLATION=custom_lightweight`: When a contract violation is detected, a custom
handler is invoked. The client must define the handler at global scope with the signature:
handler is invoked. The client must define the handler in the `adobe` namespace with the signature:

```cpp
[[noreturn]] void adobe_contract_violation_lightweight() {
[[noreturn]] void ::adobe::contract_violated_lightweight() {
// implementation
}
```
Expand Down
12 changes: 8 additions & 4 deletions include/adobe/contract_checks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,27 @@ namespace detail {
#elif INTERNAL_ADOBE_CONTRACT_VIOLATION_BEHAVIOR == INTERNAL_ADOBE_CONTRACT_VIOLATION_custom_verbose

#define INTERNAL_ADOBE_CONTRACT_VIOLATED(condition, kind, file, line, message) \
::adobe_contract_violated_verbose(condition, kind, file, line, message)
::adobe::contract_violated_verbose(condition, kind, file, line, message)

#include <cstdint>

[[noreturn]] extern void adobe_contract_violated_verbose(const char *condition,
namespace adobe {
[[noreturn]] extern void contract_violated_verbose(const char *condition,
adobe::contract_violation_kind kind,
const char *file,
std::uint32_t line,
const char *message);
}

#elif INTERNAL_ADOBE_CONTRACT_VIOLATION_BEHAVIOR \
== INTERNAL_ADOBE_CONTRACT_VIOLATION_custom_lightweight

#define INTERNAL_ADOBE_CONTRACT_VIOLATED(condition, kind, file, line, message) \
::adobe_contract_violated_lightweight()
::adobe::contract_violated_lightweight()

[[noreturn]] extern void adobe_contract_violated_lightweight();
namespace adobe {
[[noreturn]] extern void contract_violated_lightweight();
}

#elif INTERNAL_ADOBE_CONTRACT_VIOLATION_BEHAVIOR == INTERNAL_ADOBE_CONTRACT_VIOLATION_unsafe

Expand Down
12 changes: 6 additions & 6 deletions test/custom_lightweight_configuration_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
#include <gtest/gtest.h>
#include <stdexcept>

[[noreturn]] void adobe_contract_violated_lightweight()
[[noreturn]] void ::adobe::contract_violated_lightweight()
{
throw std::logic_error("adobe_contract_violated_lightweight");
throw std::logic_error("::adobe::contract_violated_lightweight");
}

TEST(CustomLightweightConfiguration, FailedChecksThrow)
{
EXPECT_THROW(ADOBE_PRECONDITION(false), std::logic_error);
EXPECT_THROW(ADOBE_INVARIANT(false), std::logic_error);

EXPECT_THROW(ADOBE_PRECONDITION(false, "##########"), std::logic_error);
EXPECT_THROW(ADOBE_INVARIANT(false, "#########"), std::logic_error);
EXPECT_THROW(ADOBE_PRECONDITION(false, "% Message %"), std::logic_error);
EXPECT_THROW(ADOBE_INVARIANT(false, "% Message %"), std::logic_error);
}

TEST(CustomLightweightConfiguration, ContractNonViolationsDoNotThrow)
{
ADOBE_PRECONDITION(true);
ADOBE_INVARIANT(true);

ADOBE_PRECONDITION(true, "##########");
ADOBE_INVARIANT(true, "#########");
ADOBE_PRECONDITION(true, "% Message %");
ADOBE_INVARIANT(true, "% Message %");
}
15 changes: 9 additions & 6 deletions test/custom_verbose_configuration_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#include "adobe/contract_checks.hpp"

#include "portable_death_tests.hpp"
#include <cstdint>
#include <exception>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <cstdint>
#include <exception>
#include <sstream>
#include <stdexcept>

// Throws a std::logic_error with a message constructed from the arguments.
[[noreturn]] void adobe_contract_violated_verbose(const char *condition,
[[noreturn]] void ::adobe::contract_violated_verbose(const char *condition,
adobe::contract_violation_kind kind,
const char *file,
std::uint32_t line,
Expand All @@ -25,12 +28,12 @@

namespace {

// Expects that `f()` throws an exception and that the exception's `what()` method contains the
// Expects that `fun()` throws an exception and that the exception's `what()` method contains the
// `match` regex.
template<class F> void expect_throw(F f, const char *match)
template<class F> void expect_throw(F fun, const char *match)
{
try {
f();
fun();
} catch (const std::exception &e) {
EXPECT_THAT(e.what(), testing::ContainsRegex(match));
return;
Expand Down
13 changes: 9 additions & 4 deletions test/inadequate_arity_checking_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "adobe/contract_checks.hpp"
#include <gtest/gtest.h>

struct F
namespace {

struct Failure
{
template<class T, class U, class V, class W>
void operator()(const T & /*unused*/,
Expand All @@ -10,12 +12,15 @@ struct F
const W & /*unused*/) const
{}
};
const F f;

const Failure failure;

}// namespace

TEST(ArityChecking, TooManyArgumentsNotAlwaysDetected)
{
// These don't fail, so our arity detection is weak.
// https://github.com/stlab/adobe-contract-checks/issues/19
ADOBE_PRECONDITION(true, "message", f);
ADOBE_INVARIANT(true, "message", f);
ADOBE_PRECONDITION(true, "message", failure);
ADOBE_INVARIANT(true, "message", failure);
}
4 changes: 2 additions & 2 deletions test/lightweight_configuration_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ TEST(LightweightConfiguration, ContractNonViolationsDoNotCauseAbort)
ADOBE_PRECONDITION(true);
ADOBE_INVARIANT(true);

ADOBE_PRECONDITION(true, "##########");
ADOBE_INVARIANT(true, "#########");
ADOBE_PRECONDITION(true, "% Message %");
ADOBE_INVARIANT(true, "% Message %");
}

#if defined(__EMSCRIPTEN__) && 0
Expand Down

0 comments on commit e7a2be8

Please sign in to comment.