Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mutation test script improvements #2436

Merged
merged 6 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/mutest-issue-generate.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Generate Mutation Test Errors
name: Generate Mutation Test Errors

on:
schedule:
Expand All @@ -14,23 +14,23 @@ jobs:
-
name: Run mutation test
continue-on-error: true
run: make test-mutation
run: make test-mutation MODULES=tokenfactory
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
-
name: Execute mutation test format script
id: mutest-formatted
run: |
cat mutation_test_result.txt | grep -Ev "PASS" | grep -Ev "SKIP" | tee mutation_test_result.txt
-
name: Generate code blocks
name: Generate code blocks
id: gen-code-blocks
run: |
cat mutation_test_result.txt | sed "s# @@# @@\n\`\`\`go\n#g " | sed "s#FAIL#\`\`\`\nFAIL\n\n\n#g " > mutation_test_result.txt
-
name: Get today's date
id: date
run: |
echo "::set-output name=today::$(date "+%Y/%m/%d")"
-
echo "::set-output name=today::$(date "+%Y/%m/%d")"
-
name: Read mutation_test_result file
id: result
uses: juliangruber/read-file-action@v1
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ test-e2e-skip-upgrade:
@VERSION=$(VERSION) OSMOSIS_E2E_SKIP_UPGRADE=True go test -tags e2e -mod=readonly -timeout=25m -v $(PACKAGES_E2E)

test-mutation:
@bash scripts/mutation-test.sh
@bash scripts/mutation-test.sh $(MODULES)

benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_UNIT)
Expand Down
25 changes: 20 additions & 5 deletions scripts/mutation-test.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
#!/usr/bin/env bash

set -eo pipefail
oIFS="$IFS"; IFS=, ; set -- $1 ; IFS="$oIFS"
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved

DISABLED_MUTATORS='branch/*'

# Only consider the following:
# * go files in types or keeper packages
# * go files in types, keeper, or module root directories
# * ignore test and Protobuf files
MUTATION_SOURCES=$(find ./x -type f \( -path '*/keeper/*' -or -path '*/types/*' \) \( -name '*.go' -and -not -name '*_test.go' -and -not -name '*pb*' \))
MUTATION_SOURCES+=$(find ./x -maxdepth 2 -type f \( -name '*.go' -and -not -name '*_test.go' -and -not -name '*pb*' \))

# XXX: Filter on a module-by-module basis and expand when we think other modules
# are ready. Once all modules are considered stable enough to be tested, remove
# this filter entirely.
MUTATION_SOURCES=$(echo "$MUTATION_SOURCES" | grep './x/tokenfactory')
# Filter on a module-by-module basis as provided by input
arg_len=$#

for i in "$@"; do
if [ $arg_len -gt 1 ]; then
MODULE_FORMAT+="./x/$i\|"
MODULE_NAMES+="${i} "
let "arg_len--"
else
MODULE_FORMAT+="./x/$i"
MODULE_NAMES+="${i}"
fi
done

MUTATION_SOURCES=$(echo "$MUTATION_SOURCES" | grep "$MODULE_FORMAT")

# Collect multiple lines into a single line to be fed into go-mutesting
MUTATION_SOURCES=$(echo $MUTATION_SOURCES | tr '\n' ' ')

echo "running mutation tests for the following module(s): $MODULE_NAMES"
OUTPUT=$(go run github.com/osmosis-labs/go-mutesting/cmd/go-mutesting --disable=$DISABLED_MUTATORS $MUTATION_SOURCES)

# Fetch the final result output and the overall mutation testing score
Expand All @@ -26,6 +40,7 @@ SCORE=$(echo "$RESULT" | grep -Eo '[[:digit:]]\.[[:digit:]]+')
echo "writing mutation test result to mutation_test_result.txt"
echo "$OUTPUT" > mutation_test_result.txt

# Print the mutation score breakdown
echo $RESULT

# Return a non-zero exit code if the score is below 75%
Expand Down