xaizek / stic (License: MIT) (since 2018-12-07)
Simple Tests In C with optional automatic test registration in C.
Commit f510454826f1e3df1d47f4a0b760463e9f7cbb0c

Improve printing of multiline strings in stic
Python-style string literals:

Expected
"""
line1
line2
line3
"""
but was <NULL>

Instead of

Expected "line1
line2
line3
" but was <NULL>

Still not perfect as one can't see where each line ends but it's an
improvement (much easier to read and compare values visually).
Author: xaizek
Author date (UTC): 2026-06-17 16:55
Committer name: xaizek
Committer date (UTC): 2026-07-26 09:37
Parent(s): e382819e288f79bad512805598ffa622b24958fc
Signing key: 99DC5E4DB05F6BE2
Tree: af91d731789bf8ecf40651ccb8b4cde03f426b87
File Lines added Lines deleted
src/stic.c 20 6
File src/stic.c changed (mode: 100644) (index 7c6a900..330c140)
... ... void stic_assert_string_equal(const char* expected, const char* actual, const ch
342 342 { {
343 343 int comparison; int comparison;
344 344 char s[STIC_PRINT_BUFFER_SIZE]; char s[STIC_PRINT_BUFFER_SIZE];
345 const char *quote;
346
347 quote = "\"";
348 if ((actual != NULL && strchr(actual, '\n') != NULL) || (expected != NULL && strchr(expected, '\n') != NULL))
349 {
350 quote = "\n\"\"\"\n";
351 }
345 352
346 353 if ((expected == (char *)0) && (actual == (char *)0)) if ((expected == (char *)0) && (actual == (char *)0))
347 354 { {
 
... ... void stic_assert_string_equal(const char* expected, const char* actual, const ch
350 357 } }
351 358 else if (expected == (char *)0) else if (expected == (char *)0)
352 359 { {
353 snprintf(s, sizeof(s), "Expected <NULL> but was \"%s\"", actual);
360 snprintf(s, sizeof(s), "Expected <NULL> but was %s%s%s", quote, actual, quote);
354 361 comparison = 0; comparison = 0;
355 362 } }
356 363 else if (actual == (char *)0) else if (actual == (char *)0)
357 364 { {
358 snprintf(s, sizeof(s), "Expected \"%s\" but was <NULL>", expected);
365 snprintf(s, sizeof(s), "Expected %s%s%s but was <NULL>", quote, expected, quote);
359 366 comparison = 0; comparison = 0;
360 367 } }
361 368 else else
362 369 { {
363 370 comparison = strcmp(expected, actual) == 0; comparison = strcmp(expected, actual) == 0;
364 snprintf(s, sizeof(s), "Expected \"%s\" but was \"%s\"", expected, actual);
371 snprintf(s, sizeof(s), "Expected %s%s%s but was %s%s%s", quote, expected, quote, quote, actual, quote);
365 372 } }
366 373
367 374 stic_simple_test_result(comparison, s, function, file, line); stic_simple_test_result(comparison, s, function, file, line);
 
... ... void stic_assert_wstring_equal(const wchar_t expected[], const wchar_t actual[],
371 378 { {
372 379 int comparison; int comparison;
373 380 char s[STIC_PRINT_BUFFER_SIZE]; char s[STIC_PRINT_BUFFER_SIZE];
381 const char *quote;
382
383 quote = "\"";
384 if ((actual != NULL && wcschr(actual, L'\n') != NULL) || (expected != NULL && wcschr(expected, L'\n') != NULL))
385 {
386 quote = "\n\"\"\"\n";
387 }
374 388
375 389 if ((expected == NULL) && (actual == NULL)) if ((expected == NULL) && (actual == NULL))
376 390 { {
 
... ... void stic_assert_wstring_equal(const wchar_t expected[], const wchar_t actual[],
380 394 else if (expected == NULL) else if (expected == NULL)
381 395 { {
382 396 #ifdef STIC_C99 #ifdef STIC_C99
383 snprintf(s, sizeof(s), "Expected <NULL> but was \"%ls\"", actual);
397 snprintf(s, sizeof(s), "Expected <NULL> but was %s%ls%s", quote, actual, quote);
384 398 #else #else
385 399 snprintf(s, sizeof(s), "Expected <NULL> but was wide string"); snprintf(s, sizeof(s), "Expected <NULL> but was wide string");
386 400 #endif #endif
 
... ... void stic_assert_wstring_equal(const wchar_t expected[], const wchar_t actual[],
389 403 else if (actual == NULL) else if (actual == NULL)
390 404 { {
391 405 #ifdef STIC_C99 #ifdef STIC_C99
392 snprintf(s, sizeof(s), "Expected \"%ls\" but was <NULL>", expected);
406 snprintf(s, sizeof(s), "Expected %s%ls%s but was <NULL>", quote, expected, quote);
393 407 #else #else
394 408 snprintf(s, sizeof(s), "Expected wide string but was <NULL>"); snprintf(s, sizeof(s), "Expected wide string but was <NULL>");
395 409 #endif #endif
 
... ... void stic_assert_wstring_equal(const wchar_t expected[], const wchar_t actual[],
399 413 { {
400 414 comparison = wcscmp(expected, actual) == 0; comparison = wcscmp(expected, actual) == 0;
401 415 #ifdef STIC_C99 #ifdef STIC_C99
402 snprintf(s, sizeof(s), "Expected \"%ls\" but was \"%ls\"", expected, actual);
416 snprintf(s, sizeof(s), "Expected %s%ls%s but was %s%ls%s", quote, expected, quote, quote, actual, quote);
403 417 #else #else
404 418 snprintf(s, sizeof(s), "Expected wide string doesn't match"); snprintf(s, sizeof(s), "Expected wide string doesn't match");
405 419 #endif #endif
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/stic

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/stic

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master