Skip to content

Commit ceb4a10

Browse files
committed
[c89stringutils_tests/test_c89stringutils/test_string_extras.h] Add jasprintf test; [c89stringutils/c89stringutils_string_extras.h] Whitespace; [CMakeLists.txt] Guard test runner properly
1 parent 9e579b1 commit ceb4a10

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ configure_file(
3737
add_subdirectory("${PROJECT_NAME}")
3838

3939
include(CTest)
40-
enable_testing()
41-
add_subdirectory("c89stringutils_tests")
40+
if (BUILD_TESTING)
41+
add_subdirectory("c89stringutils_tests")
42+
endif (BUILD_TESTING)
4243

4344
# header-only so including this will pollute the `find_path` suggestion in vcpkg
4445
#install(

c89stringutils/c89stringutils_string_extras.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ extern int strcasecmp(const char *, const char *);
145145

146146
#if defined(C89STRINGUTILS_IMPLEMENTATION) && !defined(HAVE_STRNCASECMP_H)
147147
#define HAVE_STRNCASECMP_H
148-
#define strncasecmp _strnicmp
149148

149+
#define strncasecmp _strnicmp
150150
#define strcasecmp _stricmp
151151

152152
#endif /* defined(C89STRINGUTILS_IMPLEMENTATION) && \

c89stringutils_tests/test_c89stringutils/test_string_extras.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ TEST x_strnstr_should_fail(void) {
1616
PASS();
1717
}
1818

19+
TEST x_jasprintf_should_succeed(void) {
20+
char *s=NULL;
21+
jasprintf(&s, "foo%s", "bar");
22+
jasprintf(&s, "can%s", "haz");
23+
ASSERT_EQ(strcmp(s, "foobarcanhaz"), 0);
24+
free(s);
25+
PASS();
26+
}
27+
1928
/* Suites can group multiple tests with common setup. */
2029
SUITE(strnstr_suite) {
2130
RUN_TEST(x_strnstr_should_succeed);
2231
RUN_TEST(x_strnstr_should_fail);
32+
RUN_TEST(x_jasprintf_should_succeed);
2333
}

0 commit comments

Comments
 (0)