llcppsymg:config & clangutil test

llcppsymg:clangutil test
This commit is contained in:
luoliwoshang
2024-09-26 11:12:23 +08:00
parent 944133de6e
commit ca0492d997
4 changed files with 229 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
package main
import (
"fmt"
"strings"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/config"
)
func main() {
TestGetConf()
}
func TestGetConf() {
testCases := []struct {
name string
input string
}{
{
name: "SQLite configuration",
input: `{
"name": "sqlite",
"cflags": "-I/opt/homebrew/opt/sqlite/include",
"include": ["sqlite3.h"],
"libs": "-L/opt/homebrew/opt/sqlite/lib -lsqlite3",
"trimPrefixes": ["sqlite3_"],
"cplusplus": false
}`,
},
{
name: "Lua configuration",
input: `{
"name": "lua",
"cflags": "-I/opt/homebrew/include/lua",
"include": ["lua.h"],
"libs": "-L/opt/homebrew/lib -llua -lm",
"trimPrefixes": ["lua_", "lua_"],
"cplusplus": false
}`,
},
{
name: "Invalid JSON",
input: `{invalid json}`,
},
}
for _, tc := range testCases {
fmt.Printf("=== Test case: %s ===\n", tc.name)
result, err := config.GetConf([]byte(tc.input))
if err != nil {
fmt.Println("Error:", err.Error())
} else {
fmt.Println("Name:", result.Config.Name)
fmt.Println("CFlags:", result.Config.CFlags)
fmt.Println("Libs:", result.Config.Libs)
fmt.Println("Include:", strings.Join(result.Config.Include, ", "))
fmt.Println("TrimPrefixes:", strings.Join(result.Config.TrimPrefixes, ", "))
fmt.Println("Cplusplus:", result.Config.Cplusplus)
}
fmt.Println()
}
}

View File

@@ -0,0 +1,24 @@
#stdout
=== Test case: SQLite configuration ===
Name: sqlite
CFlags: -I/opt/homebrew/opt/sqlite/include
Libs: -L/opt/homebrew/opt/sqlite/lib -lsqlite3
Include: sqlite3.h
TrimPrefixes: sqlite3_
Cplusplus: false
=== Test case: Lua configuration ===
Name: lua
CFlags: -I/opt/homebrew/include/lua
Libs: -L/opt/homebrew/lib -llua -lm
Include: lua.h
TrimPrefixes: lua_, lua_
Cplusplus: false
=== Test case: Invalid JSON ===
Error: failed to parse config
#stderr
#exit 0