Skip to content

fix: replace broken test_compile_code and add compile failure test#162

Open
sakshamg19 wants to merge 1 commit intoc2siorg:mainfrom
sakshamg19:fix/test-compile-code
Open

fix: replace broken test_compile_code and add compile failure test#162
sakshamg19 wants to merge 1 commit intoc2siorg:mainfrom
sakshamg19:fix/test-compile-code

Conversation

@sakshamg19
Copy link
Copy Markdown

Fixes #161

Description

test_compile_code in gdbui_server/flask_test.py was mocking self.client.post which is the Flask test client itself. This meant
the actual /compile route handler never ran during the test. The test was only checking that a mock returned what it was set up to return, so it would always pass regardless of what the real code does.

Changes

Fixed by mocking subprocess.run instead and sending a real request through Flask, which now exercises JSON parsing, file writing, and response building.

Added test_compile_code_failure to cover the g++ non-zero exit code path (lines 88-89 in main.py), which had zero test coverage.

Added *.cpp and *.exe to gdbui_server/.gitignore to prevent compiled test artifacts from being accidentally committed.

Testing

python3 -m unittest flask_test.TestGDBRoutes.test_compile_code -v passes
python3 -m unittest flask_test.TestGDBRoutes.test_compile_code_failure -v passes
Full test suite (python3 -m unittest flask_test -v) passes with 21/21 tests

The test patched self.client.post which meant the actual /compile route never executed. It only checked that a mock returned what it was told to return so it could never catch a real bug.

Fixed it by mocking subprocess.run instead and sending a real request through Flask. Also added test_compile_code_failure to cover the case where g++ returns a non-zero exit code which had no coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant