From 37e012f2e035db94d27677deb992a8d538438feb Mon Sep 17 00:00:00 2001 From: imd Date: Tue, 8 Jun 2021 22:40:43 +0100 Subject: [PATCH] improved sequential_006 tests --- .../sequential/rule_005_test_input.fixed.vhd | 10 +- ...st_input.fixed_allowing_blank_and_case.vhd | 75 +++++++++++ ...test_input.fixed_allowing_blank_and_if.vhd | 75 +++++++++++ ...t.fixed_allowing_blank_and_if_and_case.vhd | 75 +++++++++++ vsg/tests/sequential/rule_005_test_input.vhd | 10 +- vsg/tests/sequential/test_rule_005.py | 124 +++++++++++++++++- 6 files changed, 358 insertions(+), 11 deletions(-) create mode 100644 vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_case.vhd create mode 100644 vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_if.vhd create mode 100644 vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_if_and_case.vhd diff --git a/vsg/tests/sequential/rule_005_test_input.fixed.vhd b/vsg/tests/sequential/rule_005_test_input.fixed.vhd index d1e7e542..d87c4384 100644 --- a/vsg/tests/sequential/rule_005_test_input.fixed.vhd +++ b/vsg/tests/sequential/rule_005_test_input.fixed.vhd @@ -21,12 +21,16 @@ begin end if; end if; + sig1_abcdefgh <= sig2; + sig2_abcdefgh <= sig3; + sig2_abcdefgh <= sig3; + case address is when 0 => - sig5 <= sig6; - sig6 <= sig7; - sig6 <= sig7; + sig5_a <= sig6; + sig6_a <= sig7; + sig6_a <= sig7; when 1 => sig5_abc <= sig6; sig6_abc <= sig7; diff --git a/vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_case.vhd b/vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_case.vhd new file mode 100644 index 00000000..86cad397 --- /dev/null +++ b/vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_case.vhd @@ -0,0 +1,75 @@ + +architecture RTL of FIFO is + +begin + + process + begin + + sig1 <= sig2; + sig2 <= sig3; + sig2 <= sig3; + + if a = b then + sig3 <= sig4; + sig4 <= sig5; + sig4 <= sig5; + if c = d then + sig6 <= sig7; + sig7 <= sig8; + sig7 <= sig8; + end if; + end if; + + sig1_abcdefgh <= sig2; + sig2_abcdefgh <= sig3; + sig2_abcdefgh <= sig3; + + case address is + + when 0 => + sig5_a <= sig6; + sig6_a <= sig7; + sig6_a <= sig7; + when 1 => + sig5_abc <= sig6; + sig6_abc <= sig7; + sig6_abc <= sig7; + + end case; + + end process; + + -- Violations below + + process + begin + + sig1 <= sig2; + sig2 <= sig3; + sig2 <= sig3; + + if a = b then + sig3 <= sig4; + sig4 <= sig5; + sig4 <= sig5; + if c = d then + sig6 <= sig7; + sig7 <= sig8; + sig7 <= sig8; + end if; + end if; + + case address is + + when 0 => + sig5 <= sig6; + sig6 <= sig7; + sig6 <= sig7; + + end case; + + end process; + + +end architecture RTL; diff --git a/vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_if.vhd b/vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_if.vhd new file mode 100644 index 00000000..0ffbd765 --- /dev/null +++ b/vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_if.vhd @@ -0,0 +1,75 @@ + +architecture RTL of FIFO is + +begin + + process + begin + + sig1 <= sig2; + sig2 <= sig3; + sig2 <= sig3; + + if a = b then + sig3 <= sig4; + sig4 <= sig5; + sig4 <= sig5; + if c = d then + sig6 <= sig7; + sig7 <= sig8; + sig7 <= sig8; + end if; + end if; + + sig1_abcdefgh <= sig2; + sig2_abcdefgh <= sig3; + sig2_abcdefgh <= sig3; + + case address is + + when 0 => + sig5_a <= sig6; + sig6_a <= sig7; + sig6_a <= sig7; + when 1 => + sig5_abc <= sig6; + sig6_abc <= sig7; + sig6_abc <= sig7; + + end case; + + end process; + + -- Violations below + + process + begin + + sig1 <= sig2; + sig2 <= sig3; + sig2 <= sig3; + + if a = b then + sig3 <= sig4; + sig4 <= sig5; + sig4 <= sig5; + if c = d then + sig6 <= sig7; + sig7 <= sig8; + sig7 <= sig8; + end if; + end if; + + case address is + + when 0 => + sig5 <= sig6; + sig6 <= sig7; + sig6 <= sig7; + + end case; + + end process; + + +end architecture RTL; diff --git a/vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_if_and_case.vhd b/vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_if_and_case.vhd new file mode 100644 index 00000000..c152fcc7 --- /dev/null +++ b/vsg/tests/sequential/rule_005_test_input.fixed_allowing_blank_and_if_and_case.vhd @@ -0,0 +1,75 @@ + +architecture RTL of FIFO is + +begin + + process + begin + + sig1 <= sig2; + sig2 <= sig3; + sig2 <= sig3; + + if a = b then + sig3 <= sig4; + sig4 <= sig5; + sig4 <= sig5; + if c = d then + sig6 <= sig7; + sig7 <= sig8; + sig7 <= sig8; + end if; + end if; + + sig1_abcdefgh <= sig2; + sig2_abcdefgh <= sig3; + sig2_abcdefgh <= sig3; + + case address is + + when 0 => + sig5_a <= sig6; + sig6_a <= sig7; + sig6_a <= sig7; + when 1 => + sig5_abc <= sig6; + sig6_abc <= sig7; + sig6_abc <= sig7; + + end case; + + end process; + + -- Violations below + + process + begin + + sig1 <= sig2; + sig2 <= sig3; + sig2 <= sig3; + + if a = b then + sig3 <= sig4; + sig4 <= sig5; + sig4 <= sig5; + if c = d then + sig6 <= sig7; + sig7 <= sig8; + sig7 <= sig8; + end if; + end if; + + case address is + + when 0 => + sig5 <= sig6; + sig6 <= sig7; + sig6 <= sig7; + + end case; + + end process; + + +end architecture RTL; diff --git a/vsg/tests/sequential/rule_005_test_input.vhd b/vsg/tests/sequential/rule_005_test_input.vhd index 7dd7f0f2..bcb42804 100644 --- a/vsg/tests/sequential/rule_005_test_input.vhd +++ b/vsg/tests/sequential/rule_005_test_input.vhd @@ -21,12 +21,16 @@ begin end if; end if; + sig1_abcdefgh <= sig2; + sig2_abcdefgh <= sig3; + sig2_abcdefgh <= sig3; + case address is when 0 => - sig5 <= sig6; - sig6 <= sig7; - sig6 <= sig7; + sig5_a <= sig6; + sig6_a <= sig7; + sig6_a <= sig7; when 1 => sig5_abc <= sig6; sig6_abc <= sig7; diff --git a/vsg/tests/sequential/test_rule_005.py b/vsg/tests/sequential/test_rule_005.py index 0697de9c..445c4bbf 100644 --- a/vsg/tests/sequential/test_rule_005.py +++ b/vsg/tests/sequential/test_rule_005.py @@ -10,10 +10,21 @@ sTestDir = os.path.dirname(__file__) lFile, eError =vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir,'rule_005_test_input.vhd')) -lExpected = [] -lExpected.append('') -utils.read_file(os.path.join(sTestDir, 'rule_005_test_input.fixed.vhd'), lExpected) +lExpected_all = [] +lExpected_all.append('') +utils.read_file(os.path.join(sTestDir, 'rule_005_test_input.fixed.vhd'), lExpected_all) +lExpected_blank_if = [] +lExpected_blank_if.append('') +utils.read_file(os.path.join(sTestDir, 'rule_005_test_input.fixed_allowing_blank_and_if.vhd'), lExpected_blank_if) + +lExpected_blank_if_case = [] +lExpected_blank_if_case.append('') +utils.read_file(os.path.join(sTestDir, 'rule_005_test_input.fixed_allowing_blank_and_if_and_case.vhd'), lExpected_blank_if_case) + +lExpected_blank_case = [] +lExpected_blank_case.append('') +utils.read_file(os.path.join(sTestDir, 'rule_005_test_input.fixed_allowing_blank_and_case.vhd'), lExpected_blank_case) class test_sequential_rule(unittest.TestCase): @@ -27,19 +38,122 @@ class test_sequential_rule(unittest.TestCase): self.assertEqual(oRule.name, 'sequential') self.assertEqual(oRule.identifier, '005') - lExpected = [44, 45, 46, 49, 50, 51, 53, 54, 62, 63, 64] + oRule.if_control_statements_ends_group = True + oRule.case_control_statements_ends_group = True + oRule.blank_line_ends_group = True + + lExpected = [48, 49, 50, 53, 54, 55, 57, 58, 66, 67, 68] oRule.analyze(self.oFile) self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + def test_rule_005_allowing_blank_and_if(self): + oRule = sequential.rule_005() + self.assertTrue(oRule) + self.assertEqual(oRule.name, 'sequential') + self.assertEqual(oRule.identifier, '005') + + oRule.if_control_statements_ends_group = False + oRule.case_control_statements_ends_group = True + oRule.blank_line_ends_group = False + + lExpected = [9, 10, 11, 14, 15, 16, 18, 19, 20, 48, 49, 50, 53, 54, 55, 57, 58, 66, 67, 68] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_rule_005_allowing_blank_and_case(self): + oRule = sequential.rule_005() + self.assertTrue(oRule) + self.assertEqual(oRule.name, 'sequential') + self.assertEqual(oRule.identifier, '005') + + oRule.if_control_statements_ends_group = True + oRule.case_control_statements_ends_group = False + oRule.blank_line_ends_group = False + + lExpected = [31, 32, 33, 35, 36, 37, 48, 49, 50, 53, 54, 55, 57, 58, 66, 67, 68] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_rule_005_allowing_blank_and_if_and_case(self): + oRule = sequential.rule_005() + self.assertTrue(oRule) + self.assertEqual(oRule.name, 'sequential') + self.assertEqual(oRule.identifier, '005') + + oRule.if_control_statements_ends_group = False + oRule.case_control_statements_ends_group = False + oRule.blank_line_ends_group = False + + lExpected = [9, 10, 11, 14, 15, 16, 18, 19, 20, 31, 32, 33, 35, 36, 37, 48, 49, 50, 53, 54, 55, 57, 58, 66, 67, 68] + + oRule.analyze(self.oFile), + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + def test_fix_rule_005(self): oRule = sequential.rule_005() + oRule.if_control_statements_ends_group = True + oRule.case_control_statements_ends_group = True + oRule.blank_line_ends_group = True + oRule.fix(self.oFile) lActual = self.oFile.get_lines() - self.assertEqual(lExpected, lActual) + self.assertEqual(lExpected_all, lActual) oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) + + def test_fix_rule_005_allowing_blank_and_if(self): + oRule = sequential.rule_005() + + oRule.if_control_statements_ends_group = False + oRule.case_control_statements_ends_group = True + oRule.blank_line_ends_group = False + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_blank_if, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_005_allowing_blank_and_if_and_case(self): + oRule = sequential.rule_005() + + oRule.if_control_statements_ends_group = False + oRule.case_control_statements_ends_group = False + oRule.blank_line_ends_group = False + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_blank_if_case, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_005_allowing_blank_and_case(self): + oRule = sequential.rule_005() + + oRule.if_control_statements_ends_group = True + oRule.case_control_statements_ends_group = False + oRule.blank_line_ends_group = False + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_blank_case, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + +