github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/testing/scenarios/common_coverage.go (about)

     1  // +build coverage
     2  
     3  package scenarios
     4  
     5  import (
     6  	"bytes"
     7  	"os"
     8  	"os/exec"
     9  
    10  	"v2ray.com/core/common/uuid"
    11  )
    12  
    13  func BuildV2Ray() error {
    14  	genTestBinaryPath()
    15  	if _, err := os.Stat(testBinaryPath); err == nil {
    16  		return nil
    17  	}
    18  
    19  	cmd := exec.Command("go", "test", "-tags", "coverage coveragemain", "-coverpkg", "v2ray.com/core/...", "-c", "-o", testBinaryPath, GetSourcePath())
    20  	return cmd.Run()
    21  }
    22  
    23  func RunV2RayProtobuf(config []byte) *exec.Cmd {
    24  	genTestBinaryPath()
    25  
    26  	covDir := os.Getenv("V2RAY_COV")
    27  	os.MkdirAll(covDir, os.ModeDir)
    28  	randomID := uuid.New()
    29  	profile := randomID.String() + ".out"
    30  	proc := exec.Command(testBinaryPath, "-config=stdin:", "-format=pb", "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
    31  	proc.Stdin = bytes.NewBuffer(config)
    32  	proc.Stderr = os.Stderr
    33  	proc.Stdout = os.Stdout
    34  
    35  	return proc
    36  }