-1

All I want is to be able to click on the cute bug in Visual Studio Code and step through my code to figure out why my Gtest tests are failing.

I don't want to use the submodule approach specified in this question.

How do I do this?

gkv
  • 360
  • 1
  • 8
  • Does Visual Studio Code have a graphical debugger? What's the difference between a graphical debugger and Visual Studio's debugger or GDB? – Thomas Matthews Feb 20 '23 at 02:44
  • Hm... maybe "graphical debugger" wasn't the best choice of words. I think what I meant was "a way to use GDB that felt integrated with Visual Studio's visual interface" – gkv Feb 20 '23 at 05:14

1 Answers1

0

Assuming a directory structure of

myproject
| -- CMakeLists.txt
| -- hello_test.cpp

with hello_test.cpp looking like:

#include <gtest/gtest.h>

TEST(hello_test, add)
{
    GTEST_ASSERT_EQ((10 + 22), 32);
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

Your CMakeLists.txt should look like:

cmake_minimum_required(VERSION 3.0.0)
project(myproject VERSION 0.1.0)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

include(FetchContent)

FetchContent_Declare(
  googletest
  # Specify the commit you depend on and update it regularly.
  URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip
)

FetchContent_MakeAvailable(googletest)

add_executable(hello_test hello_test.cpp)

target_link_libraries(
    hello_test
    gtest
)

include(GoogleTest)
gtest_discover_tests(hello_test)

gkv
  • 360
  • 1
  • 8