I’m trying to go through Stage #ND9 (Count rows in a table), but I hit a wall. The test suite looks at the CLI output, but the Gleam compiler messages cause the tests to fail. I need a way to silence those, but I have no idea how. Any pointers? Here’s what it dumps on the terminal.
Compiled in 0.03s
Running sqlite.main
=ERROR REPORT==== 8-Aug-2024::19:01:39.036822 ===
backend port not found: inotifywait
107
107
is the actual expected output. Anything before that is stuff that I want to silence.
Another way would be getting the test suite to ignore the compiler output, but I think that’s not how this platform works, right?
One interesting detail is that I have gone through a lot of challenge stages with the Gleam compiler already, and this never came up as a problem. Could there be something wrong with how this stage specifically expects the output to be?
Update
Just found out about the new codecrafters test --previous
flag and ran a test on the previous stages. The compiler messages are there all the time, but the tests don’t complain at all, and pass. Only #ND9 seems to be affected.
1 Like
Ah, nice catch. This is something I’m working on fixing (we’re going to push an upstream patch for Add --no-print-progress flag to gleam run and gleam build · Issue #2299 · gleam-lang/gleam · GitHub). In the meantime, I’ve got a workaround for you:
Could you try editing .codecrafters/run.sh
to look like this?
That should filter out the messages for now.
With most languages this isn’t a problem, since debug messages are printed to stderr and not stdout. Looks like Gleam prints these to stdout though.
Other stages pass ok with the same messages. Is the testing different for #ND9 ? I went through the tester repo but couldn’t figure out where exactly it asserts the output.
exec gleam run --module sqlite -- "$@" | grep -v "Compiled" | grep -v "Running" | grep -v "=ERROR REPORT=" | grep -v "backend port" | grep -v "^\n"
This is what I ended up with, unable to filter out that last newline. Is there a way to fix how the test evaluates the output?
[tester::#ND9] Running tests for Stage #ND9 (Count rows in a table)
[tester::#ND9] $ ./your_program.sh test.db "select count(*) from pistachio"
[your_program]
[your_program] 142
[tester::#ND9] Expected "142\n" as stdout, got: "\n142\n"
[tester::#ND9] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
Here’s a fix for you:
Use the following command in .codecrafters/run.sh
and your_program.sh
:
grep -vE "Compiled|Running|=ERROR REPORT=|backend port|^$"`
# The only change was from ^\r?\n to ^$
@edgerunner Could you give this a try, and please let me know how it goes?
I was also baffled by why the extra \n couldn’t be eliminated. Turns out that grep works on a line-by-line basis, meaning \n was already consumed by grep , leaving us just blank lines which can’t be matched by ^\r?\n.
1 Like
Louis (Gleam maintainer) said that the fix should land in the next release within the next few weeks, we’ll keep this open until that’s landed!
1 Like
This worked with a little bit of escaping: ^\$
because $
is a replacement character.
Coincidentally, I learned a new thing about grep today, which affects how I approach the “Make your own GREP” challenge
1 Like
Yes, it’s already in the nightly. The only question mark is how do I upgrade the gleam version without starting a fresh repo. (Which I’d rather not because I use commit messages as code comments, thanks to the git-lens feature in Zed)