Using Structs and Classes as Tests

A functor here is defined as: any class or struct with a public operator () that takes zero arguments.
Place your cursor anywhere along the desired function. Right click Source > Add Test > Add Test functor to Suite.

#include "cute.h" 
#include "ide_listener.h" 
#include "xml_listener.h" 
#include "cute_runner.h" 

struct StructTest {
    void operator() () {
        ASSERTM("Failing test", false);
    }
};

struct WithConstructor {
    WithConstructor(int x) : x{ x } {

    }
    int x;
    void operator() () {
        ASSERT_EQUALM("x should be 5", 5, x);
    }
};

bool runAllTests(int argc, char const *argv[]) {
    cute::suite s { };
    s.push_back(StructTest());
    s.push_back(WithConstructor(4));
    s.push_back(WithConstructor(5));
    cute::xml_file_opener xmlfile(argc, argv);
    cute::xml_listener<cute::ide_listener<>> lis(xmlfile.out);
    auto runner = cute::makeRunner(lis, argc, argv);
    bool success = runner(s, "AllTests");
    return success;
}

int main(int argc, char const *argv[]) {
    return runAllTests(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE;
}

Adding Test Member to Suite

A test method in a class or struct can be added. See the code bellow as example.

A class or struct method needs to be public, non static, parameterless, non union. The class needs to be default constructible. An instance method needs to be public, non static, parameterless, non union and its return type needs to be void.

#include "cute.h" 
#include "ide_listener.h" 
#include "xml_listener.h" 
#include "cute_runner.h" 

struct MemberTest {
    bool aTest() {
        ASSERT(false);
    }
};

struct WithConstructor {
    WithConstructor(int x) : x{ x } { }
    int x;
    void operator() () {
        ASSERT_EQUALM("x should be 5", 5, x);
    }

    void test10() {
        ASSERT_EQUALM("x should be 10", 10, x);
    }
};

bool runAllTests(int argc, char const *argv[]) {
    cute::suite s { };
    s.push_back(CUTE_SMEMFUN(MemberTest, aTest));
    s.push_back(WithConstructor(5));

    WithConstructor instance { 5 };
    s.push_back(CUTE_MEMFUN(instance, WithConstructor, operator())); //same as above
    s.push_back(CUTE_MEMFUN(instance, WithConstructor, test10));

    cute::xml_file_opener xmlfile(argc, argv);
    cute::xml_listener<cute::ide_listener<>> lis(xmlfile.out);
    auto runner = cute::makeRunner(lis, argc, argv);
    bool success = runner(s, "AllTests");
    return success;
}

int main(int argc, char const *argv[]) {
    return runAllTests(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE;
}

See Theory Of Operation and Goals for details.