server_env_coverage.go 841 B

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