{"id":15904492,"url":"https://github.com/parrt/c_unit","last_synced_at":"2025-08-01T14:04:43.733Z","repository":{"id":66099930,"uuid":"48771385","full_name":"parrt/c_unit","owner":"parrt","description":"A C unit testing rig in the spirit of junit.","archived":false,"fork":false,"pushed_at":"2016-01-02T23:35:38.000Z","size":17,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T20:45:25.488Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parrt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-29T23:22:32.000Z","updated_at":"2023-08-01T01:33:11.000Z","dependencies_parsed_at":"2023-03-16T20:00:32.505Z","dependency_job_id":null,"html_url":"https://github.com/parrt/c_unit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/parrt/c_unit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parrt%2Fc_unit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parrt%2Fc_unit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parrt%2Fc_unit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parrt%2Fc_unit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parrt","download_url":"https://codeload.github.com/parrt/c_unit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parrt%2Fc_unit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268240351,"owners_count":24218356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-06T12:40:26.492Z","updated_at":"2025-08-01T14:04:43.698Z","avatar_url":"https://github.com/parrt.png","language":"C","readme":"# c_unit -- C unit testing rig\n\nA simple testing rig in C that is easy to use but has decent functionality. Developed by Terence Parr, Hanzhou Shi, Shuai Yuan, Yuanyuan Zhang at University of San Francisco.\n\nSample usage:\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"c_unit.h\"\n\nstatic void setup() {\n}\n\nstatic void teardown() {\n}\n\nvoid stuff() {\n\tassert_float_equal(1.0, 1.0);\n\tassert_true(1);\n\tassert_false(0);\n\tchar *p = malloc(10);\n\tchar *q = p;\n\tassert_addr_equal(p,q);\n\tchar *r = NULL;\n\tassert_addr_not_equal(p,r);\n\tfree(p); // leave this off and valgrind will complain\n}\n\nvoid other_stuff() {\n\tassert_str_not_equal(\"hi\", \"mom\");\n}\n\nvoid bad_ptr() {\n\tchar *p = (char *)0x100;\n\t*p = 'a';\n}\n\nvoid bad_test() {\n\tassert_str_equal(\"foo\", \"bar\");\n}\n\nint main(int argc, char *argv[])\n{\n\tc_unit_setup = setup;\n\tc_unit_teardown = teardown;\n\n\ttest(stuff);\n\ttest(other_stuff);\n\n\ttest(bad_test);\n\n\t// uncomment next line to test a bad memory reference, forcing program to bail out with non-0 error code\n//\ttest(bad_ptr);\n\n\treturn c_unit_fails; // return how many test()s failed.  ctest likes 0 return value to mean no failures\n}\n```\n\n```bash\n$ cmake CMakeLists.txt\n...\n$ make\n$ ./demo\nPASS stuff\nPASS other_stuff\nassertion failure in bad_test: strcmp \"foo\" == \"bar\" (foo == bar)\nFAIL bad_test\ntest bad_ptr is confused; signal SIGSEGV (11)\n```\n\nYou can also run with ctest via cmake:\n\n```bash\n$ make test\nRunning tests...\nTest project /Users/parrt/github/c_unit\n    Start 1: sample_test\n1/1 Test #1: sample_test ......................***Failed    0.00 sec\n\n0% tests passed, 1 tests failed out of 1\n\nTotal Test time (real) =   0.00 sec\n\nThe following tests FAILED:\n\t  1 - sample_test (Failed)\nErrors while running CTest\nmake: *** [test] Error 8\n```\n\nThis cmake build uses valgrind for memory checking, which will cause failure upon memory leak.\n\nTo see all output, use `-V`:\n\n```bash\n$ ctest -V\n...\ntest 1\n    Start 1: sample_test\n\n1: Test command: /usr/local/bin/valgrind \"--error-exitcode=1\" \"--tool=memcheck\" \"--leak-check=full\" \"./sample_test\"\n...\n1: ==22403== Command: ./sample_test\n1: ==22403== \n1: PASS stuff\n1: PASS other_stuff\n1: assertion failure in bad_test: strcmp \"foo\" == \"bar\" (foo == bar)\n1: --22403:0:syswrap- WARNING: Ignoring sigreturn( ..., UC_RESET_ALT_STACK );\n1: FAIL bad_test\n1: ==22403== \n1: ==22403== HEAP SUMMARY:\n1: ==22403==     in use at exit: 34,917 bytes in 417 blocks\n1: ==22403==   total heap usage: 518 allocs, 101 frees, 41,903 bytes allocated\n1: ==22403== \n1: ==22403== LEAK SUMMARY:\n1: ==22403==    definitely lost: 0 bytes in 0 blocks\n1: ==22403==    indirectly lost: 0 bytes in 0 blocks\n1: ==22403==      possibly lost: 0 bytes in 0 blocks\n1: ==22403==    still reachable: 0 bytes in 0 blocks\n1: ==22403==         suppressed: 34,917 bytes in 417 blocks\n1: ==22403== \n1: ==22403== For counts of detected and suppressed errors, rerun with: -v\n1: ==22403== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 16 from 16)\n1/1 Test #1: sample_test ......................***Failed    0.89 sec\n\n0% tests passed, 1 tests failed out of 1\n\nTotal Test time (real) =   0.89 sec\n\nThe following tests FAILED:\n\t  1 - sample_test (Failed)\nErrors while running CTest\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparrt%2Fc_unit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparrt%2Fc_unit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparrt%2Fc_unit/lists"}