diff options
author | Bartosz Golaszewski | 2014-06-22 16:30:41 +0200 |
---|---|---|
committer | Denys Vlasenko | 2014-06-22 16:30:41 +0200 |
commit | 3ed81cf0529145d04299c4cd48b1aaab2fe36193 (patch) | |
tree | f8d40bf4c55c9dadba0773543048a5d69b695002 /libbb/strrstr.c | |
parent | 5d2e409ef8224dc32fde59702e8ec90b231441ed (diff) | |
download | busybox-3ed81cf0529145d04299c4cd48b1aaab2fe36193.zip busybox-3ed81cf0529145d04299c4cd48b1aaab2fe36193.tar.gz |
unit-tests: implement the unit-testing framework
This set of patches adds a simple unit-testing framework to Busybox
unit-tests: add some helper macros for unit-test framework implementation
unit-tests: implement the unit-testing framework
unit-tests: add basic documentation on writing the unit test cases
unit-tests: modify the Makefile 'test' target to run unit-tests too
unit-tests: add two example test cases
unit-tests: modify the existing strrstr test code to use the unit-test framework
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/strrstr.c')
-rw-r--r-- | libbb/strrstr.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/libbb/strrstr.c b/libbb/strrstr.c index d8823fc..93d970a 100644 --- a/libbb/strrstr.c +++ b/libbb/strrstr.c @@ -7,13 +7,7 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -#ifdef __DO_STRRSTR_TEST -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#else #include "libbb.h" -#endif /* * The strrstr() function finds the last occurrence of the substring needle @@ -34,8 +28,9 @@ char* FAST_FUNC strrstr(const char *haystack, const char *needle) } } -#ifdef __DO_STRRSTR_TEST -int main(int argc, char **argv) +#if ENABLE_UNIT_TEST + +BBUNIT_DEFINE_TEST(strrstr) { static const struct { const char *h, *n; @@ -59,13 +54,13 @@ int main(int argc, char **argv) i = 0; while (i < sizeof(test_array) / sizeof(test_array[0])) { const char *r = strrstr(test_array[i].h, test_array[i].n); - printf("'%s' vs. '%s': '%s' - ", test_array[i].h, test_array[i].n, r); if (r == NULL) r = test_array[i].h - 1; - printf("%s\n", r == test_array[i].h + test_array[i].pos ? "PASSED" : "FAILED"); + BBUNIT_ASSERT_EQ(r, test_array[i].h + test_array[i].pos); i++; } - return 0; + BBUNIT_ENDTEST; } -#endif + +#endif /* ENABLE_UNIT_TEST */ |