Ignore:
Timestamp:
2018-07-05T21:41:18Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
edbad13a
Parents:
4e6fb2f
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-11-02 21:01:56)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:18)
Message:

cpp: added a test set that allows us to run tests and gather summary statistics about their results and then report those

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/internal/test/tests.hpp

    r4e6fb2f r471e313  
    3030#define LIBCPP_TESTS
    3131
     32#include <cstdio>
    3233#include <internal/test/test.hpp>
     34#include <vector>
    3335
    3436namespace std::test
    3537{
     38    class test_set
     39    {
     40        public:
     41            test_set() = default;
     42
     43            template<class T>
     44            void add()
     45            {
     46                tests_.push_back(new T{});
     47            }
     48
     49            bool run()
     50            {
     51                bool res{true};
     52                unsigned int succeeded{};
     53                unsigned int failed{};
     54
     55                for (auto test: tests_)
     56                {
     57                    res &= test->run();
     58                    succeeded += test->get_succeeded();
     59                    failed += test->get_failed();
     60                }
     61
     62                std::printf("\n");
     63                if (res)
     64                    std::printf("[TESTS SUCCEEDED!]");
     65                else
     66                    std::printf("[TESTS FAILED]");
     67                std::printf("[%u OK][%u FAIL][%u TOTAL]\n",
     68                            succeeded, failed, (succeeded + failed));
     69
     70                return res;
     71            }
     72
     73            ~test_set()
     74            {
     75                // TODO: Gimme unique_ptr!
     76                for (auto ptr: tests_)
     77                    delete ptr;
     78            }
     79        private:
     80            std::vector<test_suite*> tests_{};
     81    };
     82
    3683    class array_test: public test_suite
    3784    {
Note: See TracChangeset for help on using the changeset viewer.