common_coverage.go 901 B

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