From c1c7296bfa949c4f5dd7c7b3b749920cb838bfca Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 8 Jun 2026 08:18:43 +0200 Subject: [PATCH] Add a test for fmt_print --- src/fmt-c.cc | 1 + test/c-test.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/fmt-c.cc b/src/fmt-c.cc index be1e5278..d5945ea9 100644 --- a/src/fmt-c.cc +++ b/src/fmt-c.cc @@ -10,6 +10,7 @@ #include constexpr size_t max_c_format_args = 16; + static int convert_c_format_args( fmt::basic_format_arg* format_args, const fmt_arg* args, size_t num_args) { diff --git a/test/c-test.c b/test/c-test.c index 81c9bdfb..db7c8360 100644 --- a/test/c-test.c +++ b/test/c-test.c @@ -83,10 +83,30 @@ void test_buffer_size_query(void) { ASSERT_INT_EQ(size, 15); } +void test_print(void) { + FILE* file = tmpfile(); + if (!file) { + fprintf(stderr, "\nFailed to create temporary file\n"); + exit(1); + } + + int ret = fmt_print(file, "{} and {}", 42, "foo"); + ASSERT_INT_EQ(ret, 0); + + rewind(file); + char buf[100]; + size_t n = fread(buf, 1, sizeof(buf) - 1, file); + buf[n] = '\0'; + ASSERT_STR_EQ(buf, "42 and foo"); + + fclose(file); +} + int main(void) { printf("Running C API tests\n"); test_types(); test_zero_arguments(); test_buffer_size_query(); + test_print(); printf("C API tests passed\n"); }