server_env_coverage.go 769 B

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