项目作者: avivg

项目描述 :
Lightweight unit testing harness for C projects.
高级语言: C
项目地址: git://github.com/avivg/lightunit.git
创建时间: 2019-04-14T12:15:23Z
项目社区:https://github.com/avivg/lightunit

开源协议:MIT License

下载


LightUnit Build Status

Lightweight unit testing harness for C projects.

Inspired by siu/minunit and MinUnit.

This unit testing harness uses GCC’s __attribute__((constructor))
magic to automagically register each test to its test suite without the need to do so explicitely.

Strengths

  • Lightweight and easy to install (just a .h file)
  • Simple tests management interface
    • define suites and define the tests.
    • No need to add the tests to the suites explicitly.
  • Easily extensible (PRs wellcome).
  • No dynamic memory allocations.

Weaknesses

  • Requires support for __attribute__((constructor)) from the compiler.

Usage:

  1. #include "lightunit.h"
  2. static int g_var;
  3. static const char *g_foo = "foo";
  4. LU_SUITE_CREATE(suite);
  5. LU_SUITE_SETUP(suite) {
  6. g_var = 1;
  7. }
  8. LU_TEST(suite, test1) {
  9. LU_ASSERT(g_var == 1);
  10. g_var++;
  11. LU_ASSERT_STR_EQ("foo", g_foo);
  12. LU_ASSERT(2 == 3);
  13. }
  14. LU_TEST(suite, test2) {
  15. LU_ASSERT(++g_var == 2);
  16. LU_ASSERT_STR_EQ("bar", g_foo);
  17. }
  18. int main() {
  19. LU_SUITE_RUN(suite);
  20. LU_SUITE_REPORT(suite);
  21. return LU_SUITE_STATUS(suite);
  22. }

Prints:

  1. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. SUITE: suite
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. > test1 : -1 (examples/readme_example.c+16: '2 == 3' asserted to False)
  5. > test2 : -2 (examples/readme_example.c+21: Strings different: "bar" <> g_foo)
  6. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. STATUS: FAIL (2 tests, 2 fails, 5 assertions)
  8. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TODO

  • Add verbosity options to report
  • Add more assertion types
    • ASSERT_FLT_EQ / ASSERT_DBL_EQ for float/double approx.
    • FAIL(message)
  • Time tests
  • Other compilers support