Manu343726 / siplasplas

A library for C++ reflection and introspection
https://manu343726.github.io/siplasplas
MIT License
195 stars 27 forks source link

Could not find executable test_variant #12

Closed lezcano closed 8 years ago

lezcano commented 8 years ago

After trying to compile the project as we did today in class, using the same commands, I was not able to build the "test" objective.

The commands I run were:

git clone --recursive https://github.com/GueimUCM/siplasplas.git
cd siplasplas && mkdir build && cd build
cmake ..
make run_example_variant
make test

That last make test threw:

UpdateCTestConfiguration  from :[directory]/siplasplas/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :[directory]/siplasplas/build/DartConfiguration.tcl
Test project [directory]/siplasplas/build
Constructing a list of tests
Done constructing a list of tests
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: variant
Could not find executable [directory]/siplasplas/build/tests/test_variant
Looked in the following places:
[several directories]

1: Test command: 
Unable to find executable: [directory]/siplasplas/build/tests/test_variant
1/2 Test #1: variant ..........................***Not Run   0.00 sec
test 2
    Start 2: linear_allocator
Could not find executable [directory]/siplasplas/build/tests/test_linear_allocator
Looked in the following places:
[several directories]

2: Test command: 
Unable to find executable: [directory]/siplasplas/build/tests/test_linear_allocator
2/2 Test #2: linear_allocator .................***Not Run   0.00 sec

0% tests passed, 2 tests failed out of 2

Total Test time (real) =   0.00 sec

The following tests FAILED:
      1 - variant (Not Run)
      2 - linear_allocator (Not Run)
Errors while running CTest
Manu343726 commented 8 years ago

This looks actually like a bug in the gmock.cmake script of Manu343726/cmake module. Look at the implementation of gmock_gtest_target() function:

function(gmock_test_target)
    ...
    if(NOT ET_TARGET_OUT)
        exec_target(${ARGN} PREFIX test TARGET_OUT __exec_target)
    else()
        exec_target(${ARGN} PREFIX test)
        set(__exec_target ${${ET_TARGET_OUT}})
    endif()  
    ...
    add_test(NAME ${ET_NAME} COMMAND ${__exec_target})
endfunction()

I'm declaring the test as a call to the test executable. It was written this way since GTest embeds the test driver (GTest framework) in the executable itself, so you just have to launch it.

The issue is that I forgot to add a dependency between the test target (${ET_NAME} variable) and the executable target, so the latter is built when the former is invoked. Your problem was you were trying to run the tests when the test executables are not built yet.

The solution should be as simple as adding that dependency explicitly through a call to add_dependencies().

Of course the workaround is as simple as invoking make before running the tests. Which is what I usually do and the reason why I didn't catch this....

Manu343726 commented 8 years ago

We no longer manage gmock in that way, instead the imported target is wrapped in a gmock target, so just linking against that gmock target triggers the external project build. Like:

add_executable(MyUnitTest myunittest.cpp)

target_link_libraries(MyUnitTest PRIVATE gmock)

That's all. This triggers the external project download/configure/build and then the generated gmock library is linked against your target.