mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Add ASSERT_DECLARE() macro.
Declare variables that will be used by later assertions with the goal of making them easier to read and maintain. This is particularly useful for variables that are used more than once and require a lot of syntax to extract.
This commit is contained in:
parent
e18b70bf55
commit
4daddebaca
@ -35,10 +35,15 @@ Asserts are used in test code to ensure that certain conditions are true. They
|
|||||||
// Used when execution reaches an invalid location rather than an invalid condition
|
// Used when execution reaches an invalid location rather than an invalid condition
|
||||||
#define ASSERT_MSG(message) \
|
#define ASSERT_MSG(message) \
|
||||||
THROW_FMT(AssertError, message);
|
THROW_FMT(AssertError, message);
|
||||||
|
|
||||||
|
// Declare variables that will be used by later assertions with the goal of making them easier to read and maintain
|
||||||
|
#define ASSERT_DECLARE(declaration) \
|
||||||
|
declaration
|
||||||
#else
|
#else
|
||||||
#define ASSERT(condition)
|
#define ASSERT(condition)
|
||||||
#define ASSERT_INLINE(condition)
|
#define ASSERT_INLINE(condition)
|
||||||
#define ASSERT_MSG(message)
|
#define ASSERT_MSG(message)
|
||||||
|
#define ASSERT_DECLARE(declaration)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -512,10 +512,9 @@ cfgOptionIdxDisplay(const ConfigOption optionId, const unsigned int optionIdx)
|
|||||||
|
|
||||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||||
ASSERT(configLocal != NULL);
|
ASSERT(configLocal != NULL);
|
||||||
ASSERT(
|
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||||
(!configLocal->option[optionId].group && optionIdx == 0) ||
|
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||||
(configLocal->option[optionId].group && optionIdx <
|
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||||
configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal));
|
|
||||||
|
|
||||||
// Check that the option is valid for the current command
|
// Check that the option is valid for the current command
|
||||||
if (!cfgOptionValid(optionId))
|
if (!cfgOptionValid(optionId))
|
||||||
@ -573,10 +572,9 @@ cfgOptionIdxName(ConfigOption optionId, unsigned int optionIdx)
|
|||||||
|
|
||||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||||
ASSERT(configLocal != NULL);
|
ASSERT(configLocal != NULL);
|
||||||
ASSERT(
|
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||||
(!configLocal->option[optionId].group && optionIdx == 0) ||
|
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||||
(configLocal->option[optionId].group && optionIdx <
|
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||||
configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal));
|
|
||||||
|
|
||||||
// If an indexed option
|
// If an indexed option
|
||||||
ConfigOptionData *const option = &configLocal->option[optionId];
|
ConfigOptionData *const option = &configLocal->option[optionId];
|
||||||
@ -629,10 +627,9 @@ cfgOptionIdxNegate(ConfigOption optionId, unsigned int optionIdx)
|
|||||||
|
|
||||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||||
ASSERT(configLocal != NULL);
|
ASSERT(configLocal != NULL);
|
||||||
ASSERT(
|
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||||
(!configLocal->option[optionId].group && optionIdx == 0) ||
|
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||||
(configLocal->option[optionId].group && optionIdx <
|
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||||
configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal));
|
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(configLocal->option[optionId].index[optionIdx].negate);
|
FUNCTION_TEST_RETURN(configLocal->option[optionId].index[optionIdx].negate);
|
||||||
}
|
}
|
||||||
@ -658,10 +655,9 @@ cfgOptionIdxReset(ConfigOption optionId, unsigned int optionIdx)
|
|||||||
|
|
||||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||||
ASSERT(configLocal != NULL);
|
ASSERT(configLocal != NULL);
|
||||||
ASSERT(
|
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||||
(!configLocal->option[optionId].group && optionIdx == 0) ||
|
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||||
(configLocal->option[optionId].group && optionIdx <
|
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||||
configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal));
|
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(configLocal->option[optionId].index[optionIdx].reset);
|
FUNCTION_TEST_RETURN(configLocal->option[optionId].index[optionIdx].reset);
|
||||||
}
|
}
|
||||||
@ -681,10 +677,9 @@ cfgOptionIdxInternal(
|
|||||||
|
|
||||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||||
ASSERT(configLocal != NULL);
|
ASSERT(configLocal != NULL);
|
||||||
ASSERT(
|
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||||
(!configLocal->option[optionId].group && optionIdx == 0) ||
|
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||||
(configLocal->option[optionId].group && optionIdx <
|
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||||
configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal));
|
|
||||||
|
|
||||||
// Check that the option is valid for the current command
|
// Check that the option is valid for the current command
|
||||||
if (!cfgOptionValid(optionId))
|
if (!cfgOptionValid(optionId))
|
||||||
@ -719,10 +714,9 @@ cfgOptionIdxVar(const ConfigOption optionId, const unsigned int optionIdx)
|
|||||||
FUNCTION_TEST_END();
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
ASSERT(configLocal != NULL);
|
ASSERT(configLocal != NULL);
|
||||||
ASSERT(
|
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||||
(!configLocal->option[optionId].group && optionIdx == 0) ||
|
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||||
(configLocal->option[optionId].group && optionIdx <
|
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||||
configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal));
|
|
||||||
|
|
||||||
const ConfigOptionData *const option = &configLocal->option[optionId];
|
const ConfigOptionData *const option = &configLocal->option[optionId];
|
||||||
|
|
||||||
@ -928,10 +922,9 @@ cfgOptionIdxSet(ConfigOption optionId, unsigned int optionIdx, ConfigSource sour
|
|||||||
|
|
||||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||||
ASSERT(configLocal != NULL);
|
ASSERT(configLocal != NULL);
|
||||||
ASSERT(
|
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||||
(!configLocal->option[optionId].group && optionIdx == 0) ||
|
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||||
(configLocal->option[optionId].group && optionIdx <
|
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||||
configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal));
|
|
||||||
|
|
||||||
// Set the source
|
// Set the source
|
||||||
ConfigOptionData *const option = &configLocal->option[optionId];
|
ConfigOptionData *const option = &configLocal->option[optionId];
|
||||||
@ -1024,10 +1017,9 @@ cfgOptionIdxSource(ConfigOption optionId, unsigned int optionIdx)
|
|||||||
|
|
||||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||||
ASSERT(configLocal != NULL);
|
ASSERT(configLocal != NULL);
|
||||||
ASSERT(
|
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||||
(!configLocal->option[optionId].group && optionIdx == 0) ||
|
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||||
(configLocal->option[optionId].group && optionIdx <
|
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||||
configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal));
|
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(configLocal->option[optionId].index[optionIdx].source);
|
FUNCTION_TEST_RETURN(configLocal->option[optionId].index[optionIdx].source);
|
||||||
}
|
}
|
||||||
@ -1053,11 +1045,9 @@ cfgOptionIdxTest(ConfigOption optionId, unsigned int optionIdx)
|
|||||||
|
|
||||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||||
ASSERT(configLocal != NULL);
|
ASSERT(configLocal != NULL);
|
||||||
ASSERT(
|
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||||
!cfgOptionValid(optionId) ||
|
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||||
((!configLocal->option[optionId].group && optionIdx == 0) ||
|
ASSERT(!cfgOptionValid(optionId) || ((!group && optionIdx == 0) || (group && optionIdx < indexTotal)));
|
||||||
(configLocal->option[optionId].group && optionIdx <
|
|
||||||
configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal)));
|
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(cfgOptionValid(optionId) && configLocal->option[optionId].index[optionIdx].set);
|
FUNCTION_TEST_RETURN(cfgOptionValid(optionId) && configLocal->option[optionId].index[optionIdx].set);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user