Skip to content

Simple support for mutation testing

This MR adds a few features related to mutation.

On the CLI side, two new sub-commands are present:

  • mutate-cst : mutates a file and prints the resulting mutated file, it works at the CST level.
  • mutate-ast : mutates a file and prints the resulting mutated file, it works at the AST (imperative) level.

Also, on the testing framework a few primitives are added. The first two

  • Test.mutate_count : ligo_program -> nat: given a LIGO program, it counts the number of possible mutations.
  • Test.mutate_expression : nat -> ligo_program -> ligo_program: given an index (on the possible mutations) and a LIGO program, it returns the mutated program.

These work at the CST level.

The other three

  • Test.mutate_value : nat -> 'a -> ('a * mutation) option: given an index (on the possible mutations) and a value, it returns an option signaling if the mutation was available (with resulting mutated value and mutation) or not.
  • Test.mutation_test : 'a -> ('a -> 'b) -> ('b * mutation) option: given a value to mutate (first argument), it will try all the mutations of it, passing each one to the function (second argument). On the first case of non failure when running the function on a mutation, the value and mutation involved will be returned.
  • Test.mutation_test_all : 'a -> ('a -> 'b) -> ('b * mutation) list: given a value to mutate (first argument), it will try all the mutations of it, passing each one to the function (second argument). In case no failure arises when running the function on a mutation, the failure and mutation involved will be added to the list to be returned.

These work at the AST (typed) level. These are specially recommended to mutate functions, e.g. a contract.

  • has a changelog entry
Edited by Suzanne Soy

Merge request reports

Loading