Skip to content

Commit 7a7ad60

Browse files
JFMartenJakob Marten
andauthored
issue-1469: warning for no matches of file_rules (#1470)
Co-authored-by: Jakob Marten <github@jfmarten.de>
1 parent c786afb commit 7a7ad60

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
rule:
3+
entity_008:
4+
disable : True
5+
entity_012:
6+
disable : True
7+
port_010:
8+
disable : True
9+
architecture_011:
10+
disable : True
11+
architecture_013:
12+
disable : True
13+
architecture_014:
14+
disable : True
15+
file_rules:
16+
- tests/**/entity1.vhd :
17+
rule:
18+
port_007:
19+
disable : True
20+
- tests/**/*2.vhd :
21+
rule:
22+
port_008:
23+
disable : True
24+
- tests/**/nomatch.vhd :
25+
rule:
26+
port_008:
27+
disable : True
28+
...

tests/vsg/test_vsg.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,33 @@ def test_configuration_with_globbing_in_file_rules(self):
580580

581581
self.assertEqual(lActual, lExpected)
582582

583+
def test_configuration_with_globbing_in_file_rules_and_no_match(self):
584+
lExpected = ["WARNING: Could not find file tests/**/nomatch.vhd in configuration file tests/vsg/config_file_rules_w_globbing_no_match.yaml"]
585+
586+
lActual = []
587+
588+
try:
589+
lActual = (
590+
subprocess.check_output(
591+
[
592+
*utils.vsg_exec(),
593+
"--configuration",
594+
"tests/vsg/config_file_rules_w_globbing_no_match.yaml",
595+
"-f",
596+
"tests/vsg/*.vhd",
597+
"--output_format",
598+
"syntastic",
599+
],
600+
)
601+
.decode("utf-8")
602+
.splitlines()
603+
)
604+
except subprocess.CalledProcessError as e:
605+
lActual = str(e.output.decode("utf-8")).splitlines()
606+
iExitStatus = e.returncode
607+
608+
self.assertEqual(lActual, lExpected)
609+
583610
def test_file_as_stdin(self):
584611
with open("tests/vsg/entity1.vhd") as file1:
585612
lExpected = []

vsg/config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,19 @@ def open_configuration_file(sFileName, sJUnitFileName=None):
4848
sys.exit(1)
4949

5050

51-
def validate_file_exists(sFilename, sConfigName):
51+
def validate_file_exists(sFilename, sConfigName, errorWhenEmpty):
5252
"""Validates a file exist while using the glob function to expand filenames."""
5353
if isinstance(sFilename, dict):
5454
sExpandedFilename = list(sFilename.keys())[0]
5555
else:
5656
sExpandedFilename = sFilename
5757
lFileNames = glob_filenames(sExpandedFilename)
5858
if len(lFileNames) == 0:
59-
print("ERROR: Could not find file " + sExpandedFilename + " in configuration file " + sConfigName)
60-
sys.exit(1)
59+
if errorWhenEmpty:
60+
print("ERROR: Could not find file " + sExpandedFilename + " in configuration file " + sConfigName)
61+
sys.exit(1)
62+
else:
63+
print("WARNING: Could not find file " + sExpandedFilename + " in configuration file " + sConfigName)
6164

6265

6366
def read_configuration_files(dStyle, commandLineArguments):
@@ -137,7 +140,7 @@ def process_file_list_key(dConfig, tempConfiguration, sKey, sConfigFilename):
137140
if sKey not in dConfig:
138141
dReturn[sKey] = []
139142
for iIndex, sFilename in enumerate(tempConfiguration[sKey]):
140-
validate_file_exists(sFilename, sConfigFilename)
143+
validate_file_exists(sFilename, sConfigFilename, sKey == "file_list")
141144
try:
142145
for sGlobbedFilename in glob_filenames_clean(sFilename):
143146
dReturn[sKey].append(sGlobbedFilename)

0 commit comments

Comments
 (0)