From 43873c10e2a97793039d2e8e9058793d3dc89e36 Mon Sep 17 00:00:00 2001 From: Nguyen Nguyen Date: Sat, 6 Apr 2024 01:01:39 -0700 Subject: [PATCH] Print out log file to console --- tests/integration/helpers.py | 7 ++++++ tests/integration/test_SA.py | 41 +++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 804a29c..0494dfc 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -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 diff --git a/tests/integration/test_SA.py b/tests/integration/test_SA.py index 32885f0..32eb240 100644 --- a/tests/integration/test_SA.py +++ b/tests/integration/test_SA.py @@ -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): @@ -77,7 +77,11 @@ 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): @@ -85,11 +89,29 @@ def test_medium(self): 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) { @@ -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 = """ @@ -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__':