{"id":21703733,"url":"https://github.com/carvilsi/cst","last_synced_at":"2025-03-20T16:48:36.026Z","repository":{"id":222305150,"uuid":"691912745","full_name":"carvilsi/cst","owner":"carvilsi","description":"C Simple Test","archived":false,"fork":false,"pushed_at":"2024-05-07T15:47:11.000Z","size":188,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-25T15:41:34.598Z","etag":null,"topics":["c","testing","testsuite"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/carvilsi.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-15T06:46:54.000Z","updated_at":"2024-05-07T15:47:00.000Z","dependencies_parsed_at":"2024-02-13T15:09:39.039Z","dependency_job_id":"cefa05a8-0c75-416b-b7d5-df1915111d59","html_url":"https://github.com/carvilsi/cst","commit_stats":null,"previous_names":["carvilsi/cst"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carvilsi%2Fcst","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carvilsi%2Fcst/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carvilsi%2Fcst/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carvilsi%2Fcst/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carvilsi","download_url":"https://codeload.github.com/carvilsi/cst/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244656646,"owners_count":20488638,"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","testing","testsuite"],"created_at":"2024-11-25T21:35:06.286Z","updated_at":"2025-03-20T16:48:35.997Z","avatar_url":"https://github.com/carvilsi.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n:ferris_wheel: Reinventing The Wheel Group presents :ferris_wheel:\n\nC Simple Test\n\nThere are lot of c test frameworks, but this is mine.\n\u003c/div\u003e\n\n---\n\n# CST\n\n1. [Introduction](#introduction)\n2. [Basic Syntax](#basic-syntax)\n3. [Output Example](#output-example)\n4. [Usage](#usage)\n5. [Long Answer](#long-answer)\n\n## Introduction\n\nHere we are trying to keep the c tests approach **simple** as possible; also trying to add some beauty to it like adding colors etc. Ok, there are some developers with a very strong negative opinion about colors around the terminal. I love colors, and most for test and logs outputs though. \n\n* Why reinventing the wheel here, writting another test framework for c?\n\n**TL;DR:** Just because \u0026 'cause it's fun.\n\nFor a more elaborated, but still non-sense, answer check [Long Answer](#long-answer) section.\n\n## Basic Syntax\u003ca name=\"basic-syntax\"/\u003e\n\n### integer and string assertion\n\nFor an integer use **cst_i** for a string **cst_s** or the not equal for both **cst_i_ne** and **cst_s_ne**.\n\nThese 4 functions expects 3 arguments:\n\n1. function_to_test()\n2. \"assertion text\"\n3. expected_value\n\n* assert an integer\n\n```c\n//             |-\u003e the function to test or actual value \n//             |                                |-\u003e text for the assertion\n//             |                                |                   |-\u003e the expected value\n//             |                                |                   |    \ncst_i(add_numbers(2, 2), \"should do addition for 2 + 2 and return\", 4); \n                         \n// a value different than\ncst_i_ne(add_numbers(1, 1), \"should do addition for 1 + 2 and return a different value than\", 3);\n```\n\n* assert a string\n\n```c\n// assert a string \ncst_s(give_me_a_string(), \"should give me\", \"a string\");\n\n// string not equal\ncst_s_ne(give_me_a_string(), \"should NOT give me\", \"foobar\");\n```\n\n### raw or generic assert\n\nUse the **cst_a** function that expects two arguments:\n\n1. \"text for the assertion\"\n2. a condition\n\n* raw assert\n\n```c\n//                      |-\u003e text for the assertion\n//                      |                                          |-\u003e the condition to test\n//                      |                                          |\ncst_a(\"the adition of 2 + 5 should retrieve 7\", add_numbers(2, 5) == 7);\n\ncst_a(\"the variable should be 'foobar'\", strcmp(variable, \"foobar\") == 0);\n        \ncst_a(\"the variable should not be NULL\", variable != NULL);\n```\n\n## Output example\u003ca name=\"output-example\"/\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/images/test-output.png\" alt=\"test-output\"\u003e\n\u003c/p\u003e\n\n## Usage\n\nOn your test file, include **cst.h** and the header files from your code that has the functions that you want to test. At the test file, call all the tests and then call the **cst_results()** function.\n\nUnder the **examples** directory you'll find the whole setup and file structure and basic usage.\n\nThe structure for testing could be something like this:\n\n```\nmy_code/\n├── README.md\n├── src\n│   ├── dep.c\n│   ├── dep.h\n│   └── main.c\n└── tests\n    ├── cst_example.c\n    ├── cst.c\n    ├── cst.h\n    └── Makefile\n```\n\nPut **cst.c** and **cst.h** somewhere (on test folder is fine, I did not in order to not duplicate files) and point to the **cst.c** on your **Makefile** and the c files from your tests. Something like:\n\n`$(CC) $(CCFLAGS) -o $@ $(SRC) ./../../cst.c cst_example.c $(LIBS)`\n\n Remember to not include your **main.c** file from your source code. This would be usefull:\n\n`SRC := $(shell find ./../src/ -type f -name '*.c' ! -name 'main.c')` \n\n**tip:** reusing the **Makefile** at *examples/tests/* and modifying the **cst** files location and tests c files should do the work.\n\nThen go to the *tests* fodler and run:\n\n`$ make clean \u0026\u0026 make`\n \n## Long Answer\u003ca name=\"long-answer\"/\u003e\n\nThe **More long answer:** For a personal c project, I face the Eternal Return or Eternal Recurrence of the leak of test.\nJust to ilustrate the situation consider the next sequence:\n\n1. Starts as a fun PoC, with few lines of code. So I do not even think about writing tests, just the stuff working is a \"test\" itself.\n2. I like it and I start cleaning the code, do some refactors.\n3. I add some functionality that came out to my mind during steps 1 \u0026 2, the lines starts growing. Still so small to write any test though.\n4. I leave the project for several weeks.\n5. I start working again on the personal project, I had some new ideas. More lines, more files, more functionalities, more refactoring. \n .  The idea about having some tests starts to cross my mind; but hey still something small.\n6. If I continue with the idea, I could repeat 4 and 5 several times.\n7. Once again I regret myself about the absence of tests. I did not learn the lesson yet. Write the f** tests at least on step 3 or 5! \n\nSo for first time (dealing with c) I was facing step 7 and I decided to add tests. Then; do a search on *StackOverflow*; try lot of things.\nMost of the alternatives that I found required to install dependecies or was so much complicated compared with my current needs.\nSuddenly I found this brilliant answer at StackOverflow site [Minunit](https://stackoverflow.com/a/65962/2191338), answer that I upvoted (of course) that leads to [JTN002 - MinUnit -- a minimal unit testing framework for C](https://jera.com/techinfo/jtns/jtn002). This whole test thingy it's based on this.\n\n---\n\nFeedback from usage and contributions are very welcome.\n\nAlso if you like it, please leave a :star: I would appreciate it ;)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarvilsi%2Fcst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarvilsi%2Fcst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarvilsi%2Fcst/lists"}