eos icon indicating copy to clipboard operation
eos copied to clipboard

Did someone build the unit tests alone?

Open NeverLandFly opened this issue 8 years ago • 3 comments

Hi, I'm trying to build a unit test in the 'unittests' folder without rebuilding the whole project. But I'm not familiar with the CMake configs. The compiler give a very long list of undefined reference to ... My cmakelists.txt file is, :

cmake_minimum_required( VERSION 3.5 )

project( unittest2 )

list(APPEND CMAKE_MODULE_PATH "/home/neverland/eos/libraries/fc/CMakeModules")
list(APPEND CMAKE_MODULE_PATH "/home/neverland/eos/CMakeModules")

set(CMAKE_CXX_STANDARD 14)
set(BOOST_ROOT /home/neverland/opt/boost)
set(Boost_INCLUDE_DIR /home/neverland/opt/boost/include)
set(Boost_LIBRARY_DIR /home/neverland/opt/boost/lib)


find_package(Secp256k1 REQUIRED)
find_package(Boost 1.67 REQUIRED COMPONENTS
        thread
        date_time
        filesystem
        system
        program_options
        signals
        serialization
        chrono
        unit_test_framework
        context
        locale
        iostreams)

include(wasm)

find_package(LLVM 4.0 REQUIRED CONFIG)
link_directories(${LLVM_LIBRARY_DIR})

find_package(Boost REQUIRED COMPONENTS unit_test_framework)
include_directories(${Boost_INCLUDE_DIR})
include_directories(/home/neverland/eos/libraries/testing/include)
include_directories(/home/neverland/eos/build/contracts)
include_directories(/home/neverland/eos/libraries/wasm-jit/Include)
include_directories(/home/neverland/eos/libraries/fc/include)
include_directories(/home/neverland/eos/libraries/chain/include)
include_directories(/home/neverland/eos/libraries/chainbase/include)
include_directories(/home/neverland/eos/build/libraries/chain/include)
include_directories(/home/neverland/eos/libraries/softfloat/source/include)

link_libraries(/home/neverland/eos/build/libraries/chain/libeosio_chain.a)
link_libraries(/home/neverland/eos/build/libraries/chainbase/libchainbase.a)
link_libraries(/home/neverland/eos/build/libraries/testing/libeosio_testing.a)
link_libraries(/home/neverland/eos/build/libraries/utilities/libeos_utilities.a)
link_libraries(/home/neverland/eos/build/libraries/abi_generator/libabi_generator.a)
link_libraries(/home/neverland/eos/build/libraries/fc/libfc.a)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/config.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/config.hpp ESCAPE_QUOTES)

add_executable(unittest2 multi_index_tests)

I'm not sure where I am wrong.

NeverLandFly avatar Aug 20 '18 02:08 NeverLandFly

I guess it's tricky to just build the unitest project. I suggest to save time in solving this issue and build the whole thing instead, which just takes around 1 hour.

taokayan avatar Aug 20 '18 08:08 taokayan

Yes, it's driving me crazy. I'm trying to code a contract in a TDD way. And I'm following the code in unittests folder. Because my failure to build the unit test alone, Now the only solution I came up with seems to be that put the test in the unit tests folder, and build the whold project every time I add some new code. 😹

NeverLandFly avatar Aug 20 '18 08:08 NeverLandFly

The unittests depend on the libraries being tested. They're linked directly in. It is nonsensical to attempt to build unittests standalone.

Rather than adding your contract tests to unittests, create a unittests subdirectory in your contract directory. Your contract has no need for (and no direct access to) the chainbase library or many of the other parts tested in the top level unittests. Imitate the contents of eosio.token_tests.cpp for your own test, including making your own copy of the eosio_token_test class, renamed to something suitable for your contract. You will need nothing more than what's in unittests/CMakeLists.txt for your own directory's CMakeLists.txt, and you should be able to remove things such as some of the target_link_libraries().

jgiszczak avatar Aug 20 '18 19:08 jgiszczak