1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

bring back all coverage

This commit is contained in:
v2ray 2016-08-09 00:55:36 +02:00
parent c6ad190f0a
commit 697d44abbd
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
5 changed files with 76 additions and 10 deletions

View File

@ -0,0 +1,11 @@
// +build coveragemain
package main
import (
"testing"
)
func TestRunMainForCoverage(t *testing.T) {
main()
}

View File

@ -7,7 +7,7 @@ function test_package {
DIR="github.com/v2ray/v2ray-core/$1" DIR="github.com/v2ray/v2ray-core/$1"
DEP=$(go list -f '{{ join .Deps "\n" }}' $DIR | grep v2ray | tr '\n' ',') DEP=$(go list -f '{{ join .Deps "\n" }}' $DIR | grep v2ray | tr '\n' ',')
DEP=${DEP}$DIR DEP=${DEP}$DIR
go test -tags json -coverprofile=coversingle.out -coverpkg=$DEP $DIR || FAIL=1 go test -tags "json coverage" -coverprofile=coversingle.out -coverpkg=$DEP $DIR || FAIL=1
if [ -f coversingle.out ]; then if [ -f coversingle.out ]; then
cat coversingle.out | grep -v "mode: set" >> ${COVERAGE_FILE} cat coversingle.out | grep -v "mode: set" >> ${COVERAGE_FILE}
rm coversingle.out rm coversingle.out

View File

@ -28,11 +28,11 @@ var (
binaryPath string binaryPath string
) )
func BuildV2Ray() error { func GetSourcePath() string {
if len(binaryPath) > 0 { return filepath.Join("github.com", "v2ray", "v2ray-core", "shell", "point", "main")
return nil }
}
func FillBinaryPath() error {
dir, err := ioutil.TempDir("", "v2ray") dir, err := ioutil.TempDir("", "v2ray")
if err != nil { if err != nil {
return err return err
@ -41,8 +41,7 @@ func BuildV2Ray() error {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
binaryPath += ".exe" binaryPath += ".exe"
} }
cmd := exec.Command("go", "build", "-tags=json", "-o="+binaryPath, filepath.Join("github.com", "v2ray", "v2ray-core", "shell", "point", "main")) return nil
return cmd.Run()
} }
func TestFile(filename string) string { func TestFile(filename string) string {
@ -73,9 +72,7 @@ func InitializeServer(configFile string) error {
return err return err
} }
proc := exec.Command(binaryPath, "-config="+configFile) proc := RunV2Ray(configFile)
proc.Stderr = os.Stderr
proc.Stdout = os.Stdout
err = proc.Start() err = proc.Start()
if err != nil { if err != nil {

View File

@ -0,0 +1,29 @@
// +build coverage
package scenarios
import (
"os"
"os/exec"
)
func BuildV2Ray() error {
if _, err := os.Stat(binaryPath); err == nil {
return nil
}
if err := FillBinaryPath(); err != nil {
return err
}
cmd := exec.Command("go", "test", "-tags", "json coverage coveragemain", "-coverpkg", "github.com/v2ray/v2ray-core/...", "-c", "-o", binaryPath, GetSourcePath())
return cmd.Run()
}
func RunV2Ray(configFile string) *exec.Cmd {
proc := exec.Command(binaryPath, "-config="+configFile, "-test.run=TestRunMainForCoverage", "-test.coverprofile=coversingle.out")
proc.Stderr = os.Stderr
proc.Stdout = os.Stdout
return proc
}

View File

@ -0,0 +1,29 @@
// +build !coverage
package scenarios
import (
"os"
"os/exec"
)
func BuildV2Ray() error {
if _, err := os.Stat(binaryPath); err == nil {
return nil
}
if err := FillBinaryPath(); err != nil {
return err
}
cmd := exec.Command("go", "build", "-tags=json", "-o="+binaryPath, GetSourcePath())
return cmd.Run()
}
func RunV2Ray(configFile string) *exec.Cmd {
proc := exec.Command(binaryPath, "-config="+configFile)
proc.Stderr = os.Stderr
proc.Stdout = os.Stdout
return proc
}