Skip to content

Commit f9c7fae

Browse files
committed
[c89stringutils/reports] Generate code coverage ; [c89stringutils/tests] Move around codebase so tests are in a best-practice place (and works properly with CTest)
1 parent 9bc0af5 commit f9c7fae

File tree

10 files changed

+45
-26
lines changed

10 files changed

+45
-26
lines changed

CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@ elseif ((MSVC_VERSION STRLESS_EQUAL "1900"
2020
"${CMAKE_BINARY_DIR}/c89stringutils_export.h")
2121
endif ()
2222
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
23-
# add compiler warning flags just when building this project via
24-
# the BUILD_INTERFACE genex
2523
set(gcc_like "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
2624
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>")
2725
target_compile_options(
2826
"${PROJECT_NAME}_compiler_flags"
2927
INTERFACE
30-
"$<${gcc_like}:$<BUILD_INTERFACE:-Wshadow;-Wformat=2;-Wall;-pedantic>>"
28+
"$<$<AND:${gcc_like},$<CONFIG:Debug>>:$<BUILD_INTERFACE:-Wshadow;-Wformat=2;-Wall;-Wno-missing-braces;-Wno-long-long;-pedantic;-fprofile-arcs;-ftest-coverage>>"
3129
"$<${msvc}:$<BUILD_INTERFACE:-W3;-WX;-Zi;-permissive->>"
3230
)
31+
target_link_options(
32+
"${PROJECT_NAME}_compiler_flags"
33+
INTERFACE
34+
"$<$<AND:${gcc_like},$<CONFIG:Debug>>:$<BUILD_INTERFACE:--coverage>>"
35+
)
3336
endif (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
3437
# Set the build directories
3538
if (CMAKE_SYSTEM_NAME STREQUAL "Windows"
@@ -53,9 +56,11 @@ configure_file(
5356
add_subdirectory("${PROJECT_NAME}")
5457

5558
include(CTest)
56-
if (BUILD_TESTING)
57-
add_subdirectory("${PROJECT_NAME}_tests")
58-
endif (BUILD_TESTING)
59+
option(BUILD_TESTING "Build the tests" ON)
60+
option(C89STRINGUTILS_BUILD_TESTING "Build the tests" ON)
61+
if (BUILD_TESTING AND C89STRINGUTILS_BUILD_TESTING)
62+
add_subdirectory("${PROJECT_NAME}/tests")
63+
endif (BUILD_TESTING AND C89STRINGUTILS_BUILD_TESTING)
5964

6065
###########
6166
# Install #

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ c89stringutils
33
[![License](https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg)](https://opensource.org/licenses/Apache-2.0)
44
[![CI for Linux, Windows, macOS](https://github.com/offscale/c89stringutils/actions/workflows/linux-Windows-macOS-sunOS.yml/badge.svg)](https://github.com/offscale/c89stringutils/actions/workflows/github-actions.yml)
55
[![CI for FreeBSD](https://api.cirrus-ci.com/github/offscale/c89stringutils.svg)](https://cirrus-ci.com/github/offscale/c89stringutils)
6+
![coverage](reports/test_coverage.svg)
67
[![C89](https://img.shields.io/badge/C-89-blue)](https://en.wikipedia.org/wiki/C89_(C_version))
78

89
C89 is missing some nice things. As is MSVC.

c89stringutils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ install(EXPORT "${LIBRARY_NAME}Targets" DESTINATION "${CMAKE_INSTALL_DATADIR}/${
5555

5656
install(FILES ${Header_Files} "${_export_file}"
5757
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
58+

c89stringutils/c89stringutils_string_extras.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ typedef int errno_t;
9494
#define HAVE_STRNCASECMP_H
9595
#endif
9696

97-
#if !defined(HAVE_ASPRINTF) && (defined(ANY_BSD) || \
98-
defined(__APPLE__) && defined(__MACH__) || \
99-
defined(_GNU_SOURCE) || defined(_BSD_SOURCE))
97+
#if !defined(HAVE_ASPRINTF) && \
98+
(defined(ANY_BSD) || defined(__APPLE__) && defined(__MACH__) || \
99+
defined(_GNU_SOURCE) || defined(_BSD_SOURCE))
100100
#define HAVE_ASPRINTF
101-
#endif /* !defined(HAVE_ASPRINTF) && (defined(ANY_BSD) || \
102-
defined(__APPLE__) && defined(__MACH__) || \
101+
#endif /* !defined(HAVE_ASPRINTF) && (defined(ANY_BSD) || \
102+
defined(__APPLE__) && defined(__MACH__) || \
103103
defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) */
104104

105105
#ifdef HAVE_STRINGS_H

c89stringutils_tests/test_c89stringutils/CMakeLists.txt renamed to c89stringutils/tests/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
get_filename_component(EXEC_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
2-
string(REPLACE " " "_" EXEC_NAME "${EXEC_NAME}")
2+
set(EXEC_NAME "${PROJECT_NAME}_${EXEC_NAME}")
33

44
#########################
55
# Dependencies download #
@@ -31,9 +31,9 @@ source_group("Source Files" FILES "${Source_Files}")
3131

3232
add_executable("${EXEC_NAME}" "${Header_Files}" "${Source_Files}")
3333

34-
target_link_libraries("${EXEC_NAME}" PRIVATE "c89stringutils")
34+
target_link_libraries("${EXEC_NAME}" PRIVATE "${PROJECT_NAME}")
3535
if (NOT CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
36-
target_link_libraries("${EXEC_NAME}" PRIVATE "c89stringutils_compiler_flags")
36+
target_link_libraries("${EXEC_NAME}" PRIVATE "${PROJECT_NAME}_compiler_flags")
3737
endif (NOT CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
3838
target_include_directories(
3939
"${EXEC_NAME}"
File renamed without changes.

c89stringutils_tests/test_c89stringutils/test_string_extras.h renamed to c89stringutils/tests/test_string_extras.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <greatest.h>
22

3-
#define C89STRINGUTILS_IMPLEMENTATION
3+
// #define C89STRINGUTILS_IMPLEMENTATION
44
#include <c89stringutils_string_extras.h>
55

66
static const char *buffer = "hello world";

c89stringutils_tests/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

codecov_badge_gen.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
# shellcheck disable=SC2236
4+
if [ ! -z "${BASH_VERSION+x}" ]; then
5+
# shellcheck disable=SC3028 disable=SC3054
6+
this_file="${BASH_SOURCE[0]}"
7+
# shellcheck disable=SC3040
8+
set -o pipefail
9+
elif [ ! -z "${ZSH_VERSION+x}" ]; then
10+
# shellcheck disable=SC2296
11+
this_file="${(%):-%x}"
12+
# shellcheck disable=SC3040
13+
set -o pipefail
14+
else
15+
this_file="${0}"
16+
fi
17+
ROOT="$( cd "$( dirname -- "${this_file}" )" && pwd )"
18+
19+
# TODO: .pre-commit-config.yaml instead of this
20+
21+
COVERAGE="$(cd "${ROOT}"'/cmake-build-debug' && ctest -C 'Debug' -T 'Coverage' 2>/dev/null | awk 'END {print $NF}')"
22+
printf '<svg xmlns="http://www.w3.org/2000/svg" width="114" height="20" role="img" aria-label="coverage: %s"><title>coverage: %s</title><linearGradient id="s" x2="0" y2="%s"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="114" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="53" height="20" fill="#97ca00"/><rect width="114" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text><text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text><text aria-hidden="true" x="865" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">%s</text><text x="865" y="140" transform="scale(.1)" fill="#fff" textLength="430">%s</text></g></svg>' "${COVERAGE}" "${COVERAGE}" "${COVERAGE}" "${COVERAGE}" "${COVERAGE}" > "${ROOT}"'/reports/test_coverage.svg'

reports/test_coverage.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)