Do you even test? (your code with CMake)

Поділитися
Вставка
  • Опубліковано 26 січ 2025

КОМЕНТАРІ • 82

  • @CodeForYourself
    @CodeForYourself  2 роки тому +13

    Minor correction, the --test-dir flag was only added in CMake 3.20, so if you have an older version, run the tests with these commands instead:
    cd build
    GTEST_COLOR=1 ctest --output-on-failure -j12

    • @kompila
      @kompila 2 роки тому +3

      This is amazing, thanks.

    • @HylianEvil
      @HylianEvil Рік тому +1

      I'm interested in your computer chair. Is it good for tall people?

    • @CodeForYourself
      @CodeForYourself  Рік тому +1

      @@HylianEvil well, it’s ok. It is a simple IKEA chair 🤷‍♂️

  • @siddevsam
    @siddevsam 10 місяців тому +9

    That clip of cat failing to jump is exact visual representation of me running my code! 🤣🤣

    • @CodeForYourself
      @CodeForYourself  10 місяців тому +1

      Yeah, don't even mention it! Been there many times myself 🫂

  • @blablabla7796
    @blablabla7796 Рік тому +10

    This tutorial is criminally underrated. You deserve more subscribers. 👍

    • @blablabla7796
      @blablabla7796 Рік тому

      @@CodeForYourself I’ve actively searched for cmake + gtest setup tutorials and they help but they get really confusing really fast. I randomly got recommended this video and, no offence to the other guys but, this is 100x better.

    • @CodeForYourself
      @CodeForYourself  Рік тому +2

      Wow, this really warms my heart. Thanks for such a praise! This is _really_ important to me. 🙏

  • @longvuong2600
    @longvuong2600 2 роки тому +3

    Looking forward to git submodule video. Thank you for another awesome video.

  • @MrCynosure4sure
    @MrCynosure4sure 2 роки тому +4

    This was a very infomative, engaging and entertaining video. Great work!!! Would love to see a video on your git workflow and if you use continuous integration with github. Thank you

    • @CodeForYourself
      @CodeForYourself  2 роки тому

      Gotcha. Will record this video in the coming weeks most probably. Thanks!

  • @tienvuhong3536
    @tienvuhong3536 9 місяців тому +1

    That pretty much helpful and so easy to understand, thank you!

  • @Ekalai
    @Ekalai 3 місяці тому +1

    Awesome, You are rock man!!!... 🌹💖

  • @ilarioantonioazzollini66
    @ilarioantonioazzollini66 Рік тому +1

    Hi Igor, great content once again, thanks!
    One minor comment: looks like for using the "--test-dir build" option, at least CMake 3.20 is required. I am using 3.16 and took some time to figure out why it didn't discover any tests (well not too much as the message was pretty clear in saying that it was not looking for tests in the build folder, but still I expected an error or something like that!)

    • @CodeForYourself
      @CodeForYourself  Рік тому +1

      Yeah, that is correct. With the older cmake we have to run the tests from the tests folder 🤷‍♂️ Sorry for not mentioning it upfront.

  • @andreacassotti2561
    @andreacassotti2561 10 місяців тому +1

    Thanks a lot for your tutorial! It's very clear.

    • @CodeForYourself
      @CodeForYourself  10 місяців тому

      Thanks for watching and for the kind words!

  • @onemoremagistr
    @onemoremagistr Рік тому +1

    Контенту від українців стає більше і це не може не радувати!) Дякую)

  • @Andrei-cp5jr
    @Andrei-cp5jr Рік тому +1

    When I type #include the IDE doesn't find that file. In fact, even if I try to locate the file in the googletest folder and I type it in manually, the IDE still signals that the file cannot be found. What should I do? Where could the problem come from?

    • @CodeForYourself
      @CodeForYourself  Рік тому +2

      It is hard to answer your question precisely unfortunately as I don't know what you did before and which IDE you are using? Did you follow the video precisely? Did you copy all the code from the video script?

    • @Andrei-cp5jr
      @Andrei-cp5jr Рік тому +2

      @@CodeForYourself Yep, I did everything in the video, even started over with a new project and followed every step. I was able to solve the problem by importing the framework automatically from GitHub and restarting the IDE. The folder structure was a lot less complicated. I also had a hard time understanding the dependencies in the CMakeLists file, but once I got that right and linked everything with the framework, it was fine. I had a few moments where I got confused during the video and maybe did something wrong and maybe that's why it didn't work. Anyway I'm glad it works now and that I was able to submit my programming assignment on time.

    • @CodeForYourself
      @CodeForYourself  Рік тому +1

      @@Andrei-cp5jr glad that it eventually worked out! What I’m a bit confused about is what do you mean by an IDE? Which one do you use? I find that heavy IDEs are very cumbersome to use and when you’re starting out I would suggest to only use text editors without the semantic autocomplete as this makes one learn faster in my experience.

    • @Andrei-cp5jr
      @Andrei-cp5jr Рік тому

      @@CodeForYourself I'm using CLion

  • @silentage6310
    @silentage6310 9 місяців тому +1

    Does this code at the end of each test run attempt to update submodules? Will this slow down the testing process if tests are run frequently?

    • @CodeForYourself
      @CodeForYourself  9 місяців тому

      Thanks for the question! The update code is only run at the cmake configuration stage. So it is not run when the tests are run. Does this make sense?

  • @theintjengineer
    @theintjengineer 2 роки тому +1

    First😎
    Another fascinating video, Igor🔥
    Keep it up✨

  • @keepgoing335
    @keepgoing335 Рік тому +1

    Can i ask what are the advantages of adding google test as submodule over using FetchContent?

    • @CodeForYourself
      @CodeForYourself  Рік тому +3

      Not too many. And mostly quite obscure. If we have a weird network configuration, like a firewall it feels more cumbersome to set up FetchContent, at least I remember struggling with it recently but I don't remember exactly what was so hard about it. 🤷‍♂️ Just remember it was something with permissions.
      The other thing that comes to mind is a situation when I need to clean and rebuild code without access to the internet. When using FetchContent the build folder including all external sources will be removed. This situation bit me a couple of times before. With the submodules as long as they were checked out when we had internet we're going to be good.
      There might be other reasons but as you see the ones I have are pretty obscure. FetchContent is not a bad solution, just a little bit finicky at times for my taste.

    • @keepgoing335
      @keepgoing335 Рік тому +2

      @@CodeForYourself ah.. I see the advantage of not deleting the external sources when rebuilding. on my commute to the office my laptop isn't connected to the internet mostly and it'll be nice to still have the external sources available

  • @jcbrites
    @jcbrites Рік тому

    Python and java (and all languages that run on the jvm) have build systems that can access library repositories. It's just then a matter of declaring the exact version of the dependency we use in our code. The library is then fetched automatically by the build system (including testing frameworks). Isn't there an equivalent thing for c++?

    • @CodeForYourself
      @CodeForYourself  Рік тому +1

      Not built into the language. I guess just as it is not built into python for example. For python you would use pip, for C++ there is Conan or CPM (the ones that come to mind). They are not as standardized though.

  • @BenUK1
    @BenUK1 Рік тому +1

    What I don’t understand is was CTest actually gives you here. I build my GoogleTest based Unit Test projects with Cmake but without using CTest and I just run the created Unit Test executable. It gives me the exact same GTest output as in your video, so I don’t really get what CTest is for?

    • @CodeForYourself
      @CodeForYourself  Рік тому +1

      CTest is really just a way to "register" gtest with the rest of CMake. So that you could run the ctest binary from the same folder where you are building from. It makes sure you can run all the test targets in a unified way. Imagine having multiple test targets in multiple folders. As long as they all are registered through CTest you can run them all with a single unified command. Which is by the way the same should you use a different testing framework as an additional benefit. Does this make any sense?

  • @whac-a-robot
    @whac-a-robot 9 місяців тому

    Hi Igor, I am using CMAKE 3.16, when I tried the above I am getting a message stating that no tests found. How to resolve this?

    • @CodeForYourself
      @CodeForYourself  9 місяців тому

      Yeah, that’s a bit of a limitation. There was another comment under this video where we come up with a solution. Does that solution work for you?

    • @whac-a-robot
      @whac-a-robot 9 місяців тому

      @@CodeForYourself where is that test folder is mapped? I couldn't find it.

    • @CodeForYourself
      @CodeForYourself  9 місяців тому

      @whac-a-robot8623 it should be just the build folder itself. So you have to change the directory into that build folder and run the cmake command from there. If that doesn’t work out I’ll have a look more deeply into this.

    • @whac-a-robot
      @whac-a-robot 9 місяців тому +1

      @@CodeForYourself ok will check and let you know

    • @whac-a-robot
      @whac-a-robot 9 місяців тому +1

      @@CodeForYourself I understood it now. For quick reference for others you putting my solution here. Command 1 : cd build . Command 2 : GTEST_COLOR=1 ctest --output-on-failure -j12.
      Thank you for the support.

  • @jackie7023
    @jackie7023 Рік тому

    This video is so cool. Is it possible to use google test in the microcontroller project??

    • @CodeForYourself
      @CodeForYourself  Рік тому

      I guess so, depends on your setup. Which microcontroller are you talking about?

  • @reubenthomas1033
    @reubenthomas1033 2 роки тому +1

    Great video!

  • @mohammedkamil5320
    @mohammedkamil5320 2 місяці тому

    I seriously thought you were the LangFocus channel guy, I was like: "wait, does this guy also code?"
    Write the LangFocus channel and you gonna see that you guys are mostly identical. OMG

    • @CodeForYourself
      @CodeForYourself  2 місяці тому

      @@mohammedkamil5320 ok, to me we seem to be quite different but I like these types of connections. What would you say is similar? 😅

    • @mohammedkamil5320
      @mohammedkamil5320 2 місяці тому

      @ interesting, I would say your face is mostly similar, but the other guy’s face is a bit more broad. I think you guys have mostly the same eyes, same nose and same mouth, except for the hair. I showed you both for some of my friends just to make sure that I’m not the only one and most of them agreed that you guys look similar to each other except for one or two, but they also agreed that you have similarities😁

    • @CodeForYourself
      @CodeForYourself  2 місяці тому

      @ I don’t mind at all. Maybe one day I’ll have as many subscribers too 😅

  • @hurainjinnath
    @hurainjinnath Місяць тому

    Hey, Which editor did you use here?

    • @CodeForYourself
      @CodeForYourself  Місяць тому +1

      @@hurainjinnath I’m using VS Code exclusively in this course.

    • @CodeForYourself
      @CodeForYourself  Місяць тому +1

      @@hurainjinnath oh and there is also the standard macOS terminal

    • @hurainjinnath
      @hurainjinnath Місяць тому

      @@CodeForYourself thanks ☺

    • @CodeForYourself
      @CodeForYourself  Місяць тому +1

      Sure, my pleasure!

  • @ozimandias1858
    @ozimandias1858 3 місяці тому

    Why is the method where we download GTest sources, save them to our system, build them, and then include them in our project using something like this (look down) now deprecated?
    enable_testing()
    find_package(GTest REQUIRED)
    include(GoogleTest)
    add_executable(tests
    tests.cpp
    )
    target_link_libraries(tests
    GTest::gmock
    GTest::gtest
    )
    gtest_discover_tests(tests)

    • @CodeForYourself
      @CodeForYourself  3 місяці тому

      @@ozimandias1858 well, deprecated is a strong word for it, you’re right. But it is discouraged. The suggested way is to “live at head” as mentioned in their readme: github.com/google/googletest#live-at-head

    • @CodeForYourself
      @CodeForYourself  3 місяці тому

      @@ozimandias1858 they also only provide the fetch_content example in their docs: google.github.io/googletest/quickstart-cmake.html

    • @ozimandias1858
      @ozimandias1858 2 місяці тому

      Okay, thank you!

  • @mek101whatif7
    @mek101whatif7 2 роки тому +2

    FOR THE ALGORHYTHM!!!

  • @arkadiuszszulc3303
    @arkadiuszszulc3303 2 місяці тому

    Useful info but why these noisy keyboard clicks, ha? It is a common knowledge that signs in an editor come from a keyboard. It just distracts.

    • @CodeForYourself
      @CodeForYourself  2 місяці тому

      @@arkadiuszszulc3303 I think I largely agree with you nowadays and that’s why in the recent videos I’ve done away with clocks altogether. That being said, it is a thing of personal preference and I do know people who prefer it with clicks because they like it aesthetically. It is hard to tailor to everybody. 😅 At this point I just hope it is not too distracting.