Skip to content

Commit

Permalink
Merge pull request #77 from luoliwoshang/gogensig/testskip
Browse files Browse the repository at this point in the history
gogensig:skip headerfile gen test
  • Loading branch information
luoliwoshang authored Oct 14, 2024
2 parents 13afd3e + ae42f53 commit f754570
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
7 changes: 6 additions & 1 deletion chore/gogensig/cmptest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
cppgtypes "github.com/goplus/llgo/chore/llcppg/types"
)

func RunTest(t *testing.T, pkgName string, isCpp bool, symbolEntries []config.SymbolEntry, cppgConf *cppgtypes.Config, originalCode, expectedOutput string) {
// The validateFunc is used to validate the generated file,
func RunTest(t *testing.T, pkgName string, isCpp bool, symbolEntries []config.SymbolEntry, cppgConf *cppgtypes.Config, originalCode, expectedOutput string, validateFunc func(t *testing.T, pkg *convert.Package)) {
t.Helper()

tempDir, err := os.MkdirTemp("", "gogensig-test")
Expand Down Expand Up @@ -81,6 +82,10 @@ func RunTest(t *testing.T, pkgName string, isCpp bool, symbolEntries []config.Sy
if strings.TrimSpace(expectedOutput) != strings.TrimSpace(string(content)) {
t.Errorf("does not match expected.\nExpected:\n%s\nGot:\n%s", expectedOutput, string(content))
}

if validateFunc != nil {
validateFunc(t, astConvert.GetPackage())
}
}

func CreateAndWriteTempSymbFile(entries []config.SymbolEntry) (string, error) {
Expand Down
3 changes: 2 additions & 1 deletion chore/gogensig/config/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"os/exec"
"strings"

"github.com/goplus/llgo/chore/gogensig/unmarshal"
cppgtypes "github.com/goplus/llgo/chore/llcppg/types"
Expand Down Expand Up @@ -53,7 +54,7 @@ func Sigfetch(file string, isTemp bool, isCPP bool) ([]byte, error) {

err := cmd.Run()
if err != nil {
return nil, fmt.Errorf("error running llcppsigfetch: %v\nStderr: %s", err, stderr.String())
return nil, fmt.Errorf("error running llcppsigfetch: %v\nStderr: %s\nArgs: %s", err, stderr.String(), strings.Join(args, " "))
}

return out.Bytes(), nil
Expand Down
4 changes: 4 additions & 0 deletions chore/gogensig/convert/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (p *BuiltinTypeMap) FindTypeAlias(name string) (types.Type, error) {
return nil, fmt.Errorf("%s", "not found in type alias map")
}

func (p *BuiltinTypeMap) GetTypeAliases() map[string]typeAliasInfo {
return p.typeAliases

Check warning on line 70 in chore/gogensig/convert/builtin.go

View check run for this annotation

Codecov / codecov/patch

chore/gogensig/convert/builtin.go#L69-L70

Added lines #L69 - L70 were not covered by tests
}

func (p *BuiltinTypeMap) initBuiltinTypeMap() {
// todo(zzy): int128/uint128 half(float16),long double,float 128
p.builtinTypeMap = map[ast.BuiltinType]types.Type{
Expand Down
4 changes: 4 additions & 0 deletions chore/gogensig/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (p *AstConvert) SetVisitDone(fn func(pkg *Package, docPath string)) {
p.visitDone = fn

Check warning on line 42 in chore/gogensig/convert/convert.go

View check run for this annotation

Codecov / codecov/patch

chore/gogensig/convert/convert.go#L41-L42

Added lines #L41 - L42 were not covered by tests
}

func (p *AstConvert) GetPackage() *Package {
return p.pkg

Check warning on line 46 in chore/gogensig/convert/convert.go

View check run for this annotation

Codecov / codecov/patch

chore/gogensig/convert/convert.go#L45-L46

Added lines #L45 - L46 were not covered by tests
}

func (p *AstConvert) setupSymbolTableFile(filePath string) error {
symbTable, err := config.NewSymbolTable(filePath)
if err != nil {
Expand Down
67 changes: 63 additions & 4 deletions chore/gogensig/convert/convert_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions chore/gogensig/convert/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (p *Package) SetCurFile(file string, isHeaderFile bool) error {
var fileName string
if isHeaderFile {
// headerfile to go filename
fileName = p.processHeaderFileName(file)
fileName = HeaderFileToGo(file)
} else {
// package name as the default file
fileName = file + ".go"
Expand Down Expand Up @@ -108,6 +108,14 @@ func (p *Package) GetGenPackage() *gogen.Package {
return p.p
}

func (p *Package) GetOutputDir() string {
return p.outputDir

Check warning on line 112 in chore/gogensig/convert/package.go

View check run for this annotation

Codecov / codecov/patch

chore/gogensig/convert/package.go#L111-L112

Added lines #L111 - L112 were not covered by tests
}

func (p *Package) GetTypeCvt() *TypeConv {
return p.cvt

Check warning on line 116 in chore/gogensig/convert/package.go

View check run for this annotation

Codecov / codecov/patch

chore/gogensig/convert/package.go#L115-L116

Added lines #L115 - L116 were not covered by tests
}

func (p *Package) Name() string {
return p.name
}
Expand Down Expand Up @@ -226,7 +234,7 @@ func (p *Package) Write(headerFile string) error {
return nil

Check warning on line 234 in chore/gogensig/convert/package.go

View check run for this annotation

Codecov / codecov/patch

chore/gogensig/convert/package.go#L234

Added line #L234 was not covered by tests
}

fileName := p.processHeaderFileName(headerFile)
fileName := HeaderFileToGo(headerFile)

if debug {
log.Printf("Write HeaderFile [%s] from gogen:[%s] to [%s]\n", headerFile, fileName, filepath.Join(p.outputDir, fileName))
Expand All @@ -242,7 +250,7 @@ func (p *Package) Write(headerFile string) error {
// WriteToBuffer writes the Go file to a buffer.
// Include the aliased file for debug
func (p *Package) WriteToBuffer(headerFile string) (*bytes.Buffer, error) {
goFileName := p.processHeaderFileName(headerFile)
goFileName := HeaderFileToGo(headerFile)
buf := new(bytes.Buffer)
err := p.p.WriteTo(buf, goFileName)
if err != nil {
Expand Down Expand Up @@ -271,7 +279,7 @@ func (p *Package) prepareOutputDir(outputDir string) (string, error) {

// /path/to/foo.h
// foo.go
func (p *Package) processHeaderFileName(headerFile string) string {
func HeaderFileToGo(headerFile string) string {
_, fileName := filepath.Split(headerFile)
ext := filepath.Ext(fileName)
if len(ext) > 0 {
Expand Down

0 comments on commit f754570

Please sign in to comment.