Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittest redesign #58

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ APP = test_suite
# bar/file3
# -----------------------------------------------------------------------------

FILES_PRJ = test/test_suite
FILES_PRJ = test/test_suite printf


# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -85,7 +85,7 @@ VPATH := $(sort $(dir $(FILES_TMP)))
# ------------------------------------------------------------------------------
AR = $(PATH_TOOLS_CC)ar
AS = $(PATH_TOOLS_CC)g++
CC = $(PATH_TOOLS_CC)g++
CC = $(PATH_TOOLS_CC)gcc
CL = $(PATH_TOOLS_CC)g++
NM = $(PATH_TOOLS_CC)nm
GCOV = $(PATH_TOOLS_CC)gcov
Expand All @@ -107,7 +107,6 @@ SED = $(PATH_TOOLS_UTIL)sed

GCCFLAGS = $(C_INCLUDES) \
$(C_DEFINES) \
-std=c++11 \
-g \
-Wall \
-pedantic \
Expand All @@ -124,23 +123,21 @@ GCCFLAGS = $(C_INCLUDES) \
-Winit-self \
-Wdouble-promotion \
-gdwarf-2 \
-fno-exceptions \
-O2 \
-ffunction-sections \
-ffat-lto-objects \
-fdata-sections \
-fverbose-asm \
-Wextra \
-Wunused-parameter \
-Wfloat-equal

CFLAGS = $(GCCFLAGS) \
-Wunsuffixed-float-constants \
-x c \
-std=c99

CPPFLAGS = $(GCCFLAGS) \
-x c++ \
-std=c++11 \
-fno-rtti \
-fstrict-enums \
-fno-use-cxa-atexit \
Expand Down Expand Up @@ -251,7 +248,7 @@ $(TRG)_nm.txt : $(TRG)
# ...and Create an assembly listing using objdump
# ...and Generate a dependency file (using the -MM flag)
@-$(CL) $(CPPFLAGS) $< -E -o $(PATH_PRE)/$(basename $(@F)).pre
@-$(CL) $(CPPFLAGS) $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err
@-$(CL) $(CPPFLAGS) -O $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err
@-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|:\([0-9]*\):|(\1) :|' $(PATH_ERR)/$(basename $(@F)).err
@-$(OBJDUMP) --disassemble --line-numbers -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_LST)/$(basename $(@F)).lst
@-$(CL) $(CPPFLAGS) $< -MM > $(PATH_OBJ)/$(basename $(@F)).d
Expand All @@ -269,3 +266,4 @@ $(TRG)_nm.txt : $(TRG)
@-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|:\([0-9]*\):|(\1) :|' $(PATH_ERR)/$(basename $(@F)).err
@-$(OBJDUMP) -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_LST)/$(basename $(@F)).lst
@-$(CC) $(CFLAGS) $< -MM > $(PATH_OBJ)/$(basename $(@F)).d
@-$(CL) $(CFLAGS) -O0 --coverage $< -c -o $(PATH_COV)/$(basename $(@F)).o 2> $(PATH_NUL)
15 changes: 5 additions & 10 deletions printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <stdbool.h>
#include <stdint.h>
#include <limits.h>

#include "printf.h"

Expand Down Expand Up @@ -822,16 +823,10 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
case 'p' : {
width = sizeof(void*) * 2U;
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
#if defined(PRINTF_SUPPORT_LONG_LONG)
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
if (is_ll) {
idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags);
}
else {
#endif
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, precision, width, flags);
#if defined(PRINTF_SUPPORT_LONG_LONG)
}
#if defined(PRINTF_SUPPORT_LONG_LONG) && (LONG_MAX < UINTPTR_MAX)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should be if defined(PRINTF_SUPPORT_LONG_LONG) && (ULONG_MAX < UINTPTR_MAX). The current test selects the long long code even for 32-bit pointers on targets with 32-bit longs as LONG_MAX < ULONG_MAX is always true. Writing this comparison as (UINTPTR_MAX > ULONG_MAX) might be more readable.

idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags);
#else
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, precision, width, flags);
#endif
format++;
break;
Expand Down
13 changes: 13 additions & 0 deletions test/catch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9599,6 +9599,15 @@ namespace Catch {
}
return names.substr(start, end - start + 1);
};
auto skipq = [&] (size_t start, char quote) {
for (auto i = start + 1; i < names.size() ; ++i) {
if (names[i] == quote)
return i;
if (names[i] == '\\')
++i;
}
assert(0 && "Mismatched quotes");
};

size_t start = 0;
std::stack<char> openings;
Expand All @@ -9619,6 +9628,10 @@ namespace Catch {
// case '>':
openings.pop();
break;
case '"':
case '\'':
pos = skipq(pos, c);
break;
case ',':
if (start != pos && openings.size() == 0) {
m_messages.emplace_back(macroName, lineInfo, resultType);
Expand Down
Loading