{"id":23888430,"url":"https://github.com/usmanmehmood55/c_asserts","last_synced_at":"2025-07-16T17:34:03.361Z","repository":{"id":194949709,"uuid":"691982340","full_name":"usmanmehmood55/c_asserts","owner":"usmanmehmood55","description":"A very basic assertion library written in C","archived":false,"fork":false,"pushed_at":"2024-07-25T09:11:45.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T04:41:43.777Z","etag":null,"topics":["assert","c","unit-testing"],"latest_commit_sha":null,"homepage":"","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/usmanmehmood55.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-15T09:54:33.000Z","updated_at":"2024-07-25T09:11:48.000Z","dependencies_parsed_at":"2025-01-04T20:03:51.839Z","dependency_job_id":null,"html_url":"https://github.com/usmanmehmood55/c_asserts","commit_stats":null,"previous_names":["usmanmehmood55/c_asserts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/usmanmehmood55/c_asserts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fc_asserts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fc_asserts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fc_asserts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fc_asserts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usmanmehmood55","download_url":"https://codeload.github.com/usmanmehmood55/c_asserts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fc_asserts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265527598,"owners_count":23782480,"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","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":["assert","c","unit-testing"],"created_at":"2025-01-04T09:00:24.812Z","updated_at":"2025-07-16T17:34:03.337Z","avatar_url":"https://github.com/usmanmehmood55.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C Asserts Library\n\nThe C Asserts Library is a rudimentary assertion library written in C. The library \nis designed to facilitate simple unit testing by providing straightforward macros \nand utilities for testing conditions within C programs. If a test condition fails, \nthe library will output the file, line number, and function where the failure \noccurred.\n\n## Features\n- Assert tests with the `ASSERT_TEST(condition)` macro.\n- Automatic tracking of total, passed, and failed tests.\n- Display test summary at the end of your test suite.\n\n## Requirements\n- GCC\n- CMake\n\n## Usage\nHere's a quick example that demonstrates how to use the library:\n```c\n#include \"c_asserts.h\"\n\nstatic bool passing_function_1(void)\n{\n    int a = 1;\n    int b = 2;\n    int c = a + b;\n\n    ASSERT_TEST(c == 3);\n    return true;\n}\n\nstatic bool passing_function_2(void)\n{\n    char * string = \"this is a string\";\n\n    ASSERT_TEST(strcmp(string, \"this is a string\") == 0);;\n    return true;\n}\n\nstatic bool failing_function(void)\n{\n    ASSERT_TEST(1 == 2);  // This will fail\n    return true;\n}\n\nstatic bool passing_function_3(void)\n{\n    int upper_limit = 20;\n    int lower_limit = 15;\n    srand(time(NULL));\n    int random_number = ((rand() % (upper_limit - lower_limit + 1)) + lower_limit);\n\n    ASSERT_TEST(random_number \u003c= upper_limit);\n    ASSERT_TEST(random_number \u003e= lower_limit);\n    return true;\n}\n\nint main(void)\n{\n    TEST(passing_function_1);\n    TEST(passing_function_2);\n    TEST(failing_function);\n    TEST(passing_function_3);\n\n    return display_test_summary();\n}\n```\n\n### Output\n![image](https://github.com/usmanmehmood55/c_asserts/assets/27913231/e27cfae5-98d0-4891-ad24-5c1d04977f01)\n\n### Assertions\nUse `ASSERT_TEST(condition)` to assert that a condition is true:\n```c\nASSERT_TEST(x \u003e 0);\n```\n\n### Running Tests\nUse `TEST(func)` to run a test function:\n\n```c\nTEST(my_test_function);\n```\n\n### Displaying Summary\nAt the end of your test suite, you can display the test summary:\n```c\nreturn display_test_summary();\n```\n\nThis will print the total number of tests, the number of passed tests, and the \nnumber of failed tests.\n\n## Installation\nTo install the library, clone this repository as a submodule\ngit submodule in your project\n```bash\ngit submodule add https://github.com/usmanmehmood55/c_asserts.git .\ngit submodule update --init --recursive\n```\n\nThen in your root CMakeLists.txt, add the library by including its subdirectory\n```bash\nadd_subdirectory(c_asserts)\n```\n\nAnd also link it with the executable\n```bash\ntarget_link_libraries(${PROJECT_NAME} PRIVATE c_asserts_obj)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusmanmehmood55%2Fc_asserts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusmanmehmood55%2Fc_asserts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusmanmehmood55%2Fc_asserts/lists"}