Coverage for tests/unit/GHDL.py: 97%

59 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-12 01:00 +0000

1# ==================================================================================================================== # 

2# _____ ____ _ _ ____ _ ___ _____ _ # 

3# _ __ _ _| ____| _ \ / \ / \ / ___| | |_ _|_ _|__ ___ | | # 

4# | '_ \| | | | _| | | | |/ _ \ / _ \ | | | | | | | |/ _ \ / _ \| | # 

5# | |_) | |_| | |___| |_| / ___ \ / ___ \ | |___| |___ | | | | (_) | (_) | | # 

6# | .__/ \__, |_____|____/_/ \_\/_/ \_(_)____|_____|___| |_|\___/ \___/|_| # 

7# |_| |___/ # 

8# ==================================================================================================================== # 

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

13# ==================================================================================================================== # 

14# Copyright 2017-2023 Patrick Lehmann - Boetzingen, Germany # 

15# # 

16# Licensed under the Apache License, Version 2.0 (the "License"); # 

17# you may not use this file except in compliance with the License. # 

18# You may obtain a copy of the License at # 

19# # 

20# http://www.apache.org/licenses/LICENSE-2.0 # 

21# # 

22# Unless required by applicable law or agreed to in writing, software # 

23# distributed under the License is distributed on an "AS IS" BASIS, # 

24# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

25# See the License for the specific language governing permissions and # 

26# limitations under the License. # 

27# # 

28# SPDX-License-Identifier: Apache-2.0 # 

29# ==================================================================================================================== # 

30# 

31"""Unit tests for executable ``ghdl``.""" 

32from sys import platform as sys_platform 

33from os import getenv as os_getenv 

34from pathlib import Path 

35from unittest import TestCase 

36 

37from pyEDAA.CLITool.GHDL import GHDL 

38from . import Helper 

39 

40 

41class CommonOptions(TestCase, Helper): 

42 _binaryDirectoryPath = Path(os_getenv("GHDL_PREFIX", default="/usr/local")) / "bin" 

43 

44 @classmethod 

45 def setUpClass(cls) -> None: 

46 print(f"\nPlatform: {sys_platform}") 

47 if sys_platform in ("linux", "darwin"): 47 ↛ exitline 47 didn't return from function 'setUpClass', because the condition on line 47 was never false

48 ghdlBinaryPath: Path = cls._binaryDirectoryPath / "ghdl" 

49 print(f"Creating dummy file '{ghdlBinaryPath}': ", end="") 

50 ghdlBinaryPath.touch() 

51 print(f"DONE" if ghdlBinaryPath.exists() else f"FAILED") 

52 

53 def test_Help(self): 

54 tool = GHDL(binaryDirectoryPath=self._binaryDirectoryPath) 

55 tool[tool.CommandHelp] = True 

56 

57 executable = self.getExecutablePath("ghdl", self._binaryDirectoryPath) 

58 self.assertEqual(f"[\"{executable}\", \"help\"]", repr(tool)) 

59 

60 def test_Version(self): 

61 tool = GHDL(binaryDirectoryPath=self._binaryDirectoryPath) 

62 tool[tool.CommandVersion] = True 

63 

64 executable = self.getExecutablePath("ghdl", self._binaryDirectoryPath) 

65 self.assertEqual(f"[\"{executable}\", \"version\"]", repr(tool)) 

66 

67 

68class Analyze(TestCase, Helper): 

69 _binaryDirectoryPath = Path(os_getenv("GHDL_PREFIX", default="/usr/local")) / "bin" 

70 

71 @classmethod 

72 def setUpClass(cls) -> None: 

73 print(f"\nPlatform: {sys_platform}") 

74 if sys_platform in ("linux", "darwin"): 74 ↛ exitline 74 didn't return from function 'setUpClass', because the condition on line 74 was never false

75 ghdlBinaryPath: Path = cls._binaryDirectoryPath / "ghdl" 

76 print(f"Creating dummy file '{ghdlBinaryPath}': ", end="") 

77 ghdlBinaryPath.touch() 

78 print(f"DONE" if ghdlBinaryPath.exists() else f"FAILED") 

79 

80 def test_AnalyzeFile(self): 

81 tool = GHDL(binaryDirectoryPath=self._binaryDirectoryPath) 

82 tool[tool.CommandAnalyze] = True 

83 tool[tool.FlagVHDLStandard] = "08" 

84 tool[tool.FlagSynopsys] = True 

85 tool[tool.FlagRelaxed] = True 

86 tool[tool.FlagExplicit] = True 

87 tool[tool.FlagMultiByteComments] = True 

88 tool[tool.FlagLibrary] = "lib_Test" 

89 

90 executable = self.getExecutablePath("ghdl", self._binaryDirectoryPath) 

91 self.assertEqual(f"[\"{executable}\", \"analyze\", \"--std=08\", \"-fsynopsys\", \"-frelaxed\", \"-fexplicit\", \"--work=lib_Test\", \"--mb-comments\"]", repr(tool)) 

92 

93 def test_DeriveAnalyzer(self): 

94 tool = GHDL(binaryDirectoryPath=self._binaryDirectoryPath) 

95 tool[tool.FlagVHDLStandard] = "08" 

96 tool[tool.FlagSynopsys] = True 

97 tool[tool.FlagRelaxed] = True 

98 tool[tool.FlagExplicit] = True 

99 tool[tool.FlagMultiByteComments] = True 

100 

101 derived = tool.GetGHDLAsAnalyzer() 

102 derived[derived.FlagLibrary] = "lib_Test" 

103 

104 executable = self.getExecutablePath("ghdl", self._binaryDirectoryPath) 

105 self.assertEqual(f"[\"{executable}\", \"analyze\", \"--std=08\", \"-fsynopsys\", \"-frelaxed\", \"-fexplicit\", \"--work=lib_Test\", \"--mb-comments\"]", repr(derived))