Skip to content

Commit

Permalink
create code coverage github+codecov (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin8105 authored May 30, 2024
1 parent f335d91 commit 5ad1ae5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 58 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/go.yml → .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Go

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
on: [push, pull_request]

jobs:

Expand All @@ -16,7 +12,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.3
go-version: 1.19.12

- name: Clang
run: |
Expand Down Expand Up @@ -49,14 +45,13 @@ jobs:
- name: Coverage
run: |
go get -u github.com/wadey/gocovmerge
go get -u github.com/Konstantin8105/cs
go install github.com/ory/go-acc@latest
go get -u golang.org/x/sys/unix
go test -run=TestIntegrationScripts/tests/ctype.c -coverprofile=coverage.txt -covermode=atomic
# TRAVIS=true ./scripts/test.sh
TRAVIS=true ./scripts/test.sh
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_ORG_TOKEN }}
verbose: true # optional (default = false)
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.txt
#verbose: true # optional (default = false)
61 changes: 28 additions & 33 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,38 @@

set -e

echo "" > coverage.txt

# Initialize
mkdir -p ./testdata/

# Package list
export PKGS=$(go list ./... | grep -v c4go/testdata | grep -v c4go/examples | grep -v c4go/tests | grep -v /vendor/ | tr '\n' ' ')
# github.com/Konstantin8105/c4go
# github.com/Konstantin8105/c4go/ast
# github.com/Konstantin8105/c4go/examples // ignore
# github.com/Konstantin8105/c4go/noarch
# github.com/Konstantin8105/c4go/preprocessor
# github.com/Konstantin8105/c4go/program
# github.com/Konstantin8105/c4go/scripts
# github.com/Konstantin8105/c4go/testdata // ignore
# github.com/Konstantin8105/c4go/tests // ignore
# github.com/Konstantin8105/c4go/transpiler
# github.com/Konstantin8105/c4go/types
# github.com/Konstantin8105/c4go/util
# github.com/Konstantin8105/c4go/version

# Make comma-separated.
export PKGS_DELIM=$(echo "$PKGS" | tr ' ' ',')
# Package list
export PKGS=$(go list -e ./... | grep -v testdata | grep -v examples | grep -v tests | grep -v vendor | tr '\n' ' ')
# export PKGS="github.com/Konstantin8105/c4go github.com/Konstantin8105/c4go/util"

# View
echo "PKGS : $PKGS"
echo "PKGS_DELIM : $PKGS_DELIM"

go test \
-cover \
-timeout=30m \
-coverpkg=$PKGS_DELIM \
-coverprofile=./testdata/pkg.coverprofile $PKGS

# Merge coverage profiles.
COVERAGE_FILES=`ls -1 ./testdata/*.coverprofile 2>/dev/null | wc -l`
if [ $COVERAGE_FILES != 0 ]; then
# check program `gocovmerge` is exist
if which gocovmerge >/dev/null 2>&1; then
export FILES=$(ls testdata/*.coverprofile | tr '\n' ' ')
echo "Combine next coverprofiles : $FILES"
gocovmerge $FILES > coverage.txt
fi
fi

# echo "" > coverage.out
# for d in $(go list ./... | grep -v vendor); do
# go test -v -race -coverprofile=profile.out -covermode=atomic $d
# if [ -f profile.out ]; then
# cat profile.out >> coverage.out
# rm profile.out
# fi
# done

# Initialize
touch ./coverage.tmp

# Run tests
echo 'mode: atomic' > coverage.txt
# go list -e ./... | grep -v testdata | grep -v examples | grep -v tests | grep -v vendor | grep -v cmd | xargs -n100 -I{} sh -c 'go test -covermode=atomic -coverprofile=coverage.tmp -coverpkg $(go list -e ./... | grep -v testdata | grep -v examples | grep -v tests | grep -v vendor | grep -v cmd | tr "\n" ",") {} && tail -n +2 coverage.tmp >> coverage.txt || exit 255' && rm coverage.tmp

echo "$PKGS" | xargs -n100 -I{} sh -c 'go test -covermode=atomic -coverprofile=coverage.tmp -coverpkg $(echo "$PKGS" | tr " " ",") {} && tail -n +2 coverage.tmp >> coverage.txt || exit 255' && rm coverage.tmp

# Finilize
echo "End of coverage"
8 changes: 4 additions & 4 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ func IsLastArray(s string) bool {
// ParseFunction - parsing elements of C function
func ParseFunction(s string) (prefix string, funcname string, f []string, r []string, err error) {
defer func() {
if len(f) == 1 && f[0] == "void" {
f = nil
}

// fix bug in tests:
// if len(f) == 1 && f[0] == "void" {
// f = nil
// }
if err != nil {
err = fmt.Errorf("cannot parse function '%s' : %v", s, err)
} else {
Expand Down
18 changes: 9 additions & 9 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,19 @@ func TestResolveFunction(t *testing.T) {
if len(actualField) != len(tc.fields) {
a, _ := json.Marshal(actualField)
f, _ := json.Marshal(tc.fields)
t.Errorf("Size of field is not same.\nActual : %s\nExpected: %s\n",
string(a),
string(f))
return
}
if len(actualField) != len(tc.fields) {
a, _ := json.Marshal(actualField)
f, _ := json.Marshal(tc.fields)
t.Errorf("Size of field is not same.\nActual : %s\nExpected: %s\n",
t.Errorf("Size of field is not same.\nActual : `%s`\nExpected: `%s`\n",
string(a),
string(f))
return
}
// if len(actualField) != len(tc.fields) {
// a, _ := json.Marshal(actualField)
// f, _ := json.Marshal(tc.fields)
// t.Errorf("Size of field is not same.\nActual : `%s`\nExpected: `%s`\n",
// string(a),
// string(f))
// return
// }
for i := range actualField {
actualField[i] = strings.Replace(actualField[i], " ", "", -1)
tc.fields[i] = strings.Replace(tc.fields[i], " ", "", -1)
Expand Down

0 comments on commit 5ad1ae5

Please sign in to comment.