github.com/EagleQL/Xray-core@v1.4.3/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 "github.com/xtls/xray-core/common/uuid" 11 ) 12 13 func BuildXray() 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", "github.com/xtls/xray-core/...", "-c", "-o", testBinaryPath, GetSourcePath()) 20 return cmd.Run() 21 } 22 23 func RunXrayProtobuf(config []byte) *exec.Cmd { 24 genTestBinaryPath() 25 26 covDir := os.Getenv("XRAY_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 }