Behavior of cr_assert_str* assertions changed:

- Default assertion messages will now print the expession and the content of both strings.
- String assertions will not crash, if the actual string is NULL.
  (cr_assert_not_null(actual) is called before the cr_assert_str* assertion)
This commit is contained in:
commit 2016-06-02 14:57:52 +02:00
parent 96bf7869de
commit f201d85e3c
5 changed files with 80 additions and 64 deletions

View file

@ -251,15 +251,18 @@ CR_END_C_API
// String
# define cr_assert_str_op_empty_(Fail, Op, Msg, Value, ...) \
CR_EXPAND(cr_assert_impl( \
Fail, \
(Value)[0] Op '\0', \
dummy, \
Msg, \
(CR_STR(Value)), \
__VA_ARGS__ \
))
# define cr_assert_str_op_empty_(Fail, Op, Msg, Value, ...) \
do { \
const char *cr_str_value__ = (Value); \
CR_EXPAND(cr_assert_impl( \
Fail, \
((cr_str_value__) != NULL) && (cr_str_value__)[0] Op '\0', \
dummy, \
((cr_str_value__) != NULL) ? Msg: CRITERION_ASSERT_MSG_IS_NULL, \
(CR_STR(Value), cr_str_value__), \
__VA_ARGS__ \
)); \
} while (0)
# define cr_assert_str_op_empty_va_(Fail, Op, Msg, ...) \
CR_EXPAND(cr_assert_str_op_empty_( \
@ -270,15 +273,20 @@ CR_END_C_API
CR_VA_TAIL(__VA_ARGS__) \
))
# define cr_assert_str_op_(Fail, Op, Actual, Expected, ...) \
CR_EXPAND(cr_assert_impl( \
Fail, \
CR_STDN strcmp((Actual), (Expected)) Op 0, \
dummy, \
CRITERION_ASSERT_MSG_EXPR_AS_STRINGS_FALSE, \
(CR_STR((Actual) Op (Expected))), \
__VA_ARGS__ \
))
# define cr_assert_str_op_(Fail, Op, Actual, Expected, ...) \
do { \
const char *cr_str_actual__ = (Actual); \
const char *cr_str_expected__ = (Expected); \
CR_EXPAND(cr_assert_impl( \
Fail, \
((cr_str_actual__) != NULL) && ((cr_str_expected__) != NULL) && \
CR_STDN strcmp((cr_str_actual__), (cr_str_expected__)) Op 0, \
dummy, \
CRITERION_ASSERT_MSG_EXPR_AS_STRINGS_FALSE, \
(CR_STR((Actual) Op (Expected)), cr_str_actual__, cr_str_expected__), \
__VA_ARGS__ \
)); \
} while (0)
# define cr_assert_str_op_va_(Fail, Op, ...) \
CR_EXPAND(cr_assert_str_op_( \

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Criterion \n"
"Report-Msgid-Bugs-To: franklinmathieu+criterion@gmail.com\n"
"POT-Creation-Date: 2016-02-13 12:57+0100\n"
"POT-Creation-Date: 2016-06-06 15:16+0200\n"
"PO-Revision-Date: 2016-02-12 11:12+0100\n"
"Last-Translator: <a1lu@arcor.de>\n"
"Language-Team: German\n"
@ -130,39 +130,42 @@ msgstr "Der Ausdruck %s ist falsch."
#: src/string/i18n.c:15
#, c-format
msgid "The expression (as strings) %s is false."
msgstr "Der Ausdruck (als Zeichenkette) %s ist falsch."
#: src/string/i18n.c:16
#, c-format
msgid "%s is null."
msgstr "%s ist null."
#: src/string/i18n.c:17
#: src/string/i18n.c:16
#, c-format
msgid "%s is not null."
msgstr "%s ist nicht null."
#: src/string/i18n.c:18
#: src/string/i18n.c:17
#, c-format
msgid "%s is empty."
msgstr "%s ist leer."
#: src/string/i18n.c:19
#, c-format
msgid "%s is not empty."
msgstr "%s ist nicht leer."
#: src/string/i18n.c:20
#: src/string/i18n.c:18
#, c-format
msgid "The statement `%s` did not throw any exception."
msgstr "Die Anweisung `%s` hat keine Ausnahme geworfen."
#: src/string/i18n.c:21
#: src/string/i18n.c:19
#, c-format
msgid "The statement `%s` threw some exception."
msgstr "Die Anweisung `%s` hat Ausnahmen geworfen."
#: src/string/i18n.c:22
#, c-format
msgid ""
"The expression (as strings) %1$s is false: actual=`%2$s` expected=`%3$s`."
msgstr ""
"Der Ausdruck (als Zeichenkette) %1$s ist falsch: tatsächlich=`%2$s` "
"erwartet=`%3$s`."
#: src/string/i18n.c:23
#, c-format
msgid "%1$s (`%2$s`) is not empty."
msgstr "%1$s (`%2$s`) ist nicht leer."
#: src/string/i18n.c:24
#, c-format
msgid "The file contents of %1$s does not match the string \"%2$s\"."

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: criterion 2.0.0\n"
"Report-Msgid-Bugs-To: franklinmathieu+criterion@gmail.com\n"
"POT-Creation-Date: 2016-02-13 12:57+0100\n"
"POT-Creation-Date: 2016-06-06 15:16+0200\n"
"PO-Revision-Date: 2015-04-03 17:58+0200\n"
"Last-Translator: <franklinmathieu@gmail.com>\n"
"Language-Team: French\n"
@ -130,39 +130,42 @@ msgstr "L'expression %s est fausse."
#: src/string/i18n.c:15
#, c-format
msgid "The expression (as strings) %s is false."
msgstr "L'expression (en tant que chaînes de caractères) %s est fausse."
#: src/string/i18n.c:16
#, c-format
msgid "%s is null."
msgstr "%s est nul."
#: src/string/i18n.c:17
#: src/string/i18n.c:16
#, c-format
msgid "%s is not null."
msgstr "%s n'est pas nul."
#: src/string/i18n.c:18
#: src/string/i18n.c:17
#, c-format
msgid "%s is empty."
msgstr "%s est vide."
#: src/string/i18n.c:19
#, c-format
msgid "%s is not empty."
msgstr "%s n'est pas vide."
#: src/string/i18n.c:20
#: src/string/i18n.c:18
#, fuzzy, c-format
msgid "The statement `%s` did not throw any exception."
msgstr "L'instruction `%s` n'a pas levé d'exception."
#: src/string/i18n.c:21
#: src/string/i18n.c:19
#, fuzzy, c-format
msgid "The statement `%s` threw some exception."
msgstr "L'instruction `%1$s` a levé une exception."
#: src/string/i18n.c:22
#, c-format
msgid ""
"The expression (as strings) %1$s is false: actual=`%2$s` expected=`%3$s`."
msgstr ""
"L'expression (en tant que chaînes de caractères) %1$s est fausse: actuel=`"
"%2$s` attendu=`%3$s`."
#: src/string/i18n.c:23
#, c-format
msgid "%1$s (`%2$s`) is not empty."
msgstr "%1$s (`%2$s`) n'est pas vide."
#: src/string/i18n.c:24
#, c-format
msgid "The file contents of %1$s does not match the string \"%2$s\"."

View file

@ -12,20 +12,22 @@ char *cr_translate_assert_msg(int msg_index, ...) {
static char *messages[] = {
[CRITERION_ASSERT_MSG_FAIL] = N_("The conditions for this assertion were not met."),
[CRITERION_ASSERT_MSG_EXPR_FALSE] = N_("The expression %s is false."),
[CRITERION_ASSERT_MSG_EXPR_AS_STRINGS_FALSE] = N_("The expression (as strings) %s is false."),
[CRITERION_ASSERT_MSG_IS_NULL] = N_("%s is null."),
[CRITERION_ASSERT_MSG_IS_NOT_NULL] = N_("%s is not null."),
[CRITERION_ASSERT_MSG_IS_EMPTY] = N_("%s is empty."),
[CRITERION_ASSERT_MSG_IS_NOT_EMPTY] = N_("%s is not empty."),
[CRITERION_ASSERT_MSG_ANY_THROW] = N_("The statement `%s` did not throw any exception."),
[CRITERION_ASSERT_MSG_NONE_THROW] = N_("The statement `%s` threw some exception."),
#ifdef ENABLE_NLS
[CRITERION_ASSERT_MSG_EXPR_AS_STRINGS_FALSE] = N_("The expression (as strings) %1$s is false: actual=`%2$s` expected=`%3$s`."),
[CRITERION_ASSERT_MSG_IS_NOT_EMPTY] = N_("%1$s (`%2$s`) is not empty."),
[CRITERION_ASSERT_MSG_FILE_STR_MATCH] = N_("The file contents of %1$s does not match the string \"%2$s\"."),
[CRITERION_ASSERT_MSG_FILE_MATCH] = N_("The file contents of %1$s does not match the contents of %2$s."),
[CRITERION_ASSERT_MSG_THROW] = N_("The statement `%1$s` did throw an instance of the `%2$s` exception."),
[CRITERION_ASSERT_MSG_NO_THROW] = N_("The statement `%1$s` did not throw an instance of the `%2$s` exception."),
#else
[CRITERION_ASSERT_MSG_EXPR_AS_STRINGS_FALSE] = "The expression (as strings) %s is false: actual=`%s` expected=`%s`.",
[CRITERION_ASSERT_MSG_IS_NOT_EMPTY] = "%s (`%s`) is not empty.",
[CRITERION_ASSERT_MSG_FILE_STR_MATCH] = "The file contents of %s does not match the string \"%s\".",
[CRITERION_ASSERT_MSG_FILE_MATCH] = "The file contents of %s does not match the contents of %s.",
[CRITERION_ASSERT_MSG_THROW] = "The statement `%s` did throw an instance of the `%s` exception.",

View file

@ -46,14 +46,14 @@ Testing all assert messages
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m16\x1b[0m: Assertion failed: ((void *)0) is null. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m18\x1b[0m: Assertion failed: The expression (2) - (1) <= (0.1) && (1) - (2) <= (0.1) is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m19\x1b[0m: Assertion failed: The expression (2) - (2) > (0.1) || (2) - (2) > (0.1) is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m21\x1b[0m: Assertion failed: "foo" is not empty. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m21\x1b[0m: Assertion failed: "foo" (`foo`) is not empty. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m22\x1b[0m: Assertion failed: "" is empty. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m23\x1b[0m: Assertion failed: The expression (as strings) ("abc") == ("abd") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m24\x1b[0m: Assertion failed: The expression (as strings) ("abc") != ("abc") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m25\x1b[0m: Assertion failed: The expression (as strings) ("abc") < ("aba") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m26\x1b[0m: Assertion failed: The expression (as strings) ("abc") <= ("aba") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m27\x1b[0m: Assertion failed: The expression (as strings) ("abc") > ("abd") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m28\x1b[0m: Assertion failed: The expression (as strings) ("abc") >= ("abd") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m23\x1b[0m: Assertion failed: The expression (as strings) ("abc") == ("abd") is false: actual=`abc` expected=`abd`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m24\x1b[0m: Assertion failed: The expression (as strings) ("abc") != ("abc") is false: actual=`abc` expected=`abc`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m25\x1b[0m: Assertion failed: The expression (as strings) ("abc") < ("aba") is false: actual=`abc` expected=`aba`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m26\x1b[0m: Assertion failed: The expression (as strings) ("abc") <= ("aba") is false: actual=`abc` expected=`aba`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m27\x1b[0m: Assertion failed: The expression (as strings) ("abc") > ("abd") is false: actual=`abc` expected=`abd`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m28\x1b[0m: Assertion failed: The expression (as strings) ("abc") >= ("abd") is false: actual=`abc` expected=`abd`. (esc)
[\x1b[0;31mFAIL\x1b[0m] messages::default (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m32\x1b[0m: Assertion failed: foo bar (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.c\x1b[0m:\x1b[0;31m33\x1b[0m: Assertion failed: foo bar (esc)
@ -89,14 +89,14 @@ Testing all assert messages
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m13\x1b[0m: Assertion failed: __null is null. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m15\x1b[0m: Assertion failed: The expression (2) - (1) <= (0.1) && (1) - (2) <= (0.1) is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m16\x1b[0m: Assertion failed: The expression (2) - (2) > (0.1) || (2) - (2) > (0.1) is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m18\x1b[0m: Assertion failed: "foo" is not empty. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m18\x1b[0m: Assertion failed: "foo" (`foo`) is not empty. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m19\x1b[0m: Assertion failed: "" is empty. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m20\x1b[0m: Assertion failed: The expression (as strings) ("abc") == ("abd") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m21\x1b[0m: Assertion failed: The expression (as strings) ("abc") != ("abc") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m22\x1b[0m: Assertion failed: The expression (as strings) ("abc") < ("aba") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m23\x1b[0m: Assertion failed: The expression (as strings) ("abc") <= ("aba") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m24\x1b[0m: Assertion failed: The expression (as strings) ("abc") > ("abd") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m25\x1b[0m: Assertion failed: The expression (as strings) ("abc") >= ("abd") is false. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m20\x1b[0m: Assertion failed: The expression (as strings) ("abc") == ("abd") is false: actual=`abc` expected=`abd`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m21\x1b[0m: Assertion failed: The expression (as strings) ("abc") != ("abc") is false: actual=`abc` expected=`abc`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m22\x1b[0m: Assertion failed: The expression (as strings) ("abc") < ("aba") is false: actual=`abc` expected=`aba`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m23\x1b[0m: Assertion failed: The expression (as strings) ("abc") <= ("aba") is false: actual=`abc` expected=`aba`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m24\x1b[0m: Assertion failed: The expression (as strings) ("abc") > ("abd") is false: actual=`abc` expected=`abd`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m25\x1b[0m: Assertion failed: The expression (as strings) ("abc") >= ("abd") is false: actual=`abc` expected=`abd`. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m27\x1b[0m: Assertion failed: The statement `throw std::exception()` did not throw an instance of the `std::bad_alloc` exception. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m28\x1b[0m: Assertion failed: The statement `throw std::exception()` did throw an instance of the `std::exception` exception. (esc)
[\x1b[0;34m----\x1b[0m] \x1b[0;1mfailmessages.cc\x1b[0m:\x1b[0;31m29\x1b[0m: Assertion failed: The statement `{}` did not throw any exception. (esc)