Skip to content

Commit

Permalink
Merge pull request #24 from vearne/fix/lua
Browse files Browse the repository at this point in the history
fix lua print()
  • Loading branch information
vearne authored Nov 12, 2024
2 parents bfea0ee + b5077b3 commit 50d4392
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
3 changes: 3 additions & 0 deletions config_files/my_http_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions internal/command/grpc_automate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion internal/command/http_automate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 0 additions & 16 deletions internal/rule/init.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package rule

import (
"fmt"
lua "github.com/yuin/gopher-lua"
luajson "layeh.com/gopher-json"
"os"
"sync"
)

Expand All @@ -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
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
version = "v0.1.6"
version = "v0.1.7"
)

func main() {
Expand Down

0 comments on commit 50d4392

Please sign in to comment.