### Install go-mutesting Binary Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Install the go-mutesting binary using the 'go install' command. This makes the tool available in your system's PATH. ```bash go install -v github.com/avito-tech/go-mutesting/... ``` -------------------------------- ### Mutation Testing Output Example Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Example output from a mutation testing run, showing which mutations passed (killed by tests) and failed (not killed). Includes diffs for failed mutations. ```diff PASS "/tmp/go-mutesting-422402775//home/avito-tech/go/src/github.com/avito-tech/go-mutesting/example/example.go.0" with checksum b705f4c99e6d572de509609eb0a625be PASS "/tmp/go-mutesting-422402775//home/avito-tech/go/src/github.com/avito-tech/go-mutesting/example/example.go.1" with checksum eb54efffc5edfc7eba2b276371b29836 PASS "/tmp/go-mutesting-422402775//home/avito-tech/go/src/github.com/avito-tech/go-mutesting/example/example.go.2" with checksum 011df9567e5fee9bf75cbe5d5dc1c81f --- --- +++ @@ -16,7 +16,7 @@ } if n < 0 { - n = 0 + } n++ FAIL "/tmp/go-mutesting-422402775//home/avito-tech/go/src/github.com/avito-tech/go-mutesting/example/example.go.3" with checksum 82fc14acf7b561598bfce25bf3a162a2 PASS "/tmp/go-mutesting-422402775//home/avito-tech/go/src/github.com/avito-tech/go-mutesting/example/example.go.4" with checksum 5720f1bf404abea121feb5a50caf672c PASS "/tmp/go-mutesting-422402775//home/avito-tech/go/src/github.com/avito-tech/go-mutesting/example/example.go.5" with checksum d6c1b5e25241453128f9f3bf1b9e7741 --- --- +++ @@ -24,7 +24,6 @@ n += bar() bar() - bar() return n } FAIL "/tmp/go-mutesting-422402775//home/avito-tech/go/src/github.com/avito-tech/go-mutesting/example/example.go.6" with checksum 5b1ca0cfedd786d9df136a0e042df23a PASS "/tmp/go-mutesting-422402775//home/avito-tech/go/src/github.com/avito-tech/go-mutesting/example/example.go.8" with checksum 6928f4458787c7042c8b4505888300a6 The mutation score is 0.750000 (6 passed, 2 failed, 0 skipped, total is 8) ``` -------------------------------- ### Example of skipped make() arguments mutation Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Demonstrates how numeric arguments in make() calls for slices/maps can lead to irrelevant mutations. The filter prevents mutations in these arguments. ```go // Original code slice := make([]int, 0) // Capacity argument (0) was mutated // Mutated versions slice := make([]int, 1) // Incrementer mutation slice := make([]int, -1) // Decrementer mutation ``` -------------------------------- ### Run go-mutesting with Custom Exec Command Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Use the --exec argument to specify an external script for testing mutations. This example uses a provided script to test a specific package. ```bash go-mutesting --exec "$GOPATH/src/github.com/avito-tech/go-mutesting/scripts/exec/test-mutated-package.sh" github.com/avito-tech/go-mutesting/example ``` -------------------------------- ### Example go-mutesting output with a blacklisted mutation Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md This diff output shows the result of running go-mutesting with a blacklisted mutation. Note the change in the number of mutations considered. ```diff PASS "/tmp/go-mutesting-208240643/example.go.0" with checksum b705f4c99e6d572de509609eb0a625be PASS "/tmp/go-mutesting-208240643/example.go.1" with checksum eb54efffc5edfc7eba2b276371b29836 PASS "/tmp/go-mutesting-208240643/example.go.2" with checksum 011df9567e5fee9bf75cbe5d5dc1c81f --- Original +++ New @@ -16,7 +16,7 @@ } if n < 0 { - n = 0 + } n++ FAIL "/tmp/go-mutesting-208240643/example.go.3" with checksum 82fc14acf7b561598bfce25bf3a162a2 PASS "/tmp/go-mutesting-208240643/example.go.4" with checksum 5720f1bf404abea121feb5a50caf672c PASS "/tmp/go-mutesting-208240643/example.go.5" with checksum d6c1b5e25241453128f9f3bf1b9e7741 PASS "/tmp/go-mutesting-208240643/example.go.8" with checksum 6928f4458787c7042c8b4505888300a6 The mutation score is 0.857143 (6 passed, 1 failed, 0 skipped, total is 7) ``` -------------------------------- ### Mutation Example: Boolean logic change Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md This diff shows a mutation where a boolean condition in a loop was simplified. The change was not detected by the test suite, indicating untested code. ```diff for _, d := range opts.Mutator.DisableMutators { pattern := strings.HasSuffix(d, "*") - if (pattern && strings.HasPrefix(name, d[:len(d)-2])) || (!pattern && name == d) { + if (pattern && strings.HasPrefix(name, d[:len(d)-2])) || false { continue MUTATOR } } ``` -------------------------------- ### Mutation Example: Linked list node removal Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md This diff illustrates a mutation in a linked list's remove method where the last node's reference was not properly cleared. This type of mutation can be detected using memory leak tools. ```diff } l.first = nil - l.last = nil + l.len = 0 } ``` -------------------------------- ### Display go-mutesting Help Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md View the help message for the go-mutesting binary to understand available commands and options. It is recommended to check this for a comprehensive list of arguments. ```bash go-mutesting --help ``` -------------------------------- ### Blacklist a specific mutation checksum Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Create a file containing the MD5 checksum of a mutation to mark it as a false positive. This file can then be used with the --blacklist argument. ```text 5b1ca0cfedd786d9df136a0e042df23a ``` -------------------------------- ### Run go-mutesting with Targets Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Execute go-mutesting by providing targets, which can be Go source files, directories, or packages. The '...' wildcard can be used for recursive searching. ```bash go-mutesting parse.go example/ github.com/avito-tech/go-mutesting/mutator/... ``` -------------------------------- ### Run go-mutesting on a project Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Execute go-mutesting on the specified project path. This command will mutate the code and report on which mutations are not covered by tests. ```bash go-mutesting github.com/avito-tech/go-mutesting/... ``` -------------------------------- ### Run go-mutesting with a blacklist file Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Invoke go-mutesting using the --blacklist argument, specifying the path to the file containing checksums of mutations to ignore. ```bash go-mutesting --blacklist example.blacklist github.com/avito-tech/go-mutesting/example ``` -------------------------------- ### Disable mutations for the next line using annotation Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Use `// mutator-disable-next-line` to protect the subsequent line from mutations. Specify `*` to disable all mutators or list specific mutator names. ```go // mutator-disable-next-line * x = 42 // Fully protected from mutations // mutator-disable-next-line branch/if, increment if x > 0 { // Only branch/if and increment mutators are disabled y += 1 } ``` -------------------------------- ### Disable all mutations for a function using annotation Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Use the `// mutator-disable-func` annotation above a function declaration to prevent any mutations within that function. ```go // mutator-disable-func func CalculateDiscount(price float64) float64 { return price * 0.9 } ``` -------------------------------- ### Disable mutations matching a regex pattern using annotation Source: https://github.com/avito-tech/go-mutesting/blob/master/README.md Use `// mutator-disable-regexp` to prevent mutations on lines that match a given regex pattern. Specify `*` for all mutators or list specific mutator names. ```go s := MyStruct{name: "Go"} s.Method() // mutator-disable-regexp s\.Method\(\) * ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.