MantisBT - CMake
View Issue Details
0015553CMakeModulespublic2015-05-02 09:222015-11-02 09:15
Thiago M. 
 
normalminoralways
closedfixed 
CMake 3.2.2 
CMake 3.3CMake 3.3 
0015553: FindGTest.cmake doesn't handle all spaces in TEST / TEST_F macro
The GTEST_ADD_TESTS() macro does not handle all space configurations in the test macros:

- Spaces between the test suíte name and the comma: "TEST(TestSuite ,TestName)"
- Spaces between the macro name and the open parenthesis: "TEST (TestSuite,TestName)"

For the first one, the test is not detected.
For the second one, the test name is wrongly parsed and results in errors when trying to run it.
1. Create a test file with the following content:

    #include <gtest/gtest.h>

    TEST (TestSuite,Test1)
    {
    }

    TEST(TestSuite ,Test2)
    {
    }

2. Create a CMakeLists.txt that creates an executable for this test file and uses GTEST_ADD_TESTS() to create the CTest targets. An example list file in attached to this issue.

3. Configure and compile the CMake project and run the test executable. The GTest output shows the two tests are executed with success:

    $ ./GTestParseError
    Running main() from gtest_main.cc
    [==========] Running 2 tests from 1 test case.
    [----------] Global test environment set-up.
    [----------] 2 tests from TestSuite
    [ RUN ] TestSuite.Test1
    [ OK ] TestSuite.Test1 (0 ms)
    [ RUN ] TestSuite.Test2
    [ OK ] TestSuite.Test2 (0 ms)
    [----------] 2 tests from TestSuite (1 ms total)

    [----------] Global test environment tear-down
    [==========] 2 tests from 1 test case ran. (1 ms total)
    [ PASSED ] 2 tests.

4. Run CTest (with "make test", for instance). Only one test will be executed, with the wrong name, and it will fail.

    $ make test
    Running tests...
    Test project /home/myUser/Test-build
        Start 1: TEST
    Could not find executable (
    Looked in the following places:
    (
    (
    Release/(
    Release/(
    Debug/(
    Debug/(
    MinSizeRel/(
    MinSizeRel/(
    RelWithDebInfo/(
    RelWithDebInfo/(
    Deployment/(
    Deployment/(
    Development/(
    Development/(
    Unable to find executable: (
    1/1 Test #1: TEST .............................***Not Run 0.00 sec

    0% tests passed, 1 tests failed out of 1

    Total Test time (real) = 0.00 sec

    The following tests FAILED:
          1 - TEST (Not Run)
    Errors while running CTest
    Makefile:75: recipe for target 'test' failed
    make: *** [test] Error 8
The GTEST_ADD_TESTS() macro already support spaces between:
- The open parenthesis and the test suíte name
- The test name and the close parenthesis

This support was added in issue 0010065.
No tags attached.
related to 0010065closed Philip Lowman FindGTest.cmake doesn't handle spaces around arguments to TEST / TEST_F macro 
txt CMakeLists.txt (285) 2015-05-02 09:22
https://public.kitware.com/Bug/file/5447/CMakeLists.txt
cpp Tests.cpp (83) 2015-05-02 09:22
https://public.kitware.com/Bug/file/5448/Tests.cpp
Issue History
2015-05-02 09:22Thiago M.New Issue
2015-05-02 09:22Thiago M.File Added: CMakeLists.txt
2015-05-02 09:22Thiago M.File Added: Tests.cpp
2015-05-04 10:06Brad KingRelationship addedrelated to 0010065
2015-05-04 11:30Brad KingNote Added: 0038713
2015-05-04 11:30Brad KingStatusnew => resolved
2015-05-04 11:30Brad KingResolutionopen => fixed
2015-05-04 11:30Brad KingFixed in Version => CMake 3.3
2015-05-04 11:30Brad KingTarget Version => CMake 3.3
2015-11-02 09:15Robert MaynardNote Added: 0039801
2015-11-02 09:15Robert MaynardStatusresolved => closed

Notes
(0038713)
Brad King   
2015-05-04 11:30   
Currently FindGTest has no module maintainer:

 http://www.cmake.org/Wiki/CMake:Module_Maintainers [^]

However, the fix seems easy enough:

 FindGTest: Fix parsing of test macro calls with spaces
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0f927b44 [^]
(0039801)
Robert Maynard   
2015-11-02 09:15   
Closing resolved issues that have not been updated in more than 4 months.