C: Stuck on #ea6

When running local tests, all seems to working just fine. But the tests are failing. I’ve no clue what’s wrong in my code.

My code is here: GitHub - s-frick/lox-interpreter

Here are my logs:

  1. codecrafters test
  2. codecrafters test -previous
  3. local test for paren “(”
  4. local test unexpected char and exit code
~/g/p/codecrafters-interpreter-c % codecrafters test
Initiating test run...

⚡ This is a turbo test run. https://codecrafters.io/turbo

Running tests. Logs should appear shortly...

[compile] -- Running vcpkg install
[compile] All requested packages are currently installed.
[compile] Total install time: 220 ns
[compile] -- Running vcpkg install - done
[compile] -- The C compiler identification is GNU 14.2.0
[compile] -- The CXX compiler identification is GNU 14.2.0
[compile] -- Detecting C compiler ABI info
[compile] -- Detecting C compiler ABI info - done
[compile] -- Check for working C compiler: /usr/bin/cc - skipped
[compile] -- Detecting C compile features
[compile] -- Detecting C compile features - done
[compile] -- Detecting CXX compiler ABI info
[compile] -- Detecting CXX compiler ABI info - done
[compile] -- Check for working CXX compiler: /usr/local/bin/c++ - skipped
[compile] -- Detecting CXX compile features
[compile] -- Detecting CXX compile features - done
[compile] -- Configuring done (0.8s)
[compile] -- Generating done (0.0s)
[compile] -- Build files have been written to: /app/build
[compile] [ 33%] Building C object CMakeFiles/interpreter.dir/src/main.c.o
[compile] [ 66%] Building C object CMakeFiles/interpreter.dir/src/tokenizer.c.o
[compile] [100%] Linking C executable interpreter
[compile] [100%] Built target interpreter
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.

Debug = true

[tester::#EA6] Running tests for Stage #EA6 (Scanning: Lexical errors)
[tester::#EA6] [test-1] Running test case: 1
[tester::#EA6] [test-1] Writing contents to ./test.lox:
[tester::#EA6] [test-1] [test.lox] @
[tester::#EA6] [test-1] $ ./your_program.sh tokenize test.lox
[your_program] EOF  null
[tester::#EA6] [test-1] expected exit code 65, got 0
[tester::#EA6] [test-1] Test failed

View our article on debugging test failures: https://codecrafters.io/debug
~/g/p/codecrafters-interpreter-c % codecrafters test --previous
Initiating test run...

⚡ This is a turbo test run. https://codecrafters.io/turbo

Running tests. Logs should appear shortly...

[compile] -- Running vcpkg install
[compile] All requested packages are currently installed.
[compile] Total install time: 370 ns
[compile] -- Running vcpkg install - done
[compile] -- The C compiler identification is GNU 14.2.0
[compile] -- The CXX compiler identification is GNU 14.2.0
[compile] -- Detecting C compiler ABI info
[compile] -- Detecting C compiler ABI info - done
[compile] -- Check for working C compiler: /usr/bin/cc - skipped
[compile] -- Detecting C compile features
[compile] -- Detecting C compile features - done
[compile] -- Detecting CXX compiler ABI info
[compile] -- Detecting CXX compiler ABI info - done
[compile] -- Check for working CXX compiler: /usr/local/bin/c++ - skipped
[compile] -- Detecting CXX compile features
[compile] -- Detecting CXX compile features - done
[compile] -- Configuring done (1.0s)
[compile] -- Generating done (0.0s)
[compile] -- Build files have been written to: /app/build
[compile] [ 33%] Building C object CMakeFiles/interpreter.dir/src/main.c.o
[compile] [ 66%] Building C object CMakeFiles/interpreter.dir/src/tokenizer.c.o
[compile] [100%] Linking C executable interpreter
[compile] [100%] Built target interpreter
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.

Debug = true

[tester::#RY8] Running tests for Stage #RY8 (Scanning: Empty file)
[tester::#RY8] Writing contents to ./test.lox:
[tester::#RY8] [test.lox]
[tester::#RY8] $ ./your_program.sh tokenize test.lox
[your_program] EOF  null
[tester::#RY8] ✓ 1 line(s) match on stdout
[tester::#RY8] ✓ Received exit code 0.
[tester::#RY8] Test passed.

[tester::#OL4] Running tests for Stage #OL4 (Scanning: Parentheses)
[tester::#OL4] [test-1] Running test case: 1
[tester::#OL4] [test-1] Writing contents to ./test.lox:
[tester::#OL4] [test-1] [test.lox] (
[tester::#OL4] [test-1] $ ./your_program.sh tokenize test.lox
[your_program] EOF  null
[tester::#OL4] [test-1] 𐄂 EOF  null
[tester::#OL4] [test-1] Expected line #1 on stdout to be "LEFT_PAREN ( null", got "EOF  null"
[tester::#OL4] [test-1] Test failed

View our article on debugging test failures: https://codecrafters.io/debug
~/g/p/codecrafters-interpreter-c % echo "(" > paren.lox && ./your_program.sh tokenize paren.lox
-- Running vcpkg install
All requested packages are currently installed.
Total install time: 511 ns
-- Running vcpkg install - done
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/sfrick/git/private/codecrafters-interpreter-c/build
[100%] Built target interpreter
LEFT_PAREN ( null
EOF  null
~/g/p/codecrafters-interpreter-c % echo "@" > lex_error.lox && ./your_program.sh tokenize lex_error.lox
-- Running vcpkg install
All requested packages are currently installed.
Total install time: 371 ns
-- Running vcpkg install - done
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/sfrick/git/private/codecrafters-interpreter-c/build
[100%] Built target interpreter
[line 1] Error: Unexpected character: @
EOF  null
~/g/p/codecrafters-interpreter-c % echo $?
65
~/g/p/codecrafters-interpreter-c %

Hi @s-frick, I’ll take a look and get back to you by the end of the week.

1 Like

Hi @s-frick, there’s an off-by-one error here:

int is_at_end(Scanner *scanner) {
  return scanner->current >= strlen(scanner->source) - 1;
}
1 Like

That’s right. :see_no_evil: Thank you for taking the time.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.