From b5077b3a0a2f5cb66ece011c85919d3d5b741a8a Mon Sep 17 00:00:00 2001 From: vearne Date: Tue, 12 Nov 2024 19:10:28 +0800 Subject: [PATCH] fix lua print() --- config_files/my_http_api.yml | 3 +++ internal/command/grpc_automate.go | 2 ++ internal/command/http_automate.go | 9 ++++++++- internal/rule/init.go | 16 ---------------- main.go | 2 +- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/config_files/my_http_api.yml b/config_files/my_http_api.yml index 949522b..128a5d7 100644 --- a/config_files/my_http_api.yml +++ b/config_files/my_http_api.yml @@ -53,6 +53,9 @@ function verify(r) local json = require "json"; local book = json.decode(r:body()); + print("book.author:", book.author); + print("---1---", 10); + print("---2---", 20); return book.title == "book3_title" and book.author == "book3_author-2"; end diff --git a/internal/command/grpc_automate.go b/internal/command/grpc_automate.go index 0727c0f..93eadb2 100644 --- a/internal/command/grpc_automate.go +++ b/internal/command/grpc_automate.go @@ -135,6 +135,8 @@ func HandleSingleFileGrpc(workerNum int, filePath string) (*ResultInfo, []GrpcTe } finishCount++ + // process bar will override this line. + fmt.Println() //nolint: errcheck bar.Percent(float64(finishCount) / float64(len(testcases)) * 100) if finishCount >= len(testcases) { diff --git a/internal/command/http_automate.go b/internal/command/http_automate.go index 60af6bd..edf24ce 100644 --- a/internal/command/http_automate.go +++ b/internal/command/http_automate.go @@ -195,7 +195,12 @@ func HandleSingleFileHttp(workerNum int, filePath string) (*ResultInfo, []HttpTe for future := range futureChan { gResult := future.Get() tcResult := gResult.Value.(HttpTestCaseResult) - zaplog.Debug("future.Get", zap.Any("tcResult", tcResult)) + zaplog.Debug("future.Get", + zap.Uint64("ID", tcResult.ID), + zap.String("Desc", tcResult.Desc), + zap.Any("request", tcResult.Request), + zap.Any("response", tcResult.Response), + ) if tcResult.State == model.StateNotExecuted { time.Sleep(200 * time.Millisecond) @@ -230,6 +235,8 @@ func HandleSingleFileHttp(workerNum int, filePath string) (*ResultInfo, []HttpTe } finishCount++ + // process bar will override this line. + fmt.Println() //nolint: errcheck bar.Percent(float64(finishCount) / float64(len(testcases)) * 100) if finishCount >= len(testcases) { diff --git a/internal/rule/init.go b/internal/rule/init.go index 12087e5..842a6dd 100644 --- a/internal/rule/init.go +++ b/internal/rule/init.go @@ -1,10 +1,8 @@ package rule import ( - "fmt" lua "github.com/yuin/gopher-lua" luajson "layeh.com/gopher-json" - "os" "sync" ) @@ -19,22 +17,8 @@ var LuaVMLock sync.Mutex func init() { L = lua.NewState() //defer L.Close() - // 设置自定义的 print 函数 - L.SetGlobal("print", L.NewFunction(customPrint)) // register json lib luajson.Preload(L) registerHttpRespType(L) registerGrocRespType(L) } - -func customPrint(L *lua.LState) int { - top := L.GetTop() - for i := 1; i <= top; i++ { - fmt.Fprint(os.Stdout, L.ToString(i)) // 输出到 os.Stdout - if i != top { - fmt.Fprint(os.Stdout, "\t") - } - } - fmt.Fprintln(os.Stdout) // 换行 - return 0 -} diff --git a/main.go b/main.go index 3fe18d2..4ddbea4 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ import ( ) const ( - version = "v0.1.6" + version = "v0.1.7" ) func main() {