Skip to content

Commit

Permalink
Merge pull request #100 from pks-t/pks-ci-win32
Browse files Browse the repository at this point in the history
ci: wire up support for Win32
  • Loading branch information
ethomson committed Sep 19, 2024
2 parents 614d38d + 7426a25 commit 94461c1
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 68 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@ jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
platform:
- os: ubuntu-latest
generator: Unix Makefiles
- os: macos-latest
generator: Unix Makefiles
- os: windows-latest
generator: Visual Studio 17 2022
- os: windows-latest
generator: MSYS Makefiles
- os: windows-latest
generator: MinGW Makefiles

runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.platform.os }}

steps:
- name: Check out
uses: actions/checkout@v2
- name: Build
run: |
cd test
make
mkdir build
cd build
cmake .. -G "${{matrix.platform.generator}}"
cmake --build .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
28 changes: 28 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.16..3.29)

project(clar LANGUAGES C)

option(BUILD_TESTS "Build test executable" ON)

add_library(clar INTERFACE)
target_sources(clar INTERFACE
clar.c
clar.h
clar/fixtures.h
clar/fs.h
clar/print.h
clar/sandbox.h
clar/summary.h
)
set_target_properties(clar PROPERTIES
C_STANDARD 90
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
endif()
24 changes: 5 additions & 19 deletions clar.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <stdarg.h>
#include <wchar.h>
#include <time.h>
#include <inttypes.h>

/* required for sandboxing */
#include <sys/types.h>
Expand Down Expand Up @@ -61,13 +62,6 @@
# define p_snprintf snprintf
# endif

# ifndef PRIuZ
# define PRIuZ "Iu"
# endif
# ifndef PRIxZ
# define PRIxZ "Ix"
# endif

# if defined(_MSC_VER) || (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR))
typedef struct stat STAT_T;
# else
Expand All @@ -78,12 +72,6 @@
# include <unistd.h>
# define _MAIN_CC
# define p_snprintf snprintf
# ifndef PRIuZ
# define PRIuZ "zu"
# endif
# ifndef PRIxZ
# define PRIxZ "zx"
# endif
typedef struct stat STAT_T;
#endif

Expand All @@ -102,7 +90,7 @@ fixture_path(const char *base, const char *fixture_name);
struct clar_error {
const char *file;
const char *function;
size_t line_number;
uintmax_t line_number;
const char *error_msg;
char *description;

Expand Down Expand Up @@ -271,9 +259,7 @@ static double clar_time_diff(clar_time *start, clar_time *end)

static void clar_time_now(clar_time *out)
{
struct timezone tz;

gettimeofday(out, &tz);
gettimeofday(out, NULL);
}

static double clar_time_diff(clar_time *start, clar_time *end)
Expand Down Expand Up @@ -798,8 +784,8 @@ void clar__assert_equal(
}
}
}
else if (!strcmp("%"PRIuZ, fmt) || !strcmp("%"PRIxZ, fmt)) {
size_t sz1 = va_arg(args, size_t), sz2 = va_arg(args, size_t);
else if (!strcmp("%"PRIuMAX, fmt) || !strcmp("%"PRIxMAX, fmt)) {
uintmax_t sz1 = va_arg(args, uintmax_t), sz2 = va_arg(args, uintmax_t);
is_equal = (sz1 == sz2);
if (!is_equal) {
int offset = p_snprintf(buf, sizeof(buf), fmt, sz1);
Expand Down
4 changes: 2 additions & 2 deletions clar/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void clar_print_clap_error(int num, const struct clar_report *report, con
{
printf(" %d) Failure:\n", num);

printf("%s::%s [%s:%"PRIuZ"]\n",
printf("%s::%s [%s:%"PRIuMAX"]\n",
report->suite,
report->test,
error->file,
Expand Down Expand Up @@ -136,7 +136,7 @@ static void clar_print_tap_ontest(const char *suite_name, const char *test_name,

printf(" at:\n");
printf(" file: '"); print_escaped(error->file); printf("'\n");
printf(" line: %" PRIuZ "\n", error->line_number);
printf(" line: %" PRIuMAX "\n", error->line_number);
printf(" function: '%s'\n", error->function);
printf(" ---\n");

Expand Down
4 changes: 0 additions & 4 deletions test/.gitignore

This file was deleted.

41 changes: 41 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
find_package(Python COMPONENTS Interpreter REQUIRED)

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/clar.suite"
COMMAND "${Python_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/generate.py" --output "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS main.c sample.c clar_test.h
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)

add_executable(clar_test)
set_target_properties(clar_test PROPERTIES
C_STANDARD 90
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
)

# MSVC generates all kinds of warnings. We may want to fix these in the future
# and then unconditionally treat warnings as errors.
if(NOT MSVC)
set_target_properties(clar_test PROPERTIES
COMPILE_WARNING_AS_ERROR ON
)
endif()

target_sources(clar_test PRIVATE
main.c
sample.c
"${CMAKE_CURRENT_BINARY_DIR}/clar.suite"
)
target_compile_definitions(clar_test PRIVATE
CLAR_FIXTURE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/"
_DARWIN_C_SOURCE
_POSIX_C_SOURCE=200809L
)
target_compile_options(clar_test PRIVATE
$<IF:$<CXX_COMPILER_ID:MSVC>,/W4,-Wall>
)
target_include_directories(clar_test PRIVATE
"${CMAKE_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
)
target_link_libraries(clar_test clar)
39 changes: 0 additions & 39 deletions test/Makefile

This file was deleted.

0 comments on commit 94461c1

Please sign in to comment.