server_env_coverage.go 850 B

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