mutate

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package mutate makes the mutants of a source file (spec 09.6). It is the generic mutator prog mutate: it reads the text of the file with the comment and string syntax of the language, and it uses the same six operators for every language, so that the scores of two languages can be compared.

Index

Constants

View Source
const (
	Relational = "relational"
	Arithmetic = "arithmetic"
	Constant   = "constant"
	Negate     = "negate"
	Delete     = "delete"
	Swap       = "swap"
)

The operators of spec 09.6.

View Source
const IgnoreFile = "mutants.ignore"

IgnoreFile is the name of the list of equivalent mutants in impl/<lang>/ (spec 09.6).

View Source
const MaxIgnored = 0.05

MaxIgnored is the largest part of the mutants of an implementation that mutants.ignore can list (rule S08).

View Source
const MaxPerFile = 150

MaxPerFile is the largest number of mutants of one file in a pull request run (spec 09.6).

View Source
const Seed = 9

Seed is the fixed seed of the sample, so that the score stays the same from run to run.

Variables

View Source
var Languages = map[string]Syntax{
	"python":     {Exts: []string{".py"}, Hash: true, Empty: "pass", Floor: true},
	"go":         {Exts: []string{".go"}},
	"rust":       {Exts: []string{".rs"}, Lifetimes: true},
	"c":          {Exts: []string{".c", ".h"}, Empty: ";", Parens: true},
	"cpp":        {Exts: []string{".cpp", ".cc", ".hpp", ".h"}, Empty: ";", Parens: true},
	"javascript": {Exts: []string{".js", ".mjs"}, Empty: ";", Parens: true},
	"typescript": {Exts: []string{".ts"}, Empty: ";", Parens: true},
	"java":       {Exts: []string{".java"}, Empty: ";", Parens: true},
	"kotlin":     {Exts: []string{".kt"}, Empty: "Unit", Parens: true},
	"csharp":     {Exts: []string{".cs"}, Empty: ";", Parens: true},
}

Languages are the languages that the mutator reads.

Operators are the operators, in the order of the report.

Functions

func Source

func Source(lang, name string) bool

Source tells if the file is a source file of the language that the mutator reads.

Types

type Ignore

type Ignore struct {
	ID     string
	Reason string
	Line   int
}

Ignore is one entry of mutants.ignore: the id of an equivalent mutant and the reason why it cannot change the output.

func ParseIgnore

func ParseIgnore(text string) ([]Ignore, error)

ParseIgnore reads mutants.ignore. Each line is the id of a mutant, as the mutation run writes it, then " # " and the reason. A line that starts with # is a comment.

type Mutant

type Mutant struct {
	File  string `json:"file"`
	Line  int    `json:"line"`
	Op    string `json:"op"`
	From  string `json:"from"`
	To    string `json:"to"`
	Start int    `json:"-"`
	End   int    `json:"-"`
}

Mutant is one small change of a file. The bytes from Start to End become To.

func Mutants

func Mutants(lang, name, src string) ([]Mutant, error)

Mutants gives each mutant of the source file name of the language, in the order of the file.

func Sample

func Sample(ms []Mutant, max int) []Mutant

Sample gives at most max of the mutants, chosen with the fixed seed and the file name, in the order of the file. A max of 0 or less gives all.

func (Mutant) Apply

func (m Mutant) Apply(src string) string

Apply gives the source with the mutant.

func (Mutant) ID

func (m Mutant) ID() string

ID names the mutant in a report and in mutants.ignore: the file, the line, the operator and the change.

type Set

type Set struct {
	Mutants []Mutant
	Ignore  map[string]Ignore
	// Stale are the entries of mutants.ignore that name no mutant of the sample.
	Stale []Ignore
}

Set is the sample of mutants of one implementation, with the entries of its mutants.ignore.

func Of

func Of(im node.Impl, max int) (Set, error)

Of makes the sample of mutants of each source file of the implementation (spec 09.6), and reads its mutants.ignore. max is the largest number of mutants of one file; 0 gives all.

func (Set) Ignored

func (s Set) Ignored() int

Ignored counts the mutants of the sample that mutants.ignore lists.

type Syntax

type Syntax struct {
	// Exts are the extensions of the source files.
	Exts []string
	// Hash tells if # starts a comment, as in Python. Otherwise // and /* */ start a comment, and # at the start of a line is a preprocessor line.
	Hash bool
	// Empty is the statement that takes the place of a deleted statement, so that a block or a branch does not become empty.
	Empty string
	// Parens tells if the condition of if and while is in parentheses, as in C. Otherwise it ends at the { (Go, Rust) or the : (Python) at the end of the line.
	Parens bool
	// Lifetimes tells if a single quote can start a lifetime, as in Rust, and not only a character.
	Lifetimes bool
	// Floor tells if // is an operator, as in Python.
	Floor bool
}

Syntax is what the mutator must know of a language.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL