CMake and Ctest and CppUnit

Help
BigWave
2007-03-26
2013-04-22
  • BigWave
    BigWave
    2007-03-26

    Hi CppUniters,

      I am taking the discussion from http://www.cmake.org/pipermail/cmake/2007-March/013390.html here.

      Basically, I am trying to get two (later more) simple test suites executed with cmake/ ctest.

      Following my descriptions in http://www.cmake.org/pipermail/cmake/2007-March/013380.html ,  the same test gets executed twice.

      If I follow Pascal's recommendation from http://www.cmake.org/pipermail/cmake/2007-March/013390.html , then I just get

    ----->---------->-----
      1/  2 Testing S1_CUtest
    Test command: /[..]/test/UnitTester S1_CUtest
    terminate called after throwing an instance of 'std::invalid_argument'
      what():  No test named <S1_CUtest> found in test <All Tests>.
    -- Process completed

    *** Exception executing: Child aborted
    ***Exception: Other
      2/  2 Testing S2_CUtest
    Test command: /[..]/test/UnitTester S2_CUtest
    terminate called after throwing an instance of 'std::invalid_argument'
      what():  No test named <S2_CUtest> found in test <All Tests>.
    -- Process completed

    *** Exception executing: Child aborted
    ***Exception: Other
    -----<----------<-----

    Does anyone know what I am doing wrong ?

    Thanks,

       JAN

     
    • Pascal Fleury
      Pascal Fleury
      2007-03-27

      Well, I have discovered now that some of my tests fail for the same reason, but about 80% of them work as expected (i.e. they fail for reasons related to my code, not CppUnit).

      I'll have to investigate this, but I suspect this has to do with the test naming/finding scenario. Essentially, we register every test, and then search for a given one and run it.

      It may also be that the particular tests are not properly linked into the final test_runner executable. Note that there is nothing that forces the linker to pull in these tests, as there are essentially no unresolved symbols for them. Maybe that's the case.

      Anyway, that's just off my head, I cannot verify this right now...

      I'll keep you posted.

      --Pascal

       
    • Pascal Fleury
      Pascal Fleury
      2007-04-03

      So I have some new findings about these tests. It does not play well with namespaces in C++, so that the test name may have the namespace as a prefix, rendering the simply matching void. If you add this code to the test runner stub, you'll see the full list of possible tests in case the name is not found, helpful for debugging.

      My solution is to have the tests themselves in the global namespace, which may not suit you. In that case, you'll have to find a new trick with this naming.

      void print_all_tests(Test* t, const char* spacer, std::ostream& os) {
          os << t->getName() << spacer;
          for (int i=0; i < t->getChildTestCount(); i++)
              print_all_tests( t->getChildTestAt(i), spacer, os );
      }

      int main (int argc, char* argv[]) {
        TextUi::TestRunner runner;
        TestFactoryRegistry& registry = TestFactoryRegistry::getRegistry();

        Test* test_to_run = registry.makeTest();
        if (argc>1) {
            try {
                test_to_run = test_to_run->findTest( argv[1] );
            } catch (...) {
                std::cerr << "Valid tests: ";
                print_all_tests(test_to_run, "\n", std::cerr);
                std::cerr << std::endl;
                throw;
            }
        }
         
        runner.addTest( test_to_run );
        bool failed = runner.run("", false);
        return !failed;
      }