Skip to content

[Bug] Flask /compile route has zero test coverage due to incorrect mock in test_compile_code #161

@sakshamg19

Description

@sakshamg19

Description


test_compile_code in gdbui_server/flask_test.py mocks self.client.post which is the Flask test client itself. This means the /compile route handler never runs during the test. The test just checks that a mock returns what it was set up to return, so it will always pass no matter what the real code does.

Every line of the actual /compile handler is untested:

  • request.get_json()
  • open(f'{name}.cpp', 'w')
  • subprocess.run(['g++', ...])
  • the success response
  • the failure response

Steps to Reproduce


  1. Open gdbui_server/flask_test.py
  2. Look at test_compile_code around line 29
  3. Line 31 patches self.client.post with a mock
  4. This replaces the HTTP transport so /compile never gets called

Expected behaviour


The test should send a real request to /compile and check the route actually works, only mocking subprocess.run so tests don't depend on g++ being installed.


Proposed fix


The test should mock subprocess.run instead of self.client.post. This way the Flask test client sends a real HTTP request to /compile, the route handler actually executes and only the g++ subprocess call at the system boundary gets mocked (since tests should not depend on g++ being installed in the CI environment).

The two tests that should replace the current one are:

  • test_compile_code: This mocks subprocess.run with returncode=0, sends a real request, verifies the route writes the source file to disk, calls g++ with the correct arguments and returns success: true with the right output message
  • test_compile_code_failure: mocks subprocess.run with returncode=1 and a stderr error message, verifies the route returns success: false with the compiler error in the output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions