Skip to content

Commit

Permalink
Merge pull request CodieTamida#133 from CodieTamida/integrationtest/p…
Browse files Browse the repository at this point in the history
…rint_out_log_message

Integration Test prints out log message to console to make it easier to debug
  • Loading branch information
CodieTamida authored Apr 6, 2024
2 parents 2572d52 + 43873c1 commit cae35b4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
7 changes: 7 additions & 0 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ def write_to_file(filename, content):
file.write(content)
file.close()

def print_file(filename):
# Open the file in read mode
with open(filename, 'r') as file:
# Read and print each line in the file
for line in file:
print(line, end='')

def run_command(command):
"""
Execute the command capture its output
Expand Down
41 changes: 36 additions & 5 deletions tests/integration/test_SA.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import os
from components.lexcical_analyzer import Lexer, Token
from tests.integration.helpers import write_to_file, read_tokens_from_lexer_output, read_tokens_from_parser_output, run_command
from tests.integration.helpers import write_to_file, print_file, read_tokens_from_lexer_output, read_tokens_from_parser_output, run_command


class SyntaxAnalyzerTestCase(unittest.TestCase):
Expand Down Expand Up @@ -77,19 +77,41 @@ def test_small(self):
tokens_from_parser = read_tokens_from_parser_output(self.PARSER_OUTPUT_PATH)

# Assert
self.assertListEqual(tokens_from_lexer, tokens_from_parser)
try:
self.assertListEqual(tokens_from_lexer, tokens_from_parser)
except:
print_file(self.PARSER_OUTPUT_PATH)
raise AssertionError("A token is missing")
self.assertIn("Syntax is correct", check_syntax_command_output)

def test_medium(self):
# Arrange
input_string = """
$
function alert(p1, p2 real, x, y, z boolean)
integer sum;
real p1, p2, p3, p4;
{
sum = p1 + p2;
if (sum != 0)
{
p1 = 1;
p2 = 2;
p3 = p1 * p2;
p4 = p3 / 5.5;
if (p4 => 10)
{
success = true;
return success;
}
endif
}
endif
}
function isPrime(n integer) {
function isPrime(n integer) boolean prime; integer i;
{
prime = true;
i = 2;
while (i <= n) {
Expand Down Expand Up @@ -131,8 +153,13 @@ def test_medium(self):
tokens_from_parser = read_tokens_from_parser_output(self.PARSER_OUTPUT_PATH)

# Assert
self.assertListEqual(tokens_from_lexer, tokens_from_parser)
try:
self.assertListEqual(tokens_from_lexer, tokens_from_parser)
except:
print_file(self.PARSER_OUTPUT_PATH)
raise AssertionError("A token is missing")
self.assertIn("Syntax is correct", check_syntax_command_output)

def test_large(self):
# Arrange
input_string = """
Expand Down Expand Up @@ -237,7 +264,11 @@ def test_large(self):
tokens_from_parser = read_tokens_from_parser_output(self.PARSER_OUTPUT_PATH)

# Assert
self.assertListEqual(tokens_from_lexer, tokens_from_parser)
try:
self.assertListEqual(tokens_from_lexer, tokens_from_parser)
except:
print_file(self.PARSER_OUTPUT_PATH)
raise AssertionError("A token is missing")
self.assertIn("Syntax is correct", check_syntax_command_output)

if __name__ == '__main__':
Expand Down

0 comments on commit cae35b4

Please sign in to comment.