@@ -8,6 +8,7 @@ package types
88import (
99 "flag"
1010 "os"
11+ "path/filepath"
1112 "runtime"
1213 "strconv"
1314 "strings"
@@ -600,13 +601,29 @@ func VetAndInitializeCLIAndGoConfig(cliConfig CLIConfig, goFlagsConfig GoFlagsCo
600601}
601602
602603// GenerateGoTestCompileArgs is used by the Ginkgo CLI to generate command line arguments to pass to the go test -c command when compiling the test
603- func GenerateGoTestCompileArgs (goFlagsConfig GoFlagsConfig , destination string , packageToBuild string ) ([]string , error ) {
604+ func GenerateGoTestCompileArgs (goFlagsConfig GoFlagsConfig , destination string , packageToBuild string , pathToInvocationPath string ) ([]string , error ) {
604605 // if the user has set the CoverProfile run-time flag make sure to set the build-time cover flag to make sure
605606 // the built test binary can generate a coverprofile
606607 if goFlagsConfig .CoverProfile != "" {
607608 goFlagsConfig .Cover = true
608609 }
609610
611+ if goFlagsConfig .CoverPkg != "" {
612+ coverPkgs := strings .Split (goFlagsConfig .CoverPkg , "," )
613+ adjustedCoverPkgs := make ([]string , len (coverPkgs ))
614+ for i , coverPkg := range coverPkgs {
615+ coverPkg = strings .Trim (coverPkg , " " )
616+ if strings .HasPrefix (coverPkg , "./" ) {
617+ // this is a relative coverPkg - we need to reroot it
618+ adjustedCoverPkgs [i ] = "./" + filepath .Join (pathToInvocationPath , strings .TrimPrefix (coverPkg , "./" ))
619+ } else {
620+ // this is a package name - don't touch it
621+ adjustedCoverPkgs [i ] = coverPkg
622+ }
623+ }
624+ goFlagsConfig .CoverPkg = strings .Join (adjustedCoverPkgs , "," )
625+ }
626+
610627 args := []string {"test" , "-c" , "-o" , destination , packageToBuild }
611628 goArgs , err := GenerateFlagArgs (
612629 GoBuildFlags ,
0 commit comments