Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
pks-t committed Sep 7, 2024
1 parent 678e1c0 commit 2902e7d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
17 changes: 5 additions & 12 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ target_sources(clar_test PRIVATE
)
target_compile_definitions(clar_test PRIVATE
CLAR_FIXTURE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/expected/"
SELFTEST_BINARY_PATH="$<TARGET_FILE:selftest>"
_DARWIN_C_SOURCE
_POSIX_C_SOURCE=200809L
)
Expand All @@ -43,21 +42,15 @@ target_include_directories(clar_test PRIVATE
)
target_link_libraries(clar_test clar)

add_test(build_selftest
"${CMAKE_COMMAND}"
--build "${CMAKE_BINARY_DIR}"
--config "$<CONFIG>"
--target selftest
add_test(NAME build_selftest
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config "$<CONFIG>" --target selftest
)
set_tests_properties(build_selftest PROPERTIES FIXTURES_SETUP clar_test_fixture)

add_test(build_test
"${CMAKE_COMMAND}"
--build "${CMAKE_BINARY_DIR}"
--config "$<CONFIG>"
--target clar_test
add_test(NAME build_test
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config "$<CONFIG>" --target clar_test
)
set_tests_properties(build_test PROPERTIES FIXTURES_SETUP clar_test_fixture)

add_test(clar_test "${CMAKE_CURRENT_BINARY_DIR}/clar_test")
add_test(NAME clar_test COMMAND "${CMAKE_CURRENT_BINARY_DIR}/clar_test" "$<TARGET_FILE:selftest>")
set_tests_properties(clar_test PROPERTIES FIXTURES_REQUIRED clar_test_fixture)
6 changes: 3 additions & 3 deletions test/clar.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string.h>
#include <sys/stat.h>

#include "clar.h"
#include "clar_test.h"

#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -110,7 +110,7 @@ static void run(const char *expected_output_file, int expected_error_code, ...)
startup_info.hStdError = stdout_write;
startup_info.hStdOutput = stdout_write;
startup_info.dwFlags |= STARTF_USESTDHANDLES;
cl_assert_equal_b(1, CreateProcess(SELFTEST_BINARY_PATH, cmdline, NULL, NULL, TRUE,
cl_assert_equal_b(1, CreateProcess(selftest_binary_path, cmdline, NULL, NULL, TRUE,
0, NULL, NULL, &startup_info, &process_info));
cl_assert_equal_b(1, CloseHandle(stdout_write));

Expand Down Expand Up @@ -210,7 +210,7 @@ static void run(const char *expected_output_file, int expected_error_code, ...)
close(pipe_fds[1]) < 0)
exit(1);

execv(SELFTEST_BINARY_PATH, (char **) argv);
execv(selftest_binary_path, (char **) argv);
exit(1);
} else if (pid > 0) {
pid_t waited_pid;
Expand Down
3 changes: 3 additions & 0 deletions test/clar_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "clar.h"

extern const char *selftest_binary_path;
17 changes: 16 additions & 1 deletion test/main.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
#include "clar.h"
#include <stdio.h>
#include <string.h>

#include "clar_test.h"

const char *selftest_binary_path;

#ifdef _WIN32
int __cdecl main(int argc, char *argv[])
#else
int main(int argc, char *argv[])
#endif
{
if (argc < 2) {
fprintf(stderr, "USAGE: %s <SELFTEST_EXECUTABLE> <OPTIONS>\n",
argv[0]);
exit(1);
}

selftest_binary_path = argv[1];
memmove(argv, argv + 1, argc);
argc -= 1;

return clar_test(argc, argv);
}

0 comments on commit 2902e7d

Please sign in to comment.