Skip to content

Commit

Permalink
lua: test conda
Browse files Browse the repository at this point in the history
  • Loading branch information
moqsien committed Feb 3, 2025
1 parent 9e6f5b5 commit bad37e7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
3 changes: 0 additions & 3 deletions internal/luapi/lua_global/cs.go

This file was deleted.

54 changes: 54 additions & 0 deletions internal/luapi/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
var goPluginPath = "/Users/moqsien/projects/lua/vmr_plugins/go.lua"
var minicondaPluginPath = "/Users/moqsien/projects/lua/vmr_plugins/miniconda.lua"
var coursierPluginPath = "/Users/moqsien/projects/lua/vmr_plugins/coursier.lua"
var luaPluginPath = "/Users/moqsien/projects/lua/vmr_plugins/lua.lua"

func TestGoPlugin(t *testing.T) {
fmt.Println("aaa")
Expand Down Expand Up @@ -183,3 +184,56 @@ func TestCoursierPlugin(t *testing.T) {
}
fmt.Println(ic.FlagFiles)
}

func TestLuaPlugin(t *testing.T) {
fmt.Println("aaa")

ll := lua_global.NewLua()
defer ll.L.Close()
if err := ll.L.DoFile(luaPluginPath); err != nil {
t.Error(err)
}

L := ll.GetLState()

if pre := GetConfItemFromLua(L, Prequisite); pre != "conda" {
t.Errorf("prequisite should be 'conda', but got '%s'", pre)
}

f := L.GetGlobal("crawl")
if f == nil || f.Type() != lua.LTFunction {
t.Error("crawl function should be defined")
}

if err := L.CallByParam(lua.P{
Fn: f,
NRet: 1,
Protect: true,
}); err != nil {
t.Error(err)
}

r := L.Get(-1)

ud, ok := r.(*lua.LUserData)
if !ok {
t.Error("return value should be userdata")
}

if vl, ok := ud.Value.(lua_global.VersionList); !ok {
t.Error("userdata value should be VersionList")
} else {
// keys := []string{}
// for k := range vl {
// keys = append(keys, k)
// }
// fmt.Println(keys)
fmt.Println(vl["5.4.6"])
}

ic := lua_global.GetInstallerConfig(L)
if ic == nil {
t.Error("installer config should be defined")
}
fmt.Println(ic.BinaryDirs)
}

0 comments on commit bad37e7

Please sign in to comment.