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 ¶
const ( Relational = "relational" Arithmetic = "arithmetic" Constant = "constant" Negate = "negate" Delete = "delete" Swap = "swap" )
The operators of spec 09.6.
const IgnoreFile = "mutants.ignore"
IgnoreFile is the name of the list of equivalent mutants in impl/<lang>/ (spec 09.6).
const MaxIgnored = 0.05
MaxIgnored is the largest part of the mutants of an implementation that mutants.ignore can list (rule S08).
const MaxPerFile = 150
MaxPerFile is the largest number of mutants of one file in a pull request run (spec 09.6).
const Seed = 9
Seed is the fixed seed of the sample, so that the score stays the same from run to run.
Variables ¶
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.
var Operators = []string{Relational, Arithmetic, Constant, Negate, Delete, Swap}
Operators are the operators, in the order of the report.
Functions ¶
Types ¶
type Ignore ¶
Ignore is one entry of mutants.ignore: the id of an equivalent mutant and the reason why it cannot change the output.
func ParseIgnore ¶
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 ¶
Mutants gives each mutant of the source file name of the language, in the order of the file.
func Sample ¶
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.
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.
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.