{"id":13339514,"url":"https://github.com/pazamelin/sutf","last_synced_at":"2025-03-11T14:31:40.664Z","repository":{"id":56480945,"uuid":"291357665","full_name":"pazamelin/sutf","owner":"pazamelin","description":"simple unit test framework","archived":true,"fork":false,"pushed_at":"2021-01-14T08:56:43.000Z","size":305,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-10-24T02:30:06.807Z","etag":null,"topics":["cpp","framework","header-only","macro","single-header-lib","unit-testing","unit-testing-framework"],"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/pazamelin.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}},"created_at":"2020-08-29T22:17:22.000Z","updated_at":"2023-03-01T19:18:36.000Z","dependencies_parsed_at":"2022-08-15T19:31:27.901Z","dependency_job_id":null,"html_url":"https://github.com/pazamelin/sutf","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/pazamelin%2Fsutf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pazamelin%2Fsutf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pazamelin%2Fsutf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pazamelin%2Fsutf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pazamelin","download_url":"https://codeload.github.com/pazamelin/sutf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243051895,"owners_count":20228288,"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":["cpp","framework","header-only","macro","single-header-lib","unit-testing","unit-testing-framework"],"created_at":"2024-07-29T19:20:21.452Z","updated_at":"2025-03-11T14:31:40.316Z","avatar_url":"https://github.com/pazamelin.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple unit test framework\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/954f686578db42a49f614bc4eea033f0)](https://app.codacy.com/gh/pazamelin/sutf?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=pazamelin/sutf\u0026utm_campaign=Badge_Grade) [![Linux Status](https://img.shields.io/badge/Linux-passing-brightgreen)]()  [![macOS Status](https://img.shields.io/badge/macOS-passing-brightgreen)]()  [![Windows Status](https://img.shields.io/badge/Windows-failing-red)]()\n\n## Assertions:\n\n### Basic Assertions\n\nThese assertions do basic true/false condition testing.\n\nFatal assertion            | Nonfatal assertion         | Verifies\n-------------------------- | -------------------------- | --------------------\n`ASSERT_TRUE(condition);`  | `EXPECT_TRUE(condition);`  | `condition` is true\n`ASSERT_FALSE(condition);` | `EXPECT_FALSE(condition);` | `condition` is false\n\n### Binary Comparison\n\nThis section describes assertions that compare two values.\n\nFatal assertion          | Nonfatal assertion       | Verifies\n------------------------ | ------------------------ | --------------\n`ASSERT_EQ(val1, val2);` | `EXPECT_EQ(val1, val2);` | `val1 == val2`\n`ASSERT_NE(val1, val2);` | `EXPECT_NE(val1, val2);` | `val1 != val2`\n`ASSERT_LT(val1, val2);` | `EXPECT_LT(val1, val2);` | `val1 \u003c val2`\n`ASSERT_LE(val1, val2);` | `EXPECT_LE(val1, val2);` | `val1 \u003c= val2`\n`ASSERT_GT(val1, val2);` | `EXPECT_GT(val1, val2);` | `val1 \u003e val2`\n`ASSERT_GE(val1, val2);` | `EXPECT_GE(val1, val2);` | `val1 \u003e= val2`\n\n### String Comparison\n\nThe assertions in this group compare two **C strings**. If you want to compare\ntwo `string` objects, use `EXPECT_EQ`, `EXPECT_NE`, and etc instead.\n\n\u003c!-- mdformat off(github rendering does not support multiline tables) --\u003e\n\n| Fatal assertion                  | Nonfatal assertion               | Verifies                                                 |\n| --------------------------       | ------------------------------   | -------------------------------------------------------- |\n| `ASSERT_CSTR_EQ(str1,str2);`     | `EXPECT_CSTR_EQ(str1,str2);`     | the two C strings have the same content   \t\t     |\n| `ASSERT_CSTR_NE(str1,str2);`     | `EXPECT_CSTR_NE(str1,str2);`     | the two C strings have different contents \t\t     |\n\n\u003c!-- mdformat on--\u003e\n\n## Simple Tests\n\nTo create a test:\n\n1.  Use the `TEST()` macro to define and name a test function. \n2.  In this function, along with any valid C++ statements you want to include,\n    use the various assertions to check values.\n3.  The test's result is determined by the assertions. \n    If any `ASSERT_*` in the test fails or if the test crashes, the entire test fails.\n    If any `EXPECT_*` in the test fails, an error message is produced, but the entire test won't fail.\n\n```c++\nTEST(TestName) {\n  ... test body ...\n}\n```\nTo run all created tests use the `RUN_ALL_TESTS()` macro.\n\n## Usage Example:\n\n```c++\n#include \u003ciostream\u003e\n#include \u003cfstream\u003e\n#include \u003cstring\u003e\n#include \u003cset\u003e\n#include \u003cmap\u003e\n#include \u003cvector\u003e\n\n#include \"single_header/sutf.hpp\"\n\nTEST(strings)\n{\n    std::string str1{\"first string\"};\n    std::string str2{\"second string\"};\n\n    ASSERT_EQ(str1, \"first string\");\n    ASSERT_NE(str1, str2);\n}\n\nTEST(cstrings)\n{\n    char cstr1[] = \"first string\";\n    char cstr2[] = \"second string\";\n\n    ASSERT_CSTR_EQ(cstr1, \"first string\");\n    ASSERT_CSTR_LT(cstr1, cstr2);\n}\n\nTEST(expect_failure)\n{\n    std::string str1;\n\n    EXPECT_FALSE(str1.empty());\n}\n\nTEST(assert_failure)\n{\n    std::set\u003cint\u003e some_data{0, 1, 2, 4, 5};\n    auto value_entries{some_data.count(3)};\n\n    ASSERT_EQ(value_entries, 2u);\n    ASSERT_EQ(value_entries, 3u);\n}\n\nint main()\n{\n     RUN_ALL_TESTS();\n     return 0;\n}\n```\n\n## Test output:\nIf an assertion fails, an according failure message is printed to std::cerr in to provide information about failed comparison.\nThe failure message, inter alia, contains `actual` and `expected` values according to the failed assertion. There are, however, four different cases for test output:\n1. If the type T has both standard stream inserter operator and custom test output function, then the custom test output function is used for printing the failure message.\n2. If the type T has standard stream inserter operator but no custom test output function, then the standard stream inserter operator is used for printing the failure message. \n3. If the type T has no standard stream inserter operator, but has custom test output function for test output, than the function is used for printing the failure message. \n4. If the type T has neither standard stream inserter operator nor custom test output function, then default test output function is used. \n\ncustom test output function format:\n```c++\nstd::ostream\u0026 user_defined_sutf_printer_function(std::ostream \u0026os, T value)\n{\n  ...\n}\n\n```\nThe function may be used to provide different output for testing than the “normal” output. For example, you may want to print some hidden flags or data in the type that normally wouldn’t be exposed while printing.\n\nstandard stream inserter operator          |custom test output function       | what is used for output\n------------------------ | ------------------------ | --------------\nYES | YES | `custom test output function`\nYES | NO | `standard stream inserter operator`\nNO | YES | `custom test output function`\nNO | NO | `default test output function`\n\n### Examples for the four cases:\n```c++\n#include \u003ciostream\u003e\n#include \u003cfstream\u003e\n#include \u003cstring\u003e\n#include \u003cset\u003e\n#include \u003cmap\u003e\n#include \u003cvector\u003e\n\nstd::ostream\u0026 operator \u003c\u003c (std::ostream\u0026 os, const std::set\u003cint\u003e\u0026 obj)\n{\n    return os \u003c\u003c \" user-defined stream inserter for set\u003cint\u003e\";\n}\n\nstd::ostream\u0026 operator \u003c\u003c (std::ostream\u0026 os, const std::map\u003cint,int\u003e\u0026 obj)\n{\n    return os \u003c\u003c \" user-defined stream inserter for map\u003cint, int\u003e\";\n}\n\n// user-defined stream inserter\nstd::ostream\u0026 operator \u003c\u003c (std::ostream \u0026os,\n                           const std::vector\u003cstd::pair\u003cint, std::string\u003e\u003e\u0026 value)\n{\n    return os \u003c\u003c \"user-defined stream inserter std::vector\u003cstd::pair\u003cint, std::string\u003e\u003e\";\n}\n\n// user-defined function for test output\nstd::ostream\u0026 user_defined_sutf_printer_function(std::ostream \u0026os,\n                                                 const std::vector\u003cstd::pair\u003cint, std::string\u003e\u003e\u0026 value)\n{\n    return os \u003c\u003c \"user-defined test output for std::vector\u003cstd::pair\u003cint, std::string\u003e\u003e\";\n}\n\n#include \"single_header/sutf.hpp\"\n\nTEST(test_output_print)\n{\n    {\n        std::vector\u003cstd::pair\u003cint,int\u003e\u003e data1{{0, 1}, {2, 4}};\n        std::vector\u003cstd::pair\u003cint,int\u003e\u003e data2{{0, 1}, {2, 1}};\n\n        // std::vector\u003cstd::pair\u003cint,int\u003e\u003e has no stream inserter operator\n        // values of data1 and data2 will still be printed by\n        // SUTF's default test output function\n        ASSERT_EQ(data1, data2);\n    }\n\n    {\n        std::map\u003cint, int\u003e data1{{0, 1}, {2, 4}};\n        std::map\u003cint, int\u003e data2{{0, 1}, {2, 6}};\n\n\n        // std::map\u003cint,int\u003e has defined stream inserter operator\n        // values of data1 and data2 will be thus printed by the operator\n        ASSERT_EQ(data1,data2);\n    }\n\n    {\n        std::set\u003cint\u003e data1{1,2,3};\n        std::set\u003cint\u003e data2{1,2,4};\n\n        // std::set\u003cint\u003e has defined stream inserter operator\n        // values of data1 and data2 will be thus printed by the operator\n        ASSERT_EQ(data1,data2);\n    }\n\n    {\n        std::vector\u003cstd::pair\u003cint,std::string\u003e\u003e data1{{0, \"abc\"}, {2, \"def\"}};\n        std::vector\u003cstd::pair\u003cint,std::string\u003e\u003e data2{{0, \"abc\"}, {2, \"efg\"}};\n\n        // std::vector\u003cstd::pair\u003cint,int\u003e\u003e has stream inserter operator\n        // the type also has user_defined_sutf_printer_function, meaning that it shall be\n        // used for the output:\n        ASSERT_EQ(data1,data2);\n    }\n}\n\nint main()\n{\n    // default (\"non-test\") output for std::vector\u003cstd::pair\u003cint,std::string\u003e\u003e uses user-defined\n    // stream inserter operator (while for tests' output user_defined_sutf_printer_function is employed)\n    std::vector\u003cstd::pair\u003cint,std::string\u003e\u003e data1{{0, \"abc\"}, {2, \"def\"}};\n    std::cout \u003c\u003c data1 \u003c\u003c std::endl;\n\n    RUN_ALL_TESTS();\n    return 0;\n}\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpazamelin%2Fsutf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpazamelin%2Fsutf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpazamelin%2Fsutf/lists"}