mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-07-12 15:10:22 +08:00
Merge pull request #177 from jsalling/refactor/unreachable
Fix unreachable code in Unity on fully covered switch statements
This commit is contained in:
@ -35,6 +35,7 @@ const char UnityStrInf[] = "Infinity";
|
|||||||
const char UnityStrNegInf[] = "Negative Infinity";
|
const char UnityStrNegInf[] = "Negative Infinity";
|
||||||
const char UnityStrNaN[] = "NaN";
|
const char UnityStrNaN[] = "NaN";
|
||||||
const char UnityStrDet[] = "Determinate";
|
const char UnityStrDet[] = "Determinate";
|
||||||
|
const char UnityStrInvalidFloatTrait[] = "Invalid Float Trait";
|
||||||
const char UnityStrErrFloat[] = "Unity Floating Point Disabled";
|
const char UnityStrErrFloat[] = "Unity Floating Point Disabled";
|
||||||
const char UnityStrErrDouble[] = "Unity Double Precision Disabled";
|
const char UnityStrErrDouble[] = "Unity Double Precision Disabled";
|
||||||
const char UnityStrErr64[] = "Unity 64-bit Support Disabled";
|
const char UnityStrErr64[] = "Unity 64-bit Support Disabled";
|
||||||
@ -775,6 +776,8 @@ void UnityAssertFloatSpecial(const _UF actual,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
trait_index = 0;
|
||||||
|
trait_names[0] = UnityStrInvalidFloatTrait;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -905,7 +908,7 @@ void UnityAssertDoubleSpecial(const _UD actual,
|
|||||||
const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
|
const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
|
||||||
_U_SINT should_be_trait = ((_U_SINT)style & 1);
|
_U_SINT should_be_trait = ((_U_SINT)style & 1);
|
||||||
_U_SINT is_trait = !should_be_trait;
|
_U_SINT is_trait = !should_be_trait;
|
||||||
_U_SINT trait_index = style >> 1;
|
_U_SINT trait_index = (_U_SINT)(style >> 1);
|
||||||
|
|
||||||
UNITY_SKIP_EXECUTION;
|
UNITY_SKIP_EXECUTION;
|
||||||
|
|
||||||
@ -938,6 +941,8 @@ void UnityAssertDoubleSpecial(const _UD actual,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
trait_index = 0;
|
||||||
|
trait_names[0] = UnityStrInvalidFloatTrait;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +396,8 @@ typedef enum _UNITY_FLOAT_TRAIT_T
|
|||||||
UNITY_FLOAT_IS_NOT_NAN,
|
UNITY_FLOAT_IS_NOT_NAN,
|
||||||
UNITY_FLOAT_IS_NAN,
|
UNITY_FLOAT_IS_NAN,
|
||||||
UNITY_FLOAT_IS_NOT_DET,
|
UNITY_FLOAT_IS_NOT_DET,
|
||||||
UNITY_FLOAT_IS_DET
|
UNITY_FLOAT_IS_DET,
|
||||||
|
UNITY_FLOAT_INVALID_TRAIT
|
||||||
} UNITY_FLOAT_TRAIT_T;
|
} UNITY_FLOAT_TRAIT_T;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -28,6 +28,9 @@ coverage: $(BUILD_DIR)/testunityRunner.c
|
|||||||
uncovered:
|
uncovered:
|
||||||
grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
|
grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
|
||||||
|
|
||||||
|
test: CFLAGS += -Wbad-function-cast -Wcast-qual -Wconversion -Wformat=2 -Wold-style-definition \
|
||||||
|
-Wpointer-arith -Wshadow -Wstrict-overflow=5 -Wstrict-prototypes -Wswitch-default -Wundef \
|
||||||
|
-Wunreachable-code -Wunused -fstrict-aliasing
|
||||||
test: $(BUILD_DIR)/testunityRunner.c
|
test: $(BUILD_DIR)/testunityRunner.c
|
||||||
$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC) -o $(TARGET)
|
$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC) -o $(TARGET)
|
||||||
./$(TARGET)
|
./$(TARGET)
|
||||||
|
@ -2978,6 +2978,18 @@ void testFloatIsNotDeterminate2(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testFloatTraitFailsOnInvalidTrait(void)
|
||||||
|
{
|
||||||
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
EXPECT_ABORT_BEGIN
|
||||||
|
UnityAssertFloatSpecial(1.0f, NULL, __LINE__, UNITY_FLOAT_INVALID_TRAIT);
|
||||||
|
VERIFY_FAILS_END
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void testEqualFloatArrays(void)
|
void testEqualFloatArrays(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
@ -3483,6 +3495,17 @@ void testDoubleIsNotDeterminate2(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testDoubleTraitFailsOnInvalidTrait(void)
|
||||||
|
{
|
||||||
|
#ifdef UNITY_EXCLUDE_DOUBLE
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
EXPECT_ABORT_BEGIN
|
||||||
|
UnityAssertDoubleSpecial(1.0, NULL, __LINE__, UNITY_FLOAT_INVALID_TRAIT);
|
||||||
|
VERIFY_FAILS_END
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void testEqualDoubleArrays(void)
|
void testEqualDoubleArrays(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_DOUBLE
|
#ifdef UNITY_EXCLUDE_DOUBLE
|
||||||
|
Reference in New Issue
Block a user