github.com/xraypb/xray-core@v1.6.6/testing/scenarios/common_coverage.go (about)

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