Skip to content

An example of using ctest for a C++ app / library.

License

Notifications You must be signed in to change notification settings

jthelin/hello-ctest

Repository files navigation

hello-ctest

Running build and test locally

In order to build and test this project locally, you need to follow 4 steps:

  1. Create the Build environment

    Create a directory for all of the generated files (e.g. make files, object files, executables etc.) will be located. This can be done by running the command like:

    cmake -E make_directory my_build_directory

    or something system specific like:

    mkdir -p my_build_directory
  2. Configure CMake

    This step generates all of the files needed for the build. Navigate to my_build_directory and run:

    cmake ../

    Expected output:

    -- The CXX compiler identification is GNU 13.2.0
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Using CTEST_RESOURCE_SPEC_FILE = some_path/hello-ctest/test-resource-spec.json
    -- CMAKE_INSTALL_PREFIX = some_path/hello-ctest/my_build_directory/install/hello-ctest -- Use the cmake --install-prefix arg to override.
    -- Configuring done (0.2s)
    -- Generating done (0.0s)
    -- Build files have been written to: some_path/hello-ctest/my_build_directory
    
  3. Build the project

    Navigate to my_build_directory and run:

    cmake --build .

    The output should look like:

    [ 50%] Building CXX object src/CMakeFiles/hello-ctest.dir/main.cpp.o
    [100%] Linking CXX executable hello-ctest
    [100%] Built target hello-ctest
    
  4. Execute the tests using ctest

    Tests in this project are expresed using ctest. To execute all of them navigate to my_build_directory and run:

    ctest
    

    The output should look like:

    Test project some_path/hello-ctest/my_build_directory
        Start 1: run_hello-ctest
    1/6 Test #1: run_hello-ctest ..................   Passed    0.00 sec
        Start 2: Hello_One
    2/6 Test #2: Hello_One ........................   Passed    0.00 sec
        Start 3: Hello_Two
    3/6 Test #3: Hello_Two ........................   Passed    0.00 sec
        Start 4: Hello_Three
    4/6 Test #4: Hello_Three ......................   Passed    0.00 sec
        Start 5: Hello_Four
    5/6 Test #5: Hello_Four .......................   Passed    0.00 sec
        Start 6: Hello_Five
    6/6 Test #6: Hello_Five .......................   Passed    0.00 sec
    
    100% tests passed, 0 tests failed out of 6
    
    Total Test time (real) =   0.02 sec
    

These steps are reflected in build_and_test.yml workflow.

About

An example of using ctest for a C++ app / library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published