Set up test framework with demo test

This commit is contained in:
Daniel Thorpe 2024-06-20 15:56:30 +01:00
parent 9dd0c42ca7
commit 2a8be1c462
No known key found for this signature in database
5 changed files with 39 additions and 4 deletions

View File

@ -1,5 +1,6 @@
add_library(gemhadar_lib
"fd_io.c"
"url.c"
)
target_include_directories(gemhadar_lib PUBLIC "include")
set_property(TARGET gemhadar_lib PROPERTY C_STANDARD 11)

6
lib/include/url.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef URL_H
#define URL_H
int foo(void);
#endif

6
lib/url.c Normal file
View File

@ -0,0 +1,6 @@
#include "url.h"
int foo(void)
{
return 42;
}

View File

@ -1,6 +1,9 @@
add_library(test_lib
"test_io.c"
)
target_include_directories(test_lib PUBLIC "include")
add_library(test_lib "test_io.c")
set_property(TARGET test_lib PROPERTY C_STANDARD 11)
target_include_directories(test_lib PUBLIC "include")
target_link_libraries(test_lib gemhadar_lib)
add_executable(url_tests "url_tests.c")
set_property(TARGET test_lib PROPERTY C_STANDARD 11)
target_link_libraries(url_tests gemhadar_lib test_lib)
add_test(NAME "URL tests" COMMAND url_tests)

19
test/url_tests.c Normal file
View File

@ -0,0 +1,19 @@
#include "greatest.h"
#include "url.h"
TEST foo_returns_42(void)
{
ASSERT_EQ(42, foo());
PASS();
}
GREATEST_MAIN_DEFS();
int main(int argc, char *argv[])
{
GREATEST_MAIN_BEGIN();
RUN_TEST(foo_returns_42);
GREATEST_MAIN_END();
}