This commit is contained in:
Jeremiah Leary 2021-10-12 06:42:22 -05:00
commit 0820cccd70
8 changed files with 91 additions and 18 deletions

4
.gitignore vendored
View File

@ -10,3 +10,7 @@ _build
# This version file should never be committed
vsg/version_info.py
# IDE files
.idea/
.vscode/

View File

@ -49,10 +49,10 @@ Refer to the section `Configuring Uppercase and Lowercase Rules <configuring.htm
.. code-block:: vhdl
port map (
WR_EN => wr_en,
RD_EN => rd_en,
OVERFLOW => overflow,
UNDERFLOW(c_index) => underflow
wr_en => wr_en,
rd_en => rd_en,
overflow => overflow,
underflow(c_index) => underflow
);
port_map_003
@ -60,7 +60,7 @@ port_map_003
|phase_1| |error|
This rule checks the ( is on the same line as the **port map** keywords.
This rule checks the "(" character is on the same line as the **port map** keywords.
**Violation**
@ -90,7 +90,7 @@ port_map_004
|phase_1| |error|
This rule checks the closing ) for the port map is on it's own line.
This rule checks the closing ")" character for the port map is on it's own line.
**Violation**

View File

@ -219,7 +219,7 @@ port_010
|phase_6| |error|
This rule checks port names are uppercase.
This rule checks the port names have proper case.
Refer to the section `Configuring Uppercase and Lowercase Rules <configuring.html#configuring-uppercase-and-lowercase-rules>`_ for information on changing the default case.
@ -239,10 +239,10 @@ Refer to the section `Configuring Uppercase and Lowercase Rules <configuring.htm
.. code-block:: vhdl
port (
WR_EN : in std_logic;
RD_EN : in std_logic;
OVERFLOW : out std_logic;
UNDERFLOW : out std_logic
wr_en : in std_logic;
rd_en : in std_logic;
overflow : out std_logic;
underflow : out std_logic
);
port_011

View File

@ -82,6 +82,7 @@ The command line tool can be invoked with:
| --backup | Creates a copy of the input file before |
| | applying any fixes. This can be used to |
| | compare the fixed file against the original. |
| | NOTE: This is only valid when using --fix. |
+-------------------------------+-------------------------------------------------+
| --output_configuration | Writes a JSON configuration file of the current |
| | run. It includes a file_list, local_rules (if |

View File

@ -3,7 +3,6 @@
import sys
import os
import json
import shutil
import glob
import yaml
import functools
@ -21,11 +20,6 @@ from . import version
from . import vhdlFile
def create_backup_file(sFileName):
'''Copies existing file and adds .bak to the end.'''
shutil.copy2(sFileName, sFileName + '.bak')
def generate_output_configuration(commandLineArguments, oConfig):
'''
Creates a configuration based on parameters passed on the command line.

View File

@ -1,9 +1,17 @@
import shutil
from . import config
from . import rule_list
from . import utils
from . import vhdlFile
def create_backup_file(sFileName):
'''Copies existing file and adds .bak to the end.'''
shutil.copy2(sFileName, sFileName + '.bak')
def configure_rules(oConfig, oRules, configuration, iIndex, sFileName):
oRules.configure(oConfig)

View File

@ -58,6 +58,8 @@ def parse_command_line_arguments():
args_ = parser.parse_args()
validate_backup_argument(args_)
if sys.platform == "win32":
# Work around https://bugs.python.org/issue26903
args_.jobs = min(args_.jobs, 60)
@ -87,4 +89,11 @@ def get_predefined_styles():
lReturn.append(tempConfiguration['name'])
return lReturn
def validate_backup_argument(args_):
'''
The function validates the backup option is only present when the fix option is also present.
'''
if args_.backup and not args_.fix:
print('ERROR: --backup argument requires --fix argument')
sys.exit(1)

View File

@ -1,8 +1,10 @@
import filecmp
import pathlib
import unittest
from unittest import mock
import subprocess
import os
import subprocess
import shutil
import sys
import contextlib
@ -368,3 +370,58 @@ class testVsg(unittest.TestCase):
pass
mock_stdout.write.assert_has_calls(lExpected)
@mock.patch('sys.stdout')
def test_backup_file(self, mock_stdout):
if os.path.isfile('vsg/tests/vsg/deleteme.vhd'):
os.remove('vsg/tests/vsg/deleteme.vhd')
if os.path.isfile('vsg/tests/vsg/deleteme.vhd.bak'):
os.remove('vsg/tests/vsg/deleteme.vhd.bak')
shutil.copyfile('vsg/tests/vsg/entity1.vhd', 'vsg/tests/vsg/deleteme.vhd')
lExpected = []
sys.argv = ['vsg']
sys.argv.extend(['--output_format', 'syntastic'])
sys.argv.extend(['-f', 'vsg/tests/vsg/deleteme.vhd'])
sys.argv.extend(['--fix'])
sys.argv.extend(['--backup'])
try:
__main__.main()
except SystemExit:
pass
self.assertTrue(os.path.isfile('vsg/tests/vsg/deleteme.vhd.bak'))
self.assertTrue(filecmp.cmp('vsg/tests/vsg/entity1.vhd', 'vsg/tests/vsg/deleteme.vhd.bak'))
mock_stdout.write.assert_has_calls(lExpected)
if os.path.isfile('vsg/tests/vsg/deleteme.vhd'):
os.remove('vsg/tests/vsg/deleteme.vhd')
if os.path.isfile('vsg/tests/vsg/deleteme.vhd.bak'):
os.remove('vsg/tests/vsg/deleteme.vhd.bak')
@mock.patch('sys.stdout')
def test_backup_file_without_fix(self, mock_stdout):
lExpected = []
lExpected.append(mock.call('ERROR: --backup argument requires --fix argument'))
lExpected.append(mock.call('\n'))
sys.argv = ['vsg']
sys.argv.extend(['--output_format', 'syntastic'])
sys.argv.extend(['-f', 'vsg/tests/vsg/entity1.vhd'])
sys.argv.extend(['--backup'])
with self.assertRaises(SystemExit) as cm:
__main__.main()
mock_stdout.write.assert_has_calls(lExpected)
self.assertEqual(cm.exception.code, 1)
self.assertFalse(os.path.isfile('vsg/tests/vsg/entity1.vhd.bak'))