Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
lvyahui8 committed Jun 15, 2024
1 parent c8a59d1 commit ecfcca0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ellyn_agent/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/lvyahui8/ellyn/ellyn_agent

go 1.18
go 1.19

replace github.com/lvyahui8/ellyn => ./..

Expand Down
5 changes: 5 additions & 0 deletions ellyn_ast/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Processor interface {
FilterPackage(progCtx *ProgramContext, pkg Package) bool
FilterFile(progCtx *ProgramContext, pkg Package, file fs.FileInfo) bool
HandleFile(progCtx *ProgramContext, pkg Package, file fs.FileInfo, content []byte)
HandleFunc(progCtx *ProgramContext, pkg Package, file fs.FileInfo, goFunc *GoFunc)
}

type DefaultProcessor struct {
Expand Down Expand Up @@ -40,3 +41,7 @@ func (d DefaultProcessor) FilterFile(progCtx *ProgramContext, pkg Package, file
func (d DefaultProcessor) HandleFile(progCtx *ProgramContext, pkg Package, file fs.FileInfo, content []byte) {
log.Infof("dir %s,file %s", pkg.Dir, file.Name())
}

func (d DefaultProcessor) HandleFunc(progCtx *ProgramContext, pkg Package, file fs.FileInfo, goFunc *GoFunc) {

}
19 changes: 17 additions & 2 deletions ellyn_ast/visitor_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package ellyn_ast

import "testing"
import (
"github.com/lvyahui8/ellyn/ellyn_testing"
"github.com/stretchr/testify/require"
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"testing"
)

func TestFileVisitor_Visit(t *testing.T) {

fileName := ellyn_testing.GetTestProjPath() + "/main.go"
content, err := ioutil.ReadFile(fileName)
require.Nil(t, err)
visitor := &FileVisitor{content: content}
fset := token.NewFileSet()
visitor.fset = fset
parsedFile, err := parser.ParseFile(fset, fileName, content, parser.ParseComments)
ast.Walk(visitor, parsedFile)
}
2 changes: 1 addition & 1 deletion example/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module example

go 1.18
go 1.19
7 changes: 7 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ func Trade() {
}()

go Handle()

c := make(chan string, 100)
c <- "hello"
select {
case msg := <-c:
_ = fmt.Sprintf("say: %v", msg)
}
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/lvyahui8/ellyn

go 1.18
go 1.19

require (
github.com/stretchr/testify v1.8.4
Expand Down

0 comments on commit ecfcca0

Please sign in to comment.