fix: replace broken test_compile_code and add compile failure test#162
Open
sakshamg19 wants to merge 1 commit intoc2siorg:mainfrom
Open
fix: replace broken test_compile_code and add compile failure test#162sakshamg19 wants to merge 1 commit intoc2siorg:mainfrom
sakshamg19 wants to merge 1 commit intoc2siorg:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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