Test Overview
This test checks if the static analysis tool correctly identifies a syntax error in the source code before running the program. It verifies that the tool reports the error and prevents faulty code from executing.
This test checks if the static analysis tool correctly identifies a syntax error in the source code before running the program. It verifies that the tool reports the error and prevents faulty code from executing.
def test_static_analysis_detects_syntax_error(): # Simulate running a static analysis tool on code with a syntax error source_code = 'def foo(:\n pass' try: # Normally, a static analysis tool would parse the code compile(source_code, '<string>', 'exec') error_detected = False except SyntaxError as e: error_detected = True error_message = str(e) assert error_detected, 'Static analysis did not detect syntax error' assert 'invalid syntax' in error_message, 'Error message does not mention syntax issue'
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test environment is ready with PyTest framework | - | PASS |
| 2 | Simulate static analysis by compiling source code with syntax error | Source code contains 'def foo(:\n pass' which is invalid syntax | - | PASS |
| 3 | Catch SyntaxError exception from compile() | SyntaxError exception is raised with message about invalid syntax | Check that error_detected is True | PASS |
| 4 | Assert error message contains 'invalid syntax' | Error message string is available from exception | Verify 'invalid syntax' in error_message | PASS |
| 5 | Test ends with all assertions passed | Static analysis tool correctly detected syntax error | - | PASS |