← Back to team overview

kicad-developers team mailing list archive

Re: [RFC] [PATCH] simple C++ tests

 


On 9/7/2016 5:39 PM, Tomasz Wlostowski wrote:
> On 07.09.2016 21:24, Wayne Stambaugh wrote:
>> Tom,
>>
>> I also forgot to mention there were tabs in the CMakeLists.txt file.
>>
> Hi Wayne,
> 
> Here's a (hopefully) fixed version.
> 
> Cheers,
> Tom

Hey Tom,

Here is the patch that fixes the linking as well.  I linked against the
static libraries.  That shouldn't be an issue.

FYI, I would rather you use CTest[1] add_test()[2] for defining tests
then creating a custom function.  When you use CTest, I believe the
BUILD_TESTING enables building the tests but I've never used this so I'm
not sure how it all fits together but I'm sure it's documented somewhere.

Cheers,

Wayne

[1] https://cmake.org/Wiki/CMake_Testing_With_CTest
[2] https://cmake.org/cmake/help/v3.6/command/add_test.html


> 
>> Cheers,
>>
>> Wayne
>>
>> On 9/7/2016 12:17 PM, Tomasz Wlostowski wrote:
>>> Hi,
>>>
>>> This patch adds possibility to build C++ tests for pcbnew, using
>>> Boost.Test framework. I intended it primarily to make tests for the P&S,
>>> which I used to develop out-of-tree before.
>>>
>>> Since Kicad's codebase is rather monolithic, testing/refactoring
>>> anything drags in pretty much everything else in the code as a
>>> dependency.  This causes long rebuild and linking times, which I find
>>> very annoying. Also, while developing new features, most of the time is
>>> spent linking pcbnew and clicking in the GUI to trigger the particular
>>> feature.
>>>
>>> For that reason I decided to link all the test cases directly to the
>>> _pcbnew_kiface library and skip pcbnew's dependency scanning when
>>> building tests. I'm also preparing a bare PCB test window for verifying
>>> interactive/graphical operations without rebuilding pcbnew as a whole app.
>>>
>>> I've attached the patch (set the KICAD_BUILD_TESTS=ON option to enable).
>>> There's one trivial unit test included as an example. Let me know if
>>> such solution would be acceptable.
>>>
>>> Cheers,
>>> Tom
>>>
>>>
>>>
>>> _______________________________________________
>>> Mailing list: https://launchpad.net/~kicad-developers
>>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>>> Unsubscribe : https://launchpad.net/~kicad-developers
>>> More help   : https://help.launchpad.net/ListHelp
>>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>>
> 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6a3abea..7a7ba46 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,15 +1,19 @@
-include_directories ( 
-    ${CMAKE_SOURCE_DIR} 
+include_directories(
+    ${CMAKE_BINARY_DIR}
     ${CMAKE_SOURCE_DIR}/polygon
     ${CMAKE_SOURCE_DIR}/include
     ${CMAKE_SOURCE_DIR}/pcbnew
     ${CMAKE_SOURCE_DIR}/pcbnew/router )
 
-link_directories ( ${CMAKE_BINARY_DIR}/pcbnew )
+link_directories( ${CMAKE_BINARY_DIR}/pcbnew )
 
 function( add_test_case name )
-    add_executable ( ${name} ${name}.cpp )
-    target_link_libraries ( ${name} ${wxWidgets_LIBRARIES} _pcbnew_kiface ${Boost_LIBRARIES} )
+    add_executable( ${name} ${name}.cpp )
+    target_link_libraries( ${name} ${wxWidgets_LIBRARIES}
+        common
+        pcbcommon
+        pnsrouter
+        ${Boost_LIBRARIES} )
 endfunction( add_test_case )
 
-add_subdirectory ( pns )
+add_subdirectory( pns )

Follow ups

References