{"id":23167657,"url":"https://github.com/oblivious-oblivious/cspec","last_synced_at":"2025-07-06T12:36:26.393Z","repository":{"id":107333972,"uuid":"248358718","full_name":"Oblivious-Oblivious/cSpec","owner":"Oblivious-Oblivious","description":"A lightweight, compile time unit testing library for TDD and BDD models, heavily inspired by ruby's RSpec.","archived":false,"fork":false,"pushed_at":"2024-11-23T19:14:17.000Z","size":4205,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-23T20:20:59.727Z","etag":null,"topics":["bdd","c-language","cspec","tdd","testing"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Oblivious-Oblivious.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2020-03-18T22:40:44.000Z","updated_at":"2024-11-23T19:14:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"2c916907-d7dd-42e4-b6fb-ff5ce797aaf8","html_url":"https://github.com/Oblivious-Oblivious/cSpec","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oblivious-Oblivious%2FcSpec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oblivious-Oblivious%2FcSpec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oblivious-Oblivious%2FcSpec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oblivious-Oblivious%2FcSpec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Oblivious-Oblivious","download_url":"https://codeload.github.com/Oblivious-Oblivious/cSpec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230208231,"owners_count":18190281,"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":["bdd","c-language","cspec","tdd","testing"],"created_at":"2024-12-18T02:31:39.516Z","updated_at":"2024-12-18T02:31:54.561Z","avatar_url":"https://github.com/Oblivious-Oblivious.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cSpec - A Full Scale Testing Library\n\ncSpec is a lightweight, compile time unit testing library\nfor TDD and BDD models, heavily inspired by ruby's `RSpec`.\n\n[![GPLv3 License](https://img.shields.io/badge/License-GPL%20v3-yellow.svg)](./COPYING)\n\n![](https://github.com/Oblivious-Oblivious/cSpec/blob/master/images/simple_example.png)\n\n## Why\n\n`cSpec` provides an interface for creating both low level tests\nin the form of simple assertions, as well as high level integration or even\nacceptance tests in the form of `describes` or `contexts`. These tools will\nallow the programmer to encapsulate test modules that will be maintainable\nthroughout huge projects.\n\n## Features\n\n- Assertion macro for test blocks\n  - `assert_that(test)`\n- Assertion macros for different data types\n  - `assert_that_int(actual, expected)`\n  - `assert_that_double(actual, expected)`\n  - `assert_that_charptr(actual, expected)`\n- Assertions for arrays\n  - `assert_that_int_array(actual, expected, length)`\n  - `assert_that_double_array(actual, expected, length)`\n  - `assert_that_charptr_array(actual, expected, length)`\n- False assertions macro calls for defined data types\n  - `nassert_that_*`\n\n## Usage\n\n- Include the `cSpec.h` file your project (compiled into the `export` directory)\n- All directives are defined in this one header\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/Oblivious-Oblivious/cSpec/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [oblivious](https://github.com/Oblivious-Oblivious) - creator and maintainer\n\n## Basic usage\n\nGood practice for defining cSpec tests goes as follows:\n\n- Define a spec file named: `mySuite.spec.c`\n- Include the header files of the code to be tested.\n- If you have multiple modules you can define them in different files named: `myModule.module.h`\n- Define a spec suite of modules using `spec_suite`\n\n##### Setting up the testing environment\n\nSuppose we want to test a C project with a header and implementation file.\n\n**_`meaning_of_life.h`_**\n\n```C\n#ifndef __MEANING_OF_LIFE_H_\n#define __MEANING_OF_LIFE_H_\n\n/**\n * @func: find_meaning_of_life\n * @brief: Finds the ultimate answer to the great\n *      question of life the universe and everything\n * @return Returns the answer\n */\nint find_meaning_of_life(void);\n\n#endif\n```\n\n**_`meaning_of_life.c`_**\n\n```C\n#include \"meaning_of_life.h\"\n\nint find_meaning_of_life(void) {\n  if(1 == 1) {\n    return 42;\n  }\n}\n```\n\n**We define a spec file as such:**\n\n**_`meaning_of_life.spec.c`_**\n\n```C\n#include \"meaning_of_life.h\"\n#include \"cSpec.h\"\n\nmodule(lifeMod, {\n  describe(\"what is life\", {\n    it(\"seeks for the meaning of life\", {\n      assert_that(find_meaning_of_life() is 42);\n      assert_that_int(find_meaning_of_life() equals to 42);\n    });\n  });\n})\n\nint main(void) {\n  /* We only want to print failing tests */\n  cspec_run_suite(\"failing\", {\n    lifeMod();\n  });\n}\n```\n\n**Alternatively we could define a module as such:**\n\n`meaning_of_life.module.h`\n\n```C\n#ifndef __MEANING_OF_LIFE_MODULE_H_\n#define __MEANING_OF_LIFE_MODULE_H_\n\nmodule(lifeMod, {\n  describe(\"what is life\", {\n    it(\"seeks for the meaning of life\", {\n      assert_that(find_meaning_of_life() is 42);\n      assert_that_int(find_meaning_of_life() equals to 42);\n    });\n  });\n})\n\n#endif\n```\n\n**and then include it in the spec file:**\n\n`life.spec.c`\n\n```C\n#include \"meaning_of_life.h\"\n#include \"cSpec.h\"\n\n/* Get modules */\n#include \"meaning_of_life.module.h\"\n\nint main(void) {\n  cspec_run_suite(\"failing\", {\n    lifeMod();\n  });\n}\n```\n\n**Result:**\n![](https://github.com/Oblivious-Oblivious/cSpec/blob/master/images/meaning_of_life_example.png)\n\nIt is a preety satisfying DSL, very intuitive and close to high level designs.\n\n## Basic Interface\n\n- [Interface](https://github.com/Oblivious-Oblivious/cSpec/blob/master/documentation/Basic%20Interface.md)\n\n## Creating asserts\n\nWhen calling asserts, the main purpose is to validate some expression,\nto check for a true of false condition. cSpec uses a few\nabstractions for making assert statements look more natural.\n\n```C\n#define is ==\n#define isnot !=\n#define equals ,\n#define to\n#define with\n#define array_size ,\n```\n\nUsing those constructs to call asserts we use the power of the C preprocessor to expand the macro like this:\n\n- assert_that_int(actual equals to expected) --\u003e assert_that_int(actual, expected)\n- assert_that(value isnot 2) --\u003e assert_that(value != 2)\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foblivious-oblivious%2Fcspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foblivious-oblivious%2Fcspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foblivious-oblivious%2Fcspec/lists"}