Skip to content

Commit

Permalink
Allow HDL files with various case extensions (upper, lower, mixed cas…
Browse files Browse the repository at this point in the history
…e, etc)
  • Loading branch information
joshrsmith authored and kraigher committed Sep 1, 2015
1 parent e3eae14 commit e5d2f1c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
27 changes: 24 additions & 3 deletions vunit/test/acceptance/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from os import remove
import re
from re import MULTILINE
from vunit.ui import VUnit
from vunit.ui import VUnit, VHDL_EXTENSIONS, VERILOG_EXTENSIONS


class TestPreprocessor(object):
Expand Down Expand Up @@ -86,15 +86,15 @@ def _create_ui(self):
ui.add_library('lib')
return ui

def _create_temp_files(self, num_files):
def _create_temp_files(self, num_files, file_suffix='.vhd'):
"""
Create and return num_files temporary files containing the
same source code but with different entity names depending on
the index
"""
files = [None] * num_files
for i in range(num_files):
with NamedTemporaryFile(mode='w', suffix='.vhd', delete=False) as files[i]:
with NamedTemporaryFile(mode='w', suffix=file_suffix, delete=False) as files[i]:
files[i].write(self._source.substitute(entity='foo%d' % i))
return files

Expand Down Expand Up @@ -196,6 +196,27 @@ def test_locally_specified_preprocessors_should_be_used_instead_of_any_globally_

self._delete_temp_files(files)

def test_supported_source_file_suffixes(self):
"""Test adding a supported filetype, of any case, is accepted."""
ui = self._create_ui()
accepted_extensions = VHDL_EXTENSIONS + VERILOG_EXTENSIONS
allowable_extensions = [ext for ext in accepted_extensions]
allowable_extensions.extend([ext.upper() for ext in accepted_extensions])
allowable_extensions.append(VHDL_EXTENSIONS[0][0] + VHDL_EXTENSIONS[0][1].upper() +
VHDL_EXTENSIONS[0][2:]) # mixed case
for ext in allowable_extensions:
files = self._create_temp_files(1, ext)
ui.add_source_files(files[0].name, 'lib')
self._delete_temp_files(files)

def test_unsupported_source_file_suffixes(self):
"""Test adding an unsupported filetype is rejected"""
ui = self._create_ui()
bogus_ext = '.docx' # obviously not an HDL file
files = self._create_temp_files(1, bogus_ext)
self.assertRaises(RuntimeError, ui.add_source_files, files[0].name, 'lib')
self._delete_temp_files(files)


class TestUiEncoding(unittest.TestCase):
"""
Expand Down
8 changes: 6 additions & 2 deletions vunit/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
import logging
LOGGER = logging.getLogger(__name__)

# lower case representation of supported extensions
VHDL_EXTENSIONS = (".vhd", ".vhdl")
VERILOG_EXTENSIONS = (".v", ".vp", ".sv")


class VUnit(object): # pylint: disable=too-many-instance-attributes, too-many-public-methods
"""
Expand Down Expand Up @@ -665,9 +669,9 @@ def file_type_of(file_name):
Return the file type of file_name based on the file ending
"""
_, ext = splitext(file_name)
if ext in (".vhd", ".vhdl"):
if ext.lower() in VHDL_EXTENSIONS:
return "vhdl"
elif ext in (".v", ".vp", ".sv"):
elif ext.lower() in VERILOG_EXTENSIONS:
return "verilog"
else:
raise RuntimeError("Unknown file ending '%s' of %s" % (ext, file_name))
Expand Down

0 comments on commit e5d2f1c

Please sign in to comment.