client/tests/client.go

46 lines
776 B
Go
Raw Permalink Normal View History

package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"apigo.cc/gojs"
"apigo.cc/gojs/client"
"github.com/ssgo/u"
)
func main() {
gojs.ExportForDev()
testOK := false
client.Bind("setTestOK", func(testIsOK bool) {
testOK = testIsOK
})
scriptFile := "client.js"
if len(os.Args) > 1 {
scriptFile = os.Args[1]
}
exePath, _ := os.Executable()
appDir := ""
if strings.Contains(exePath, "Contents/MacOS") {
appDir = filepath.Join(filepath.Dir(filepath.Dir(exePath)), "Resources")
os.Chdir(appDir)
}
u.WriteFile("/tmp/aaa.txt", appDir)
r, err := gojs.RunFile(scriptFile)
if err != nil {
fmt.Println(u.Red(err.Error()))
}
gojs.WaitAll()
if !testOK {
fmt.Println(u.BRed("test failed"))
} else {
fmt.Println(u.BGreen("test OK"), r)
}
}