Removed a warning on write(). MinGW-64 gcc takes unsigned int as length (although docs seems to say size_t?), and warns when passing result of strlen().
Removed not needed #include <process.h> for _WIN32, as getpid() is not called. <io.h> still needed for write() and isatty().
This commit removes dependency of two POSIX functions which are not supported on many non-unix/linux platforms (one exception is CYGWIN).
gettimeofday() is replaced with the standard clock() function. On windows, the kill() call is skipped, as segmentation fault will terminate the process in any case (without core-dump).
These changes enables ctest to compile and work with both MinGW gcc, clang and TINYC on Windows with SEGFAULT enabled. (TINYC on Linux misbehaves, but this is likely an issue with TINYC).
This commit adds C++ support with the following modifications:
- Remove the use of C-only features including designated initializers
and non-strict prototypes.
- Add spaces between literals and string macros to silence the C++-only
-Wliteral-suffix warning.
- Conditionally use template specialization instead of tentative
definitions to implement optional setup/teardown functions.
Note that no C++-specific features have been added. The goal of this
commit is to simply enable compiling in C++ mode.
Since we're already using `vsnprintf` and other C99 features, it's only
natural to use `snprintf` as well. Moreover, `sprintf` is "deprecated" in
Microsoft's CRT in favor of more secure (Microsoft-specific) alternatives
with its use resulting in a warning, while `snprintf` isn't (although
requires recent enough CRT).
Where GCC and Clang issue warnings such as "empty struct is a GNU extension"
(with `-Wgnu-empty-struct`) or "empty struct has size 0 in C, size 1 in C++"
(with `-Wc++-compat`), MSVC issues an error C2016 "C requires that a struct
or union has at least one member".
This eliminates "redundant redeclaration of '..._setup' [-Wredundant-decls]"
and "redundant redeclaration of '..._teardown' [-Wredundant-decls]" GCC
warnings.
Where not possible (as with `ctest::run`), suppress the warning.
This eliminates "function declaration isn't a prototype [-Wstrict-prototypes]"
GCC warning.
This eliminates "function '...' can never be inlined because it uses variable
argument lists [-Winline]" and "inlining failed in call to '...': function
not inlinable [-Winline]" GCC warnings.
Marking `CTEST_ERR` function as noreturn leads to same warning appearing
for `ctest_fail` function; marking the latter as noreturn as well leads
to warnings in user test cases which is not something we want.
This eliminates "function 'CTEST_ERR' could be declared with attribute
'noreturn' [-Wmissing-noreturn]" Clang warning.
This resulted in gaps between `ctest` structs with GCC on amd64, so adding
aligned(1) attribute to the section fix this.
This eliminates "padding struct 'struct ctest' with 4 bytes to align 'data'
[-Wpadded]" and "padding size of 'struct ctest' with 4 bytes to alignment
boundary [-Wpadded]" Clang warnings.
This eliminates "format string is not a string literal [-Wformat-nonliteral]"
(and after that "format specifies type 'void *' but the argument has type
'... *' [-Wformat-pedantic]") Clang warning.
Not using `__attribute__((unused))` as I think the warning could be useful:
if one is using CTEST2, they should be using `data`.
This eliminates "unused parameter '...' [-Wunused-parameter]" GCC/Clang
warning.
Provide prototypes for setup and teardown test case functions as making
them static is not possible due to weak linking.
Provide prototype for ctest_main function as making it static might break
existing code if someone does `#define ctest_main main`.
This eliminates "no previous prototype for function '...'
[-Wmissing-prototypes]" Clang warning.