🐐 Line numbers in errors

This commit is contained in:
2026-04-25 20:21:16 +02:00
parent 382492a6fc
commit 272881e6cf
8 changed files with 176 additions and 71 deletions

View File

@@ -174,3 +174,34 @@ class TestCompilerErrors(unittest.TestCase):
@parameterized.expand(compiler_error_tests)
def test_compiler_errors(self, source, error_type):
run_compiler_error_test(self, source)
class TestErrorLineNumbers(unittest.TestCase):
def test_interpreter_error_includes_line(self):
source = "DESIGNA x VT III\nDIC(y)\n"
tokens = Lexer().get_lexer().lex(source)
program = Parser().parse(tokens)
with self.assertRaisesRegex(CentvrionError, r"at line 2"):
program.eval()
def test_compiled_error_includes_line(self):
source = "DESIGNA x VT III\nDIC(y)\n"
tokens = Lexer().get_lexer().lex(source)
program = Parser().parse(tokens)
c_source = compile_program(program)
with tempfile.NamedTemporaryFile(suffix=".c", delete=False, mode="w") as tmp_c:
tmp_c.write(c_source)
tmp_c_path = tmp_c.name
with tempfile.NamedTemporaryFile(suffix="", delete=False) as tmp_bin:
tmp_bin_path = tmp_bin.name
try:
subprocess.run(
["gcc", "-O2", tmp_c_path, _RUNTIME_C, "-o", tmp_bin_path, "-lcurl", "-lmicrohttpd"],
check=True, capture_output=True,
)
proc = subprocess.run([tmp_bin_path], capture_output=True, text=True)
self.assertNotEqual(proc.returncode, 0)
self.assertIn("at line 2", proc.stderr)
finally:
os.unlink(tmp_c_path)
os.unlink(tmp_bin_path)