Skip to content

Commit

Permalink
Disable warnings on test cases, actually testing the errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
offa committed May 5, 2021
1 parent b728df6 commit 9eb6645
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/CppUTest/Utest.cpp
Expand Up @@ -30,6 +30,10 @@
#include "CppUTest/PlatformSpecificFunctions.h"
#include "CppUTest/TestOutput.h"

#if defined(__GNUC__) && __GNUC__ >= 11
# define NEEDS_DISABLE_NULL_WARNING
#endif /* GCC >= 11 */

bool doubles_equal(double d1, double d2, double threshold)
{
if (PlatformSpecificIsNan(d1) || PlatformSpecificIsNan(d2) || PlatformSpecificIsNan(threshold))
Expand Down Expand Up @@ -158,10 +162,20 @@ UtestShell::~UtestShell()
}

// LCOV_EXCL_START - actually covered but not in .gcno due to race condition
#ifdef NEEDS_DISABLE_NULL_WARNING
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wnonnull"
#endif /* NEEDS_DISABLE_NULL_WARNING */

static void defaultCrashMethod()
{
UtestShell* ptr = (UtestShell*) NULLPTR; ptr->countTests();
UtestShell* ptr = (UtestShell*) NULLPTR;
ptr->countTests();
}

#ifdef NEEDS_DISABLE_NULL_WARNING
# pragma GCC diagnostic pop
#endif /* NEEDS_DISABLE_NULL_WARNING */
// LCOV_EXCL_STOP

static void (*pleaseCrashMeRightNow) () = defaultCrashMethod;
Expand Down
15 changes: 15 additions & 0 deletions tests/CppUTest/MemoryOperatorOverloadTest.cpp
Expand Up @@ -10,6 +10,11 @@
#include "CppUTest/TestHarness_c.h"
#include "AllocationInCFile.h"

#if defined(__GNUC__) && __GNUC__ >= 11
# define NEEDS_DISABLE_FREE_NON_HEEP_WARNING
#endif /* GCC >= 11 */


TEST_GROUP(BasicBehavior)
{
};
Expand Down Expand Up @@ -60,12 +65,22 @@ TEST(BasicBehavior, DeleteWithSizeParameterWorks)
}
#endif

#ifdef NEEDS_DISABLE_FREE_NON_HEEP_WARNING
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wfree-nonheap-object"
#endif /* NEEDS_DISABLE_FREE_NON_HEEP_WARNING */

static void deleteUnallocatedMemory()
{
delete (char*) 0x1234678;
FAIL("Should never come here"); // LCOV_EXCL_LINE
} // LCOV_EXCL_LINE

#ifdef NEEDS_DISABLE_FREE_NON_HEEP_WARNING
# pragma GCC diagnostic pop
#endif /* NEEDS_DISABLE_FREE_NON_HEEP_WARNING */


TEST(BasicBehavior, deleteWillNotThrowAnExceptionWhenDeletingUnallocatedMemoryButCanStillCauseTestFailures)
{
/*
Expand Down

0 comments on commit 9eb6645

Please sign in to comment.