Skip to content

Commit

Permalink
add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
Strum355 committed Feb 12, 2024
1 parent b6d22b4 commit 010a2c1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/go-mockgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func mainErr() error {
stdlibRoot = packageOpts.StdlibRoot

importpath := packageOpts.ImportPaths[0]
importpathToSourcefiles[importpath] = append(importpathToSourcefiles[importpath], packageOpts.SourceFiles...)
if len(packageOpts.SourceFiles) > 0 {
importpathToSourcefiles[importpath] = append(importpathToSourcefiles[importpath], packageOpts.SourceFiles...)
}

for _, archive := range packageOpts.Archives {
a, err := parseArchive(archive)
Expand Down
Binary file removed input.a
Binary file not shown.
2 changes: 2 additions & 0 deletions internal/integration-gcexportdata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mock_test.go
*.a
5 changes: 5 additions & 0 deletions internal/integration-gcexportdata/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package integrationgcexportdata

//go:generate go build -o sampletext.a .
//go:generate go build -o require.a ../../testutil/require
//go:generate go run ../../cmd/go-mockgen
16 changes: 16 additions & 0 deletions internal/integration-gcexportdata/mockgen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
force: true
disable-formatting: true
mocks:
- filename: mock_test.go
package: integrationgcexportdata
interfaces:
- Banana
path: github.com/derision-test/go-mockgen/internal/integration-gcexportdata
source-files:
- sampletext.go
archives:
# need to include sources for this as its a direct dependency
# (a package from which we're generating mocks)
- github.com/derision-test/go-mockgen/internal/integration-gcexportdata=sampletext.a
# don't need to include sources for this, as its an indirect dependency
- github.com/derision-test/go-mockgen/testutil/require=require.a
7 changes: 7 additions & 0 deletions internal/integration-gcexportdata/sampletext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package integrationgcexportdata

import mockrequire "github.com/derision-test/go-mockgen/testutil/require"

type Banana interface {
DoSomething() mockrequire.CallInstanceAsserter
}
2 changes: 1 addition & 1 deletion internal/mockgen/generation/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func generateDirectory(ifaces []*types.Interface, opts *Options) error {
}

filename := fmt.Sprintf("%s%s%s.go", prefix, iface.Name, suffix)
return path.Join(opts.OutputOptions.OutputDir, strings.Replace(strings.ToLower(filename), "-", "_", -1))
return path.Join(opts.OutputOptions.OutputDir, strings.ReplaceAll(strings.ToLower(filename), "-", "_"))
}

if !opts.OutputOptions.Force {
Expand Down

0 comments on commit 010a2c1

Please sign in to comment.