Skip to content

Commit ae846fb

Browse files
authored
Merge pull request #39 from zimmski/fix-compile-errors
Fix compile errors
2 parents ad16e6a + bd33afb commit ae846fb

File tree

7 files changed

+68
-9
lines changed

7 files changed

+68
-9
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ install-tools:
4343
lint:
4444
$(ROOT_DIR)/scripts/lint.sh
4545
test:
46-
go test -race -test.timeout 60s $(PKG_TEST)
46+
go test -race -test.timeout 120s $(PKG_TEST)
4747
test-verbose:
48-
go test -race -test.timeout 60s -v $(PKG_TEST)
48+
go test -race -test.timeout 120s -v $(PKG_TEST)
4949
test-with-coverage:
5050
ginkgo -r -cover -race -skipPackage="testdata"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Every mutation has to be tested using an [exec command](#write-mutation-exec-com
9292
- Execute all tests of the package of the mutated file.
9393
- Report if the mutation was killed.
9494

95-
Alternatively the `--exec` argument can be used to invoke an external exec command. The [/scripts/exec](/scripts/exec) directory holds basic exec commands for Go projects. The [test-mutated-package.sh](/scripts/exec/test-mutated-package.sh) script implements all steps of the built-in exec command. It can be for example used to test the [github.com/zimmski/go-mutesting/example](/example) package.
95+
Alternatively the `--exec` argument can be used to invoke an external exec command. The [/scripts/exec](/scripts/exec) directory holds basic exec commands for Go projects. The [test-mutated-package.sh](/scripts/exec/test-mutated-package.sh) script implements all steps and almost all features of the built-in exec command. It can be for example used to test the [github.com/zimmski/go-mutesting/example](/example) package.
9696

9797
```bash
9898
go-mutesting --exec "$GOPATH/src/github.com/zimmski/go-mutesting/scripts/exec/test-mutated-package.sh" github.com/zimmski/go-mutesting/example

astutil/query.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,39 @@ type identifierWalker struct {
1717
identifiers []ast.Expr
1818
}
1919

20+
var blacklistedIdentifiers = map[string]bool{
21+
"_": true,
22+
"append": true,
23+
"close": true,
24+
"go": true,
25+
"func": true,
26+
"len": true,
27+
"nil": true,
28+
}
29+
30+
func checkForSelectorExpr(node ast.Expr) bool {
31+
switch n := node.(type) {
32+
case *ast.Ident:
33+
return true
34+
case *ast.SelectorExpr:
35+
return checkForSelectorExpr(n.X)
36+
}
37+
38+
return false
39+
}
40+
2041
func (w *identifierWalker) Visit(node ast.Node) ast.Visitor {
2142
switch n := node.(type) {
2243
case *ast.Ident:
23-
w.identifiers = append(w.identifiers, n)
44+
if _, ok := blacklistedIdentifiers[n.Name]; !ok {
45+
w.identifiers = append(w.identifiers, n)
46+
}
2447

2548
return nil
2649
case *ast.SelectorExpr:
27-
w.identifiers = append(w.identifiers, n)
50+
if checkForSelectorExpr(n) {
51+
w.identifiers = append(w.identifiers, n)
52+
}
2853

2954
return nil
3055
}

cmd/go-mutesting/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,12 @@ MUTATOR:
300300
}
301301

302302
func mutate(opts *options, mutators []mutatorItem, mutationBlackList map[string]struct{}, mutationID int, file string, fset *token.FileSet, src ast.Node, node ast.Node, tmpFile string, execs []string, stats *mutationStats) int {
303-
pkg, err := build.ImportDir(filepath.Dir(file), build.FindOnly)
303+
dir, err := filepath.Abs(filepath.Dir(file))
304+
if err != nil {
305+
panic(err)
306+
}
307+
308+
pkg, err := build.ImportDir(dir, build.FindOnly)
304309
if err != nil {
305310
panic(err)
306311
}

cmd/go-mutesting/main_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@ import (
1010
)
1111

1212
func TestMain(t *testing.T) {
13+
testMain(
14+
t,
15+
"../../example",
16+
[]string{"--debug", "--exec-timeout", "1"},
17+
returnOk,
18+
"The mutation score is 0.500000 (7 passed, 7 failed, 0 skipped, total is 14)",
19+
)
20+
}
21+
22+
func TestMainRecursive(t *testing.T) {
1323
testMain(
1424
t,
1525
"../../example",
1626
[]string{"--debug", "--exec-timeout", "1", "./..."},
1727
returnOk,
18-
"The mutation score is 0.538462 (7 passed, 6 failed, 1 skipped, total is 14)",
28+
"The mutation score is 0.533333 (8 passed, 7 failed, 0 skipped, total is 15)",
1929
)
2030
}
2131

@@ -25,7 +35,7 @@ func TestMainFromOtherDirectory(t *testing.T) {
2535
"../..",
2636
[]string{"--debug", "--exec-timeout", "1", "github.com/zimmski/go-mutesting/example"},
2737
returnOk,
28-
"The mutation score is 0.538462 (7 passed, 6 failed, 1 skipped, total is 14)",
38+
"The mutation score is 0.500000 (7 passed, 7 failed, 0 skipped, total is 14)",
2939
)
3040
}
3141

@@ -35,7 +45,7 @@ func TestMainMatch(t *testing.T) {
3545
"../../example",
3646
[]string{"--debug", "--exec", "../scripts/exec/test-mutated-package.sh", "--exec-timeout", "1", "--match", "baz", "./..."},
3747
returnOk,
38-
"The mutation score is 0.000000 (0 passed, 1 failed, 0 skipped, total is 1)",
48+
"The mutation score is 0.500000 (1 passed, 1 failed, 0 skipped, total is 2)",
3949
)
4050
}
4151

example/sub/sub.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package sub
2+
3+
func baz() int {
4+
i := 1
5+
i = i + i
6+
7+
return i
8+
}

example/sub/sub_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package sub
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestBaz(t *testing.T) {
10+
Equal(t, baz(), 2)
11+
}

0 commit comments

Comments
 (0)