crytic_compile.utils.unit_tests
Module handling unit-tests features
1""" 2Module handling unit-tests features 3""" 4import json 5from pathlib import Path 6from typing import List 7 8 9def guess_tests(target: str) -> List[str]: 10 """Try to guess the unit tests commands 11 12 Args: 13 target (str): path to the target 14 15 Returns: 16 List[str]: List of guessed unit tests commands 17 """ 18 targets: List[str] = [] 19 20 readme_path = Path(target, "README.md") 21 if readme_path.is_file(): 22 with open(readme_path, encoding="utf8") as readme_f: 23 readme = readme_f.read() 24 if "yarn test" in readme: 25 targets += ["yarn test"] 26 27 package_path = Path(target, "package.json") 28 if package_path.is_file(): 29 with open(package_path, encoding="utf8") as package_f: 30 package = json.load(package_f) 31 if "scripts" in package: 32 if "test" in package["scripts"]: 33 targets += package["scripts"]["test"] 34 35 return targets
def
guess_tests(target: str) -> List[str]:
10def guess_tests(target: str) -> List[str]: 11 """Try to guess the unit tests commands 12 13 Args: 14 target (str): path to the target 15 16 Returns: 17 List[str]: List of guessed unit tests commands 18 """ 19 targets: List[str] = [] 20 21 readme_path = Path(target, "README.md") 22 if readme_path.is_file(): 23 with open(readme_path, encoding="utf8") as readme_f: 24 readme = readme_f.read() 25 if "yarn test" in readme: 26 targets += ["yarn test"] 27 28 package_path = Path(target, "package.json") 29 if package_path.is_file(): 30 with open(package_path, encoding="utf8") as package_f: 31 package = json.load(package_f) 32 if "scripts" in package: 33 if "test" in package["scripts"]: 34 targets += package["scripts"]["test"] 35 36 return targets
Try to guess the unit tests commands
Args: target (str): path to the target
Returns: List[str]: List of guessed unit tests commands