Skip to content

Commit

Permalink
Merge branch 'master' into lsp-client
Browse files Browse the repository at this point in the history
  • Loading branch information
hezyin committed Feb 20, 2019
2 parents 19c1b76 + 03c3fd5 commit 0a0880c
Show file tree
Hide file tree
Showing 22 changed files with 429 additions and 22 deletions.
2 changes: 1 addition & 1 deletion persper/analytics/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_graph(self):
r = requests.get(graph_url)
graph_data = r.json()
graph_data['directed'] = True
graph_data['multigraph'] = True
graph_data['multigraph'] = False
return CallCommitGraph(graph_data)

def reset_graph(self):
Expand Down
31 changes: 31 additions & 0 deletions test/go_test_repo/D/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main
import(
"fmt"
"math"
)
type a func()

type Vertex struct {
X, Y float64
}

func (v Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
func (v *Vertex) Absp() float64{
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}

func funcA () {
fmt.Println("func A is called!")
}

func main() {
a := funcA
a()
v := Vertex{3, 4}
fmt.Println(v.Abs())
p := &Vertex{4,5}
fmt.Println(p.Absp())
}

2 changes: 1 addition & 1 deletion test/go_test_repo/cg.dot
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
digraph go_test_repo {
A -> B -> C;
A -> B -> C -> D;
}
5 changes: 5 additions & 0 deletions test/go_test_repo_1/A/calcproj/src/simplemath/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package sm

func Add(a int, b int) int {
return a + b
}
11 changes: 11 additions & 0 deletions test/go_test_repo_1/A/calcproj/src/simplemath/add_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sm

import "testing"

func TestAdd1(t *testing.T) {
r := Add(1, 2)

if r != 3 {
t.Errorf("Add(1, 2) failed. Got %d, expected 3.", r)
}
}
8 changes: 8 additions & 0 deletions test/go_test_repo_1/A/calcproj/src/simplemath/sqrt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package sm

import "math"

func Sqrt(i int) int {
v := math.Sqrt(float64(i))
return int(v)
}
11 changes: 11 additions & 0 deletions test/go_test_repo_1/A/calcproj/src/simplemath/sqrt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sm

import "testing"

func TestSqrt1(t *testing.T) {
v := Sqrt(16)

if v != 4 {
t.Errorf("Sqrt(16) failed. Got %v, expected 4.", v)
}
}
53 changes: 53 additions & 0 deletions test/go_test_repo_1/B/calcproj/src/calc/calc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import ("os"
"fmt"
"strconv"
"gitlab.com/meri.co/test/calcproj/src/simplemath")

var Usage = func() {
fmt.Println("USAGE: calc command [arguments] ...")
fmt.Println("\nThe commands are:\n\tadd\tAddition of two values.\n\tsqrt\tSquare root of a non-negative value.")
}

func main() {
args := os.Args
if args == nil || len(args) < 2 {
Usage()
return
}

switch args[1] {
case "add":
if len(args) != 4 {
fmt.Println("USAGE: calc add <integer1> <integer2>")
return
}

v1, err1 := strconv.Atoi(args[2])
v2, err2 := strconv.Atoi(args[3])
if err1 != nil || err2 != nil {
fmt.Println("USAGE: calc add <integer1> <integer2>")
return
}

ret := sm.Add(v1, v2)
fmt.Println("Result: ", ret)
case "sqrt":
if len(args) != 3 {
fmt.Println("USAGE: calc sqrt <integer>")
return
}

v, err := strconv.Atoi(args[2])
if err != nil {
fmt.Println("USAGE: calc sqrt <integer>")
return
}

ret := sm.Sqrt(v)
fmt.Println("Result: ", ret)
default:
Usage()
}
}
5 changes: 5 additions & 0 deletions test/go_test_repo_1/B/calcproj/src/simplemath/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package sm

func Add(a int, b int) int {
return a + b
}
11 changes: 11 additions & 0 deletions test/go_test_repo_1/B/calcproj/src/simplemath/add_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sm

import "testing"

func TestAdd1(t *testing.T) {
r := Add(1, 2)

if r != 3 {
t.Errorf("Add(1, 2) failed. Got %d, expected 3.", r)
}
}
8 changes: 8 additions & 0 deletions test/go_test_repo_1/B/calcproj/src/simplemath/sqrt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package sm

import "math"

func Sqrt(i int) int {
v := math.Sqrt(float64(i))
return int(v)
}
11 changes: 11 additions & 0 deletions test/go_test_repo_1/B/calcproj/src/simplemath/sqrt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sm

import "testing"

func TestSqrt1(t *testing.T) {
v := Sqrt(16)

if v != 4 {
t.Errorf("Sqrt(16) failed. Got %v, expected 4.", v)
}
}
3 changes: 3 additions & 0 deletions test/go_test_repo_1/cg.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
digraph go_test_repo {
A -> B ;
}
30 changes: 30 additions & 0 deletions test/go_test_repo_2/A/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main
import(
"fmt"
)
//This test code is used for test interface function call
type animal interface {
printInfo()
}

type cat int
type dog int

func (c cat) printInfo(){
fmt.Println("a cat")
}

func (d dog) printInfo(){
fmt.Println("a dog")
}

func main() {
var a animal
var c cat
a=c
a.printInfo()
//other type
var d dog
a=d
a.printInfo()
}
28 changes: 28 additions & 0 deletions test/go_test_repo_2/B/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main
import(
"fmt"
)
//This test code is used for test interface function call
type animal interface {
printInfo()
}

type cat int
type dog int
func (c cat) printInfo(){
fmt.Println("a cat")
}

func (c dog) printInfo(){
fmt.Println("a dog")
}
func invoke(a animal){
a.printInfo()
}
func main() {
var c cat
var d dog
//as value convert
invoke(c)
invoke(d)
}
3 changes: 3 additions & 0 deletions test/go_test_repo_2/cg.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
digraph go_test_repo {
A -> B ;
}
11 changes: 8 additions & 3 deletions test/test_analytics/test_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pytest
import subprocess
import shutil
from persper.analytics.c import CGraphServer
from persper.analytics.analyzer import Analyzer
from persper.analytics.graph_server import C_FILENAME_REGEXES
Expand All @@ -13,9 +14,13 @@ def az():
repo_path = os.path.join(root_path, 'repos/test_feature_branch')
script_path = os.path.join(root_path, 'tools/repo_creater/create_repo.py')
test_src_path = os.path.join(root_path, 'test/test_feature_branch')
if not os.path.isdir(repo_path):
cmd = '{} {}'.format(script_path, test_src_path)
subprocess.call(cmd, shell=True)

# Always use latest source to create test repo
if os.path.exists(repo_path):
shutil.rmtree(repo_path)

cmd = '{} {}'.format(script_path, test_src_path)
subprocess.call(cmd, shell=True)

return Analyzer(repo_path, CGraphServer(C_FILENAME_REGEXES))

Expand Down
22 changes: 18 additions & 4 deletions test/test_analytics/test_analyzer_go.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import time
import pytest
import shutil
import subprocess
from persper.analytics.graph_server import GO_FILENAME_REGEXES
from persper.analytics.go import GoGraphServer
Expand All @@ -25,9 +26,12 @@ def az():
test_src_path = os.path.join(root_path, 'test/go_test_repo')
server_addr = 'http://localhost:%d' % server_port

if not os.path.isdir(repo_path):
cmd = '{} {}'.format(script_path, test_src_path)
subprocess.call(cmd, shell=True)
# Always use latest source to create test repo
if os.path.exists(repo_path):
shutil.rmtree(repo_path)

cmd = '{} {}'.format(script_path, test_src_path)
subprocess.call(cmd, shell=True)

return Analyzer(repo_path, GoGraphServer(server_addr, GO_FILENAME_REGEXES))

Expand All @@ -38,6 +42,10 @@ def test_analzyer_go(az):
ccgraph = az.get_graph()

history_truth = {
'D': {'Abs': 6,
'funcA': 0,
'main': 8,
"Absp": 3},
'C': {'Abs': 5,
'funcA': 0,
'funcB': 1,
Expand Down Expand Up @@ -78,5 +86,11 @@ def test_analzyer_go(az):
('funcB', 'funcA')
])

all_edges = edges_added_by_A.union(edges_added_by_B).union(edges_added_by_C)
edges_added_by_D = set([
("Absp", "Sqrt"),
("main", "Absp")
])

print(set(az._graph_server.get_graph().edges()))
all_edges = edges_added_by_A.union(edges_added_by_B).union(edges_added_by_C).union(edges_added_by_D)
assert(set(az._graph_server.get_graph().edges()) == all_edges)
Loading

0 comments on commit 0a0880c

Please sign in to comment.