# Timeout while testing

**URL:** <https://forum.codecrafters.io/t/timeout-while-testing/1826>\
**Category:** Challenges\
**Tags:** challenge:interpreter\
**Created:** [September 17, 2024, 8:43pm UTC](https://forum.codecrafters.io/t/timeout-while-testing/1826 "2024-09-17T20:43:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PedroFernandesMIEI](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/pedrofernandesmiei/32/1752_2.png) [@PedroFernandesMIEI](https://forum.codecrafters.io/u/PedroFernandesMIEI)\
**Post date:** [September 17, 2024, 8:43pm UTC](https://forum.codecrafters.io/t/timeout-while-testing/1826/1 "2024-09-17T20:43:46Z")

</div>

I’m stuck on Stage #TZ7.

I’ve tried testing my solution, but I always get stuck in the test that uses “//Comment” and it times out the testing when others run normally fast.

Here are my logs:

```auto
[tester::#TZ7] Running tests for Stage #TZ7 (Scanning: Multi-line errors)
[tester::#TZ7] [test-1] Running test case: 1
[tester::#TZ7] [test-1] Writing contents to ./test.lox:
[tester::#TZ7] [test-1] [test.lox] ()<|SPACE|><|TAB|>@
[tester::#TZ7] [test-1] $ ./your_program.sh tokenize test.lox
[your_program] LEFT_PAREN ( null
[your_program] RIGHT_PAREN ) null
[your_program] [line 2] Error: Unexpected character: @
[your_program] EOF null
[tester::#TZ7] [test-1] ✓ 1 line(s) match on stderr
[tester::#TZ7] [test-1] ✓ 3 line(s) match on stdout
[tester::#TZ7] [test-1] ✓ Received exit code 65.
[tester::#TZ7] [test-2] Running test case: 2
[tester::#TZ7] [test-2] Writing contents to ./test.lox:
[tester::#TZ7] [test-2] [test.lox] #
[tester::#TZ7] [test-2] [test.lox] %<|TAB|>
[tester::#TZ7] [test-2] $ ./your_program.sh tokenize test.lox
[your_program] EOF null
[your_program] [line 1] Error: Unexpected character: #
[your_program] [line 2] Error: Unexpected character: %
[tester::#TZ7] [test-2] ✓ 2 line(s) match on stderr
[tester::#TZ7] [test-2] ✓ 1 line(s) match on stdout
[tester::#TZ7] [test-2] ✓ Received exit code 65.
[tester::#TZ7] [test-3] Running test case: 3
[tester::#TZ7] [test-3] Writing contents to ./test.lox:
[tester::#TZ7] [test-3] [test.lox] () #<|TAB|>{}
[tester::#TZ7] [test-3] [test.lox] @
[tester::#TZ7] [test-3] [test.lox] $
[tester::#TZ7] [test-3] [test.lox] +++
[tester::#TZ7] [test-3] [test.lox] // Let's Go!
[tester::#TZ7] [test-3] [test.lox] +++
[tester::#TZ7] [test-3] [test.lox] #
[tester::#TZ7] [test-3] $ ./your_program.sh tokenize test.lox
[your_program] [line 1] Error: Unexpected character: #
[your_program] [line 2] Error: Unexpected character: @
[your_program] [line 3] Error: Unexpected character: $
[your_program] [line 7] Error: Unexpected character: #
[your_program] LEFT_PAREN ( null
[your_program] RIGHT_PAREN ) null
[your_program] LEFT_BRACE { null
[your_program] RIGHT_BRACE } null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] EOF null
[tester::#TZ7] [test-3] ✓ 4 line(s) match on stderr
[tester::#TZ7] [test-3] ✓ 11 line(s) match on stdout
[tester::#TZ7] [test-3] ✓ Received exit code 65.
[tester::#TZ7] [test-4] Running test case: 4
[tester::#TZ7] [test-4] Writing contents to ./test.lox:
[tester::#TZ7] [test-4] [test.lox] ({;
[tester::#TZ7] [test-4] [test.lox] @})
[tester::#TZ7] [test-4] $ ./your_program.sh tokenize test.lox
[your_program] LEFT_PAREN ( null
[your_program] [line 2] Error: Unexpected character: @
[your_program] LEFT_BRACE { null
[your_program] SEMICOLON ; null
[your_program] RIGHT_BRACE } null
[your_program] RIGHT_PAREN ) null
[your_program] EOF null
[tester::#TZ7] [test-4] ✓ 1 line(s) match on stderr
[tester::#TZ7] [test-4] ✓ 6 line(s) match on stdout
[tester::#TZ7] [test-4] ✓ Received exit code 65.
[tester::#TZ7] Test passed.

[tester::#ER2] Running tests for Stage #ER2 (Scanning: Whitespace)
[tester::#ER2] [test-1] Running test case: 1
[tester::#ER2] [test-1] Writing contents to ./test.lox:
[tester::#ER2] [test-1] [test.lox] <|SPACE|>
[tester::#ER2] [test-1] $ ./your_program.sh tokenize test.lox
[your_program] EOF null
[tester::#ER2] [test-1] ✓ 1 line(s) match on stdout
[tester::#ER2] [test-1] ✓ Received exit code 0.
[tester::#ER2] [test-2] Running test case: 2
[tester::#ER2] [test-2] Writing contents to ./test.lox:
[tester::#ER2] [test-2] [test.lox] <|TAB|>
[tester::#ER2] [test-2] [test.lox] <|SPACE|>
[tester::#ER2] [test-2] $ ./your_program.sh tokenize test.lox
[your_program] EOF null
[tester::#ER2] [test-2] ✓ 1 line(s) match on stdout
[tester::#ER2] [test-2] ✓ Received exit code 0.
[tester::#ER2] [test-3] Running test case: 3
[tester::#ER2] [test-3] Writing contents to ./test.lox:
[tester::#ER2] [test-3] [test.lox] {
[tester::#ER2] [test-3] [test.lox] }
[tester::#ER2] [test-3] [test.lox] ((<|SPACE|>.,;))
[tester::#ER2] [test-3] $ ./your_program.sh tokenize test.lox
[your_program] LEFT_BRACE { null
[your_program] RIGHT_BRACE } null
[your_program] LEFT_PAREN ( null
[your_program] LEFT_PAREN ( null
[your_program] DOT . null
[your_program] COMMA , null
[your_program] SEMICOLON ; null
[your_program] RIGHT_PAREN ) null
[your_program] RIGHT_PAREN ) null
[your_program] EOF null
[tester::#ER2] [test-3] ✓ 10 line(s) match on stdout
[tester::#ER2] [test-3] ✓ Received exit code 0.
[tester::#ER2] [test-4] Running test case: 4
[tester::#ER2] [test-4] Writing contents to ./test.lox:
[tester::#ER2] [test-4] [test.lox] {<|TAB|><|TAB|>
[tester::#ER2] [test-4] [test.lox]
[tester::#ER2] [test-4] [test.lox] }
[tester::#ER2] [test-4] [test.lox] ((>-,
[tester::#ER2] [test-4] [test.lox] ;))
[tester::#ER2] [test-4] $ ./your_program.sh tokenize test.lox
[your_program] LEFT_BRACE { null
[your_program] RIGHT_BRACE } null
[your_program] LEFT_PAREN ( null
[your_program] LEFT_PAREN ( null
[your_program] GREATER > null
[your_program] MINUS - null
[your_program] COMMA , null
[your_program] SEMICOLON ; null
[your_program] RIGHT_PAREN ) null
[your_program] RIGHT_PAREN ) null
[your_program] EOF null
[tester::#ER2] [test-4] ✓ 11 line(s) match on stdout
[tester::#ER2] [test-4] ✓ Received exit code 0.
[tester::#ER2] Test passed.

[tester::#ML2] Running tests for Stage #ML2 (Scanning: Division operator & comments)
[tester::#ML2] [test-1] Running test case: 1
[tester::#ML2] [test-1] Writing contents to ./test.lox:
[tester::#ML2] [test-1] [test.lox] //Comment
[tester::#ML2] [test-1] $ ./your_program.sh tokenize test.lox
[tester::#ML2] [test-1] timed out, test exceeded 10 seconds
[tester::#ML2] [test-1] Test failed

```

And here’s a snippet of my code that I added for this stage to work:

```python
            elif char == "/":
                if idx + 1 < len(file_contents) and file_contents[idx + 1] == "/":
                    if file_contents.find("\n", idx + 2) == 0:
                        idx = len(file_contents) - 1
                    else:
                        idx = file_contents.find("\n", idx + 1) - 1
                else:
                    print("SLASH / null")
            elif char in "$#@%":
                print(f"[line {line_number}] Error: Unexpected character: {char}", file=sys.stderr)
                error_code = 65
            elif char in " \t":
                pass
            elif char == "\n":
                line_number += 1
            idx += 1

        print("EOF null")
        exit(error_code)

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [September 18, 2024, 12:50pm UTC](https://forum.codecrafters.io/t/timeout-while-testing/1826/2 "2024-09-18T12:50:28Z")

</div>

@PedroFernandesMIEI Could you please explain briefly in words what the intended behavior of the `elif char == "/"` block is?

I want to make sure I fully understand it before offering suggestions or helping you troubleshoot.​

---

<div class="post-metadata">

**Author:** ![PedroFernandesMIEI](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/pedrofernandesmiei/32/1752_2.png) [@PedroFernandesMIEI](https://forum.codecrafters.io/u/PedroFernandesMIEI)\
**Post date:** [September 18, 2024, 7:58pm UTC](https://forum.codecrafters.io/t/timeout-while-testing/1826/3 "2024-09-18T19:58:25Z")

</div>

In a previous stage I was asked to have a token for both slash and comment. At the time I only wanted it to find if there are 2 slashes consecutevly, and if so make the idx the last character/token since it’s with only one line.  
For this stage however there can be more than 1 line. So my thought process was to find if there is a ‘/n’ at the end of the comment to see if it is only one single line, the last or one in between.

So for one of the tests it would read the ‘//’ and would find a ‘/n’ at the end of the line, and would therefore skip to the last token of the current line (the newline char) and proceed from there. For this one in particular it shouldn’t find any ‘/n’ and would skip until the last token (because later it would add 1 to idx and it would be over the file\_contents’s length and end with EOF.

I hope I explained my ideas, if you have any questions tell me.

Thanks for the help

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [September 19, 2024, 11:36pm UTC](https://forum.codecrafters.io/t/timeout-while-testing/1826/4 "2024-09-19T23:36:15Z")

</div>

> would find a ‘/n’ at the end of the line…  
> this one in particular it shouldn’t find any ‘/n’…

@PedroFernandesMIEI To check whether the newline is absent, compare the result of `find` with -1, instead of 0.

---

<div class="post-metadata">

**Author:** ![PedroFernandesMIEI](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/pedrofernandesmiei/32/1752_2.png) [@PedroFernandesMIEI](https://forum.codecrafters.io/u/PedroFernandesMIEI)\
**Post date:** [September 20, 2024, 1:58pm UTC](https://forum.codecrafters.io/t/timeout-while-testing/1826/5 "2024-09-20T13:58:39Z")

</div>

Thank you. I thought it would return 0.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [September 25, 2024, 1:59pm UTC](https://forum.codecrafters.io/t/timeout-while-testing/1826/6 "2024-09-25T13:59:31Z")

</div>

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