Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
- No changes yet.
- [#273][]: Archive mode: supports same capabilities as "package" mode, including:
erroring out on type constraints and handling type aliases explicitly

[#273]: https://github.com/uber-go/mock/pull/273

## 0.6.0 (18 Aug 2025)
### Added
Expand Down
26 changes: 7 additions & 19 deletions mockgen/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"golang.org/x/tools/go/gcexportdata"
)

func archiveMode(importPath string, symbols []string, archive string) (*model.Package, error) {
func parseExportFile(importPath string, symbols []string, archive string) (*model.Package, error) {
f, err := os.Open(archive)
if err != nil {
return nil, err
Expand All @@ -29,27 +29,15 @@ func archiveMode(importPath string, symbols []string, archive string) (*model.Pa
return nil, err
}

interfaces, err := extractInterfacesFromPackageTypes(tp, symbols)
if err != nil {
return nil, err
}

pkg := &model.Package{
Name: tp.Name(),
PkgPath: tp.Path(),
Interfaces: make([]*model.Interface, 0, len(symbols)),
}
for _, name := range symbols {
m := tp.Scope().Lookup(name)
tn, ok := m.(*types.TypeName)
if !ok {
continue
}
ti, ok := tn.Type().Underlying().(*types.Interface)
if !ok {
continue
}
it, err := model.InterfaceFromGoTypesType(ti)
if err != nil {
return nil, err
}
it.Name = m.Name()
pkg.Interfaces = append(pkg.Interfaces, it)
Interfaces: interfaces,
}
return pkg, nil
}
5 changes: 3 additions & 2 deletions mockgen/gob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ func TestGobMode(t *testing.T) {
// Encode a package to a temporary gob.
parser := packageModeParser{}
want, err := parser.parsePackage(
"go.uber.org/mock/mockgen/internal/tests/package_mode" /* package name */,
[]string{ "Human", "Earth" } /* ifaces */,
"go.uber.org/mock/mockgen/internal/tests/package_mode", /* package name */
[]string{"Human", "Earth"}, /* ifaces */
)
require.NoError(t, err)
path := filepath.Join(t.TempDir(), "model.gob")
outfile, err := os.Create(path)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func main() {
checkArgs()
packageName = flag.Arg(0)
interfaces := strings.Split(flag.Arg(1), ",")
pkg, err = archiveMode(packageName, interfaces, *archive)
pkg, err = parseExportFile(packageName, interfaces, *archive)

default: // package mode
checkArgs()
Expand Down
160 changes: 0 additions & 160 deletions mockgen/model/model_gotypes.go

This file was deleted.

Loading