CPP build, debug and test

Hi there,

I had some issue when I work with the CPP track.

Take “Log Levels” for example, I downloaded the code with exercism ... and the log_levels.cpp will look like something like this:

std::string message(std::string line) {
// return something
}

My practice is that I wrote some garbage code first to satisfy the function declaration, so I changed the 3 functions:

namespace log_line {
    std::string message(std::string line) {
        return line;
    }

    std::string log_level(std::string line) {
        return line;
    }

    std::string reformat(std::string line) {
        return line;
    }
}

I know this code will not pass tests. But, I have problem to compile / build too!

I use VSC on Windows and installed the extension CMake Test Toos. I can see the flask icon on my sidebar showing the test cases:

I use CMake:Refresh Tests but the compiler refuse to compile and thus I can’t debug. I have to fill in the correct codes then the exe can be generated.

My view is: TDD is a cycle with test-debug-write. Nobody can guarantee he/she can write the correct codes the first place.

Am I missing something here? Or the flow of my development is wrong?

When I use the “refresh test” icon in the testing panel of vs code I get the following output:

[main] Building folder: matching-brackets 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/cwillner/projects/exercism/cpp/matching-brackets/build --config Debug --target all --
[build] [1/1 100% :: 0.008] cd /home/cwillner/projects/exercism/cpp/matching-brackets/build && /home/cwillner/projects/exercism/cpp/matching-brackets/build/matching-brackets
[build] ===============================================================================
[build] All tests passed (14 assertions in 14 test cases)
[build] 
[driver] Build completed: 00:00:00.082
[build] Build finished with exit code 0

So the extension is working with our code base, but I cannot use the extensions “run tests” command, because I get a [ctest] No tests were found!!!.

I always use the console to run the tests, so I am not entirely sure what the extension is doing differently or expecting here.

That probably is because in the corresponding test file, say log_levels_test.cpp, the #if defined(EXERCISM_RUN_ALL_TESTS) is NOT in effect.

To have all test to run, we need to define that thing first. I normally put it at the beginning of the XXX_test.cpp file.

Further note: looking at the info provided, it seems that the test suite actually runs ALL tests and passed.

My current issue is, if one test fails, the compilation won’t finish and thus I can’t further debug.

It is not related to the plug-in because if I write all the codes correctly, the test suite can compile, build and pass. But this is not what a test case is meant for, right?