Changeset 471e313 in mainline


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

Location:
uspace/lib/cpp
Files:
3 edited

Legend:

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

    r4e6fb2f r471e313  
    4141
    4242            virtual ~test_suite() = default;
     43
     44            unsigned int get_failed() const noexcept;
     45
     46            unsigned int get_succeeded() const noexcept;
    4347
    4448        protected:
  • 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    {
  • uspace/lib/cpp/src/internal/test/test.cpp

    r4e6fb2f r471e313  
    4747    bool test_suite::end()
    4848    {
    49         std::printf("[TEST END][%s][%lu OK][%lu FAIL]\n",
     49        std::printf("[TEST END][%s][%u OK][%u FAIL]\n",
    5050                    name(), succeeded_, failed_);
    5151        return ok_;
    5252    }
     53
     54    unsigned int test_suite::get_failed() const noexcept
     55    {
     56        return failed_;
     57    }
     58
     59    unsigned int test_suite::get_succeeded() const noexcept
     60    {
     61        return succeeded_;
     62    }
    5363}
Note: See TracChangeset for help on using the changeset viewer.