Unable to use the 'exercism test' command with C++ files in WSL

,

Hey everyone!
I’m running C++ in WSL (Windows Subsystem for Linux).
Everything works great, including building the file with CMake, but for some reason the ‘exercism test’ command isn’t working (or I might be not understanding something).

Here’s the current situation:
I’m building via CMake with the following commands:

cmake -G “Unix Makefiles” …
make
The build is successful and I’m getting:
“All tests passed (1 assertion in 1 test case)”

Now when I actually submit my file, I get a fail (I’ve already managed to fix it, I saw the problem, but the main issue here is that the local test wasn’t correct so I’m not sure why “All tests passed”)

Now, I’ve also tried running:

exercism test

But depending on the place I run it from I get errors like:

~/exercism$ exercism test
Error: open .exercism/metadata.json: no such file or directory

Or from the file folder itself:

~/exercism/cpp/log-levels/build$ exercism test
Error: open .exercism/metadata.json: no such file or directory

Help would be much appreciated as I would like to stay local until solving all of my errors before submitting.

Thanks!!
Barak

It seems you executed exercism test from the ~/exercism directory and from the ~/exercism/cpp/log-levels/build directory.

Can you try once more, from the ~/exercism/cpp/log-levels directory?

Edit: Sorry, that only seems to work if you build “in-tree”, not in a separate build directory.

Hey!
Thanks for the quick reply.

Yeah, I’ve tried from there as well, but still getting:

~/exercism/cpp/log-levels$ exercism test
Running tests via make
make: *** No targets specified and no makefile found. Stop.

I think you have two options:
Either build the project “in-tree”, not in a separate build directory, or
(instead of exercism test) call make directly in the build directory.

Gotcha
When I try to run the ‘make’ command inside the build folder directly, for some reason, all tests are passing. But when I actually submit the file - it fails.
So for some reason the test isn’t correct?
Or the actual tests can only occur after submitting (on Exercism’s website itself)?

I’ve also tried building with CMake directly inside the folder (without creating a separate build folder), and now I’m able to call the ‘exercism test’ command when I run it directly as you suggested, but the test are still passing when intentionally I’ve made mistakes in order to test the tests (lol)

To submit you can call exercism submit from the directory of the exercise … not from the build directory.

Yes, I know. The problem isn’t submitting, it’s the fact that ‘exercism test’ tests are passing while there are mistakes in the .cpp file.
Therefore I must submit to actually see the mistakes, and I would like to test it locally if possible. But the local test is passing my .cpp for some reason (while there are mistakes in it)

Sorry, I misunderstood your last two comments.

Did you explicitly enable all the tests? Initially only the first test is enabled, all subsequent tests are disabled with the line
#if defined(EXERCISM_RUN_ALL_TESTS)

The intended use is that you focus on one test at a time, make it pass, clean up the code, and then move that line one test further to enable the next test. That’s somewhat similar to Test Driven Development (TDD).

Of course, you can enable all tests from the start by passing the argument -DEXERCISM_RUN_ALL_TESTS=1 to the initial call of cmake.

1 Like

Yes!
Perfect, that was it.

That’s very interesting, is there a place I can read more about the flags with CMake and the recommended practice on how to test locally?

Thanks a lot!

There should be a file HELP.md with an explanation.

The same information is available online at

1 Like

Just to summarize, for anyone else facing a similar issue, you can:

Open a new folder inside the project folder:

mkdir build
cd build

Then run:

cmake -G "Unix Makefiles" -DEXERCISM_RUN_ALL_TESTS=1 ..

And then, for me at least, instead of using exercism test, only make works to run the tests correctly (when using a separated build folder):

make

1 Like