Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Davide Petilli <[email protected]>
  • Loading branch information
k3rn31 committed Jun 26, 2022
1 parent ddbe99e commit 8b4a8d5
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macOS-latest ]
os: [ ubuntu-latest, macOS-latest ]
steps:
- uses: actions/checkout@v3
- name: Set up Go
Expand Down
3 changes: 3 additions & 0 deletions cmd/unleash.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ var UnleashCmd = &cobra.Command{
path = args[0]
}
tmpdir, _ := ioutil.TempDir(os.TempDir(), "unleash-")
defer func(name string) {
_ = os.Remove(name)
}(tmpdir)
cov, err := coverage.New(tmpdir, path)
if err != nil {
fmt.Printf("directory %s does not contain main module\n", path)
Expand Down
25 changes: 25 additions & 0 deletions coverage/coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ func TestCoverageParsesOutput(t *testing.T) {
}
}

func TestCoverageNew(t *testing.T) {
t.Run("does not return error if it can retrieve module", func(t *testing.T) {
t.Parallel()
path := t.TempDir()
goMod := path + "/go.mod"
err := os.WriteFile(goMod, []byte("module example.com"), 0600)
if err != nil {
t.Fatal(err)
}

_, err = coverage.New(t.TempDir(), path)
if err != nil {
t.Fatal(err)
}
})

t.Run("returns error if it cannot find module", func(t *testing.T) {
t.Parallel()
_, err := coverage.New(t.TempDir(), t.TempDir())
if err == nil {
t.Fatal(err)
}
})
}

func TestParseOutputFail(t *testing.T) {
t.Parallel()
cov := coverage.NewWithCmdAndPackage(fakeExecCommandSuccess(nil), "example.com", "testdata/invalid", "./...")
Expand Down
2 changes: 1 addition & 1 deletion mutator/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (mt MutantType) String() string {
case ConditionalBoundary:
return "Conditional Boundary"
default:
return ""
panic("this should not happen")
}
}

Expand Down
44 changes: 44 additions & 0 deletions mutator/mappings_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2022 The Gremlins Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package mutator

import (
"github.com/google/go-cmp/cmp"
"testing"
)

func TestMutantTypeString(t *testing.T) {
testCases := []struct {
name string
mutantType MutantType
expected string
}{
{
"Conditional Boundary",
ConditionalBoundary,
"Conditional Boundary",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
if tc.mutantType.String() != tc.expected {
t.Errorf(cmp.Diff(tc.mutantType.String(), tc.expected))
}
})
}
}
38 changes: 38 additions & 0 deletions mutator/mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package mutator_test

import (
"github.com/google/go-cmp/cmp"
"github.com/k3rn31/gremlins/coverage"
"github.com/k3rn31/gremlins/mutator"
"go/token"
Expand Down Expand Up @@ -155,3 +156,40 @@ func TestSkipTestAndNonGoFiles(t *testing.T) {
t.Errorf("should not receive results")
}
}

func TestMutationStatusString(t *testing.T) {
testCases := []struct {
name string
mutationStatus mutator.MutationStatus
expected string
}{
{
"NotCovered",
mutator.NotCovered,
"NOT COVERED",
},
{
"Runnable",
mutator.Runnable,
"RUNNABLE",
},
{
"Lived",
mutator.Lived,
"LIVED",
},
{
"Killed",
mutator.Killed,
"KILLED",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
if tc.mutationStatus.String() != tc.expected {
t.Errorf(cmp.Diff(tc.mutationStatus.String(), tc.expected))
}
})
}
}

0 comments on commit 8b4a8d5

Please sign in to comment.