Timeout while testing

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:

[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:

            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)

@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.​

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

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.

Thank you. I thought it would return 0.

1 Like

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