Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
unit test for syntax error added
Browse files Browse the repository at this point in the history
  • Loading branch information
ThakeeNathees committed Jul 30, 2024
1 parent 877f2ec commit a771c73
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion jaclang/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,19 @@ def test_jac_cli_alert_based_err(self) -> None:
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
stdout_value = captured_output.getvalue()
# print(stdout_value)

self.assertIn("Error", stdout_value)

expected_stdout_values = (
"can speak {",
' "Hello" |> : print;',
" ~",
"}",
)
logger_capture = "\n".join([rec.message for rec in self.caplog.records])
for exp in expected_stdout_values:
self.assertIn(exp, logger_capture)

def test_jac_impl_err(self) -> None:
"""Basic test for pass."""
if "jaclang.tests.fixtures.err" in sys.modules:
Expand Down
9 changes: 9 additions & 0 deletions jaclang/utils/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
from typing import Callable, Optional
from unittest import TestCase as _TestCase

from _pytest.logging import LogCaptureFixture

import jaclang
from jaclang.compiler.passes import Pass
from jaclang.utils.helpers import get_ast_nodes_as_snake_case as ast_snakes

import pytest


class TestCase(_TestCase):
"""Base test case for Jaseci."""

# Reference: https://stackoverflow.com/a/50375022
@pytest.fixture(autouse=True)
def inject_fixtures(self, caplog: LogCaptureFixture) -> None:
"""Store the logger capture records within the tests."""
self.caplog = caplog

def setUp(self) -> None:
"""Set up test case."""
return super().setUp()
Expand Down

0 comments on commit a771c73

Please sign in to comment.