Skip to content

Commit

Permalink
Merge pull request #1104 from BradSwain/mutator-fixes
Browse files Browse the repository at this point in the history
Small slither-mutate fixes
  • Loading branch information
montyly authored Mar 14, 2022
2 parents e3392dd + e193a50 commit 7ec1aa8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions slither/tools/mutator/mutators/MIA.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from slither.core.cfg.node import NodeType
from slither.formatters.utils.patches import create_patch
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature, FaulClass
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature, FaultClass


class MIA(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "MIA"
HELP = '"if" construct around statement'
FAULTCLASS = FaulClass.Checking
FAULTCLASS = FaultClass.Checking
FAULTNATURE = FaultNature.Missing

def _mutate(self):
Expand Down
6 changes: 3 additions & 3 deletions slither/tools/mutator/mutators/MVIE.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from slither.core.expressions import Literal
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature, FaulClass
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature, FaultClass
from slither.tools.mutator.utils.generic_patching import remove_assignement


class MVIE(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "MVIV"
NAME = "MVIE"
HELP = "variable initialization using an expression"
FAULTCLASS = FaulClass.Assignement
FAULTCLASS = FaultClass.Assignement
FAULTNATURE = FaultNature.Missing

def _mutate(self):
Expand Down
4 changes: 2 additions & 2 deletions slither/tools/mutator/mutators/MVIV.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from slither.core.expressions import Literal
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature, FaulClass
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature, FaultClass
from slither.tools.mutator.utils.generic_patching import remove_assignement


class MVIV(AbstractMutator): # pylint: disable=too-few-public-methods
NAME = "MVIV"
HELP = "variable initialization using a value"
FAULTCLASS = FaulClass.Assignement
FAULTCLASS = FaultClass.Assignement
FAULTNATURE = FaultNature.Missing

def _mutate(self):
Expand Down
10 changes: 7 additions & 3 deletions slither/tools/mutator/mutators/abstract_mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IncorrectMutatorInitialization(Exception):
pass


class FaulClass(Enum):
class FaultClass(Enum):
Assignement = 0
Checking = 1
Interface = 2
Expand All @@ -31,7 +31,7 @@ class FaultNature(Enum):
class AbstractMutator(metaclass=abc.ABCMeta): # pylint: disable=too-few-public-methods
NAME = ""
HELP = ""
FAULTCLASS = FaulClass.Undefined
FAULTCLASS = FaultClass.Undefined
FAULTNATURE = FaultNature.Undefined

def __init__(self, slither: Slither, rate: int = 10, seed: Optional[int] = None):
Expand All @@ -49,7 +49,7 @@ def __init__(self, slither: Slither, rate: int = 10, seed: Optional[int] = None)
f"HELP is not initialized {self.__class__.__name__}"
)

if self.FAULTCLASS == FaulClass.Undefined:
if self.FAULTCLASS == FaultClass.Undefined:
raise IncorrectMutatorInitialization(
f"FAULTCLASS is not initialized {self.__class__.__name__}"
)
Expand All @@ -72,6 +72,10 @@ def _mutate(self) -> Dict:
def mutate(self) -> None:
all_patches = self._mutate()

if "patches" not in all_patches:
logger.debug(f"No patches found by {self.NAME}")
return

for file in all_patches["patches"]:
original_txt = self.slither.source_code[file].encode("utf8")
patched_txt = original_txt
Expand Down

0 comments on commit 7ec1aa8

Please sign in to comment.