Is it possible to post coverage for multiple packages to Coveralls?

前端 未结 6 655
故里飘歌
故里飘歌 2021-02-04 10:02

I want to track test coverage on a go project using Coveralls, the instructions for the integration reference using https://github.com/mattn/goveralls

cd $GOPA         


        
6条回答
  •  醉酒成梦
    2021-02-04 10:42

    Taking Usman's answer, and altering it to support skipping Godep and other irrelevant folders:

    echo "mode: set" > acc.out
    for Dir in $(go list ./...); 
    do
        returnval=`go test -coverprofile=profile.out $Dir`
        echo ${returnval}
        if [[ ${returnval} != *FAIL* ]]
        then
            if [ -f profile.out ]
            then
                cat profile.out | grep -v "mode: set" >> acc.out 
            fi
        else
            exit 1
        fi  
    
    done
    if [ -n "$COVERALLS_TOKEN" ]
    then
        goveralls -coverprofile=acc.out -repotoken=$COVERALLS_TOKEN -service=travis-pro
    fi  
    
    rm -rf ./profile.out
    rm -rf ./acc.out
    

    Notice that instead of looking at every directory, I us the go list ./... command which lists all directories that actually get used to build the go package.

    Hope that helps others.

    ** EDIT **

    If you are using the vendor folder for Go v.1.6+ then this script filters out the dependencies:

    echo "mode: set" > acc.out
    for Dir in $(go list ./...); 
    do
        if [[ ${Dir} != *"/vendor/"* ]]
        then
            returnval=`go test -coverprofile=profile.out $Dir`
            echo ${returnval}
            if [[ ${returnval} != *FAIL* ]]
            then
                if [ -f profile.out ]
                then
                    cat profile.out | grep -v "mode: set" >> acc.out 
                fi
            else
                exit 1
            fi
        else
            exit 1
        fi  
    
    done
    if [ -n "$COVERALLS_TOKEN" ]
    then
        goveralls -coverprofile=acc.out -repotoken=$COVERALLS_TOKEN -service=travis-pro
    fi  
    

提交回复
热议问题