{"id":19017923,"url":"https://github.com/2hdddg/chili","last_synced_at":"2025-04-23T03:29:31.070Z","repository":{"id":141939324,"uuid":"60557306","full_name":"2hdddg/chili","owner":"2hdddg","description":"Unit tests for C in C","archived":false,"fork":false,"pushed_at":"2017-03-17T19:45:15.000Z","size":120,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-17T18:23:50.346Z","etag":null,"topics":["c","embedded-c","embedded-linux","test-framework","testrunner","unit-testing","unittest"],"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/2hdddg.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":"2016-06-06T20:07:31.000Z","updated_at":"2024-10-20T14:23:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"9567b03a-e733-4ecb-8154-39792ca60378","html_url":"https://github.com/2hdddg/chili","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2hdddg%2Fchili","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2hdddg%2Fchili/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2hdddg%2Fchili/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2hdddg%2Fchili/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2hdddg","download_url":"https://codeload.github.com/2hdddg/chili/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250364674,"owners_count":21418535,"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":["c","embedded-c","embedded-linux","test-framework","testrunner","unit-testing","unittest"],"created_at":"2024-11-08T19:51:13.439Z","updated_at":"2025-04-23T03:29:31.056Z","avatar_url":"https://github.com/2hdddg.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Chili - testrunner for C in C\n\n### What is Chili\nA test runner for C programmers that makes it easy and fun to write nice\nand slim unit tests with minimum hazzle. You write your Chili tests\ncompletely without build dependencies.\n\nChili is written in C with minimal dependencies on external libraries.\nThe idea is that Chili could be used on target for embedded development.\n\n### Installation\n```bash\n~$ make \u0026\u0026 make install\n```\nChili is Linux only.\n\n### Simplest possible unit test\n**Create new file**: unittests.c\n\n```C\n#include \u003cstdio.h\u003e\n\nint test_that_succeeds()\n{\n    printf(\"Returning 1 indicates success\\n\");\n    return 1;\n}\n```\nTests should always be named with the prefix *test_*. Also note\nthat the funcion must NOT be static.\n\n**Build the unit test:**\n```bash\n~$ gcc unittests.c -fPIC --shared -o unittests.so\n```\nThis builds a shared library with the test as an exported\nsymbol. This what Chili finds and executes.\n\n**Run the unit test:**\n```bash\n~$ chili all ./unittests.so\n./unittests.so: test_that_succeeds: Success [0]\nExecuted: 1, Succeeded: 1, Failed: 0, Errors: 0\n```\nThe *all* command executes all tests in the shared library,\nin this case only one test. \nNote that the output of *printf* is not shown in the output above, \nChili will default to suppress output of all succeeding tests.\n\n### Unit test return values\nUnit tests should always return an int and should not\ntake any parameters. Chili interprets the returned values the\nfollowing way:\n\n* Positive values are interpreted as a successful/green test.\n* Zero are interpreted as a failing/red test.\n* Negative values are interpreted as an unexpected error occured\nwhile executing the test. Chili will not execute any more tests\nin this suite when it encounters a test that returns a negative\nvalue.\n\nA test could also crash during it's execution, this is reported\nas a crash but Chili will continue executing other tests.\n\n```C\n#include \u003cstdio.h\u003e\n\nint test_that_succeeds()\n{\n    printf(\"Positive indicates success\\n\");\n    return 1;\n}\n\nint test_that_fails()\n{\n    printf(\"Zero indicates failure\\n\");\n    return 0;\n}\n\nint test_that_crashes()\n{\n    int *x = (int*)0;\n    printf(\"This will crash\\n\");\n    *x = 0;\n}\n\nint test_with_error()\n{\n    printf(\"This is an error\\n\");\n    return -1;\n}\n```\nBuild this into a shared library named unittests.so and let Chili execute the tests:\n\n```bash\n~$ chili all ./unittests.so\n./unittests.so: test_that_succeeds: Success [0]\n./unittests.so: test_that_fails: Failed [1]\n\u003e\u003e\u003eCapture start\nZero indicates failure\n\u003c\u003c\u003c Capture end\n./unittests.so: test_that_crashes: Crashed [2]\n\u003e\u003e\u003e Capture start\nThis will crash\n\u003c\u003c\u003c Capture end\n./unittests.so: test_with_error: Error [3]\n\u003e\u003e\u003e Capture start\nThis is an error\n\u003c\u003c\u003c Capture end\nExecuted: 4, Succeeded: 1, Failed: 1, Errors: 2\n```\nAs shown above prints are only shown on tests with any type of problem.\n\n### Suite setup functions\n\n### Debugging a unit test\nTo debug a problematic unit test do like this. To debug the test *test_that_crashes* in the following module.\n\n```C\n#include \u003cstdio.h\u003e\n\nint test_that_crashes()\n{\n    int *x = (int*)0;\n    printf(\"This will crash\\n\");\n    *x = 0;\n}\n```\nTo be able to debug, the tests and other linked modules need to be built with debug information:\n\n```bash\n~$ gcc unittests.c -fPIC --shared -g -o unittests.so\n```\n\nDebugging is done with Chilis debug command and the name of the test:\n```bash\n~$ chili debug ./unittests.so:test_that_crashes\nGNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1\nCopyright (C) 2016 Free Software Foundation, Inc\n...\nAttaching to process 1637\nReading symbols from ...\nReading symbols ./unittests.so..done\n...\nBreakpoint 1 at 0x7fa51cab1766: file unittest.c, line 3.\nContinuing with signal SIGCONT.\n\nBreakpoint 1, test_that_crashes () at unittest.c:3\n3       int *x = (int*)0;\n(gdb)\n```\nGdb of course needs to be installed for this to work.\n\n### Other usable commands\n\nTo list all tests in a suite use the *list* command:\n```bash\n~$ chili list ./unittests.so\n./unittests.so:test_one\n./unittests.so:test_two\n```\nFormat of listed test are on the same format that is used to run tests by name. The *named* command runs all named tests that is found in a file or from stdin:\n```bash\n~$ chili list ./unittests.so | grep two | chili named\n./unittests.so: test_two: Success [0]\nExecuted: 1, Succeeded: 1, Failed: 0, Errors: 0\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2hdddg%2Fchili","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2hdddg%2Fchili","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2hdddg%2Fchili/lists"}