selftest.h: add ASSERT_STR_CONTAINS
gcc/ChangeLog: * selftest.c (selftest::assert_str_contains): New function. (selftest::test_assertions): Verify ASSERT_STR_CONTAINS. * selftest.h (selftest::assert_str_contains): New decl. (ASSERT_STR_CONTAINS): New macro. From-SVN: r239707
This commit is contained in:
parent
a181ec0301
commit
9f58978668
|
@ -1,3 +1,10 @@
|
|||
2016-08-23 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* selftest.c (selftest::assert_str_contains): New function.
|
||||
(selftest::test_assertions): Verify ASSERT_STR_CONTAINS.
|
||||
* selftest.h (selftest::assert_str_contains): New decl.
|
||||
(ASSERT_STR_CONTAINS): New macro.
|
||||
|
||||
2016-08-23 Richard Biener <rguenther@suse.de>
|
||||
|
||||
PR tree-optimization/77286
|
||||
|
|
|
@ -87,6 +87,39 @@ selftest::assert_streq (const location &loc,
|
|||
desc_expected, desc_actual, val_expected, val_actual);
|
||||
}
|
||||
|
||||
/* Implementation detail of ASSERT_STR_CONTAINS.
|
||||
Use strstr to determine if val_needle is is within val_haystack.
|
||||
::selftest::pass if it is found.
|
||||
::selftest::fail if it is not found. */
|
||||
|
||||
void
|
||||
selftest::assert_str_contains (const location &loc,
|
||||
const char *desc_haystack,
|
||||
const char *desc_needle,
|
||||
const char *val_haystack,
|
||||
const char *val_needle)
|
||||
{
|
||||
/* If val_haystack is NULL, fail with a custom error message. */
|
||||
if (val_haystack == NULL)
|
||||
::selftest::fail_formatted
|
||||
(loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=NULL",
|
||||
desc_haystack, desc_needle);
|
||||
|
||||
/* If val_needle is NULL, fail with a custom error message. */
|
||||
if (val_needle == NULL)
|
||||
::selftest::fail_formatted
|
||||
(loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=\"%s\" needle=NULL",
|
||||
desc_haystack, desc_needle, val_haystack);
|
||||
|
||||
const char *test = strstr (val_haystack, val_needle);
|
||||
if (test)
|
||||
::selftest::pass (loc, "ASSERT_STR_CONTAINS");
|
||||
else
|
||||
::selftest::fail_formatted
|
||||
(loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=\"%s\" needle=\"%s\"",
|
||||
desc_haystack, desc_needle, val_haystack, val_needle);
|
||||
}
|
||||
|
||||
/* Constructor. Create a tempfile using SUFFIX, and write CONTENT to
|
||||
it. Abort if anything goes wrong, using LOC as the effective
|
||||
location in the problem report. */
|
||||
|
@ -131,6 +164,7 @@ test_assertions ()
|
|||
ASSERT_NE (1, 2);
|
||||
ASSERT_STREQ ("test", "test");
|
||||
ASSERT_STREQ_AT (SELFTEST_LOCATION, "test", "test");
|
||||
ASSERT_STR_CONTAINS ("foo bar baz", "bar");
|
||||
}
|
||||
|
||||
/* Run all of the selftests within this file. */
|
||||
|
|
|
@ -69,6 +69,14 @@ extern void assert_streq (const location &loc,
|
|||
const char *desc_expected, const char *desc_actual,
|
||||
const char *val_expected, const char *val_actual);
|
||||
|
||||
/* Implementation detail of ASSERT_STR_CONTAINS. */
|
||||
|
||||
extern void assert_str_contains (const location &loc,
|
||||
const char *desc_haystack,
|
||||
const char *desc_needle,
|
||||
const char *val_haystack,
|
||||
const char *val_needle);
|
||||
|
||||
/* A class for writing out a temporary sourcefile for use in selftests
|
||||
of input handling. */
|
||||
|
||||
|
@ -249,6 +257,17 @@ extern int num_passes;
|
|||
(EXPECTED), (ACTUAL)); \
|
||||
SELFTEST_END_STMT
|
||||
|
||||
/* Evaluate HAYSTACK and NEEDLE and use strstr to determine if NEEDLE
|
||||
is within HAYSTACK.
|
||||
::selftest::pass if NEEDLE is found.
|
||||
::selftest::fail if it is not found. */
|
||||
|
||||
#define ASSERT_STR_CONTAINS(HAYSTACK, NEEDLE) \
|
||||
SELFTEST_BEGIN_STMT \
|
||||
::selftest::assert_str_contains (SELFTEST_LOCATION, #HAYSTACK, #NEEDLE, \
|
||||
(HAYSTACK), (NEEDLE)); \
|
||||
SELFTEST_END_STMT
|
||||
|
||||
/* Evaluate PRED1 (VAL1), calling ::selftest::pass if it is true,
|
||||
::selftest::fail if it is false. */
|
||||
|
||||
|
|
Loading…
Reference in New Issue