Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: uber-go/mock
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.0
Choose a base ref
...
head repository: uber-go/mock
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.6.0
Choose a head ref
  • 16 commits
  • 43 files changed
  • 11 contributors

Commits on Oct 17, 2024

  1. Configuration menu
    Copy the full SHA
    b8222fa View commit details
    Browse the repository at this point in the history

Commits on Oct 28, 2024

  1. Package Mode: Use aliases when used in source (#220)

    v0.5.0 included #207, which replaced reflect mode with package mode. One
    issue with package mode that came up (ref: #216) was that generated
    mocks for interfaces that referred to alias types were referring to the
    aliases' underlying names instead.
    
    e.g.,
    some package:
    ```go
    package somgpkg
    
    import "somepkg/internal/apicodec"
    ...
    type Codec = apicodec.Codec
    ```
    
    mockgen input:
    ```go
    type Foo interface{
    	Bar() somepkg.Codec
    }
    ```
    mock:
    ```go
    func (m *MockFoo) Bar() apicodec.Codec { // This is a problem, since apicodec is an internal package.
        // ...
    }
    ```
    
    While technically this problem is solved in Go 1.23 with explicit alias
    types representation, (indeed, if you run mockgen on the example in the
    linked issue with `GODEBUG=gotypesalias=1`, you get the expected
    behavior) since we support the last two versions, we can't bump `go.mod`
    to 1.23 yet. This leaves us with the old behavior, where `go/types` does
    not track alias types. You can tell if an object is an alias, but not a
    type itself, and there is no way to retrieve the object of interest at
    the point where we are recursively parsing method types.
    
    This PR works around this issue (temporarily) by using syntax
    information to find all references to aliases in the source package.
    When we find one, we record it in a mapping of underlying type -> alias
    name. Later, while we parse the type tree, we replace any underlying
    types in the mapping with their alias names.
    
    The unexpected side effect of this is that _all_ references to the
    underlying type in the generated mocks will be replaced with the alias,
    even if the source used the underlying name. This is fine because:
    * If the alias is in the mapping, it was used at least once, which means
    its accessible.
    * From a type-checking perspective, aliases and their underlying types
    are equivalent.
    
    The nice exception to the side effect is when we explicitly request mock
    generation for an alias type, since at that point we are dealing with
    the object, not the type.
    
    With this PR, the mocks get generated correctly now:
    ```go
    func (m *MockFoo) Bar() Codec {
        // ...
    }
    ```
    
    Once we can bump `go.mod` to 1.23, we should definitely remove this,
    since the new type alias type nodes solve this problem automatically.
    JacobOaks authored Oct 28, 2024
    Configuration menu
    Copy the full SHA
    c205527 View commit details
    Browse the repository at this point in the history
  2. fix: import and arg collision (#219)

    This PR fixes an issue where if the name of an argument to a method that is being mocked collides with the name of a package that needs to be imported, mockgen could generate uncompilable code.
    
    Resolves #218
    bstncartwright authored Oct 28, 2024
    Configuration menu
    Copy the full SHA
    eb67641 View commit details
    Browse the repository at this point in the history

Commits on Nov 19, 2024

  1. Fix -imports handling aliased imports in source mode (#165)

    In source mode, when generating a mock within the same package that uses
    names from a package that is imported with an alias, the generated mock
    should obey -imports properly and generate imports with the provided
    alias.
    
    If the generated code is not using the same aliases as the main filed in
    a package the go compiler will still happily run but if you want ot use
    this package as a source in another package where you want to generate a
    mock, mock will fail because it will not know what to do with a package
    that is imported with two different names in a source package.
    
    This patch fixes the generation by making `-imports` handling do a more
    correct thing.
    
    It can be argued that the correct behavior is, by default use the the
    same package aliases as the ones in the source file, however that change
    looked way more invasive and i didn't see a good coverage of tests that
    would help me make sure the changes worked well.
    
    This is what i found to be the least invasive fix for #166.
    mtoader authored Nov 19, 2024
    Configuration menu
    Copy the full SHA
    d97cf0d View commit details
    Browse the repository at this point in the history

Commits on Feb 4, 2025

  1. Copying gomock definition and tests from rules_go (#231)

    This PR copies the gomock definition and tests from rules_go with
    minimal changes:
    
    * Replacing github.com/golang/mock with go.uber.org/mock
    * Replacing `load` statements accordingly
    * Setting up a Bazel and a Go module in the "bazel" directory
    
    Note that the Go module uses v0.4.0 of go.uber.org/mock, because the
    latest version is no longer compatible with the gomock rule
    (bazel-contrib/rules_go#4153). We will update
    the rule and mockgen version in subsequent PRs.
    
    This is a first step in addressing #225
    linzhp authored Feb 4, 2025
    Configuration menu
    Copy the full SHA
    bb4128e View commit details
    Browse the repository at this point in the history

Commits on Apr 7, 2025

  1. Prepare release v0.5.1 (#241)

    Prepare the changelog for a v0.5.1 release which contains several bug
    fixes.
    JacobOaks authored Apr 7, 2025
    Configuration menu
    Copy the full SHA
    cf6f33d View commit details
    Browse the repository at this point in the history
  2. Back to development. (#242)

    Return the changelog to development status.
    JacobOaks authored Apr 7, 2025
    Configuration menu
    Copy the full SHA
    6568d88 View commit details
    Browse the repository at this point in the history

Commits on Apr 28, 2025

  1. Bump go.mod to 1.23 and remove alias replacements (#248)

    Alias replacements derived from syntax were introduced in #220 as a way
    to ensure the aliases used in source code were also used. This helped
    ensure packages mode worked on go1.22, which didn't have explicit alias
    node support in the `go/types` package.
    
    Alias replacements have a couple issues:
    * They flat out replace any would-be references to an underlying type
    with an alias type.
    * They don't properly handle aliases to generic type instantiations
    (ref: #243)
    
    Now that go1.24 is released, we can bump `go.mod` to go1.23, which means
    we can ensure `go/types` has an explicit `types.Alias` node for type
    aliases, and we can remove the alias replacement logic.
    JacobOaks authored Apr 28, 2025
    Configuration menu
    Copy the full SHA
    8ce01ac View commit details
    Browse the repository at this point in the history
  2. Prepare release v0.5.2 (#250)

    Prepare the changelog for a v0.5.2 release containing a bug fix caused
    by outdated go version and alias replacements logic.
    JacobOaks authored Apr 28, 2025
    Configuration menu
    Copy the full SHA
    0b8095f View commit details
    Browse the repository at this point in the history
  3. Back to development (#251)

    Return to development changelog status.
    
    <!-- This is an auto-generated comment: release notes by coderabbit.ai
    -->
    
    ## Summary by CodeRabbit
    
    - **Documentation**
    - Added an "Unreleased" section to the changelog for tracking future
    updates.
    
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->
    JacobOaks authored Apr 28, 2025
    Configuration menu
    Copy the full SHA
    871d86b View commit details
    Browse the repository at this point in the history

Commits on Jun 12, 2025

  1. Support for archive mode (#258)

    This adds support for a 3rd option for creating mocks after reflect and
    source-mode: the archive mode. Archive mode lets you load archive files
    to create mocks. This can come in handy for writing Bazel rules that
    produce intermediary archive files and automatically codegen mocks in
    Bazel environments.
    
    Rebased version of #125
    
    ---------
    
    Co-authored-by: Zhongpeng Lin <zplin@uber.com>
    Co-authored-by: Sung Yoon Whang <sungyoonwhang@gmail.com>
    Co-authored-by: Sung Yoon Whang <sungyoon@uber.com>
    4 people authored Jun 12, 2025
    Configuration menu
    Copy the full SHA
    359202c View commit details
    Browse the repository at this point in the history
  2. feat(bazel): support archive mode (#259)

    Removes the broken reflect mode in the bazel aspect, in favor of archive
    mode which was landed in #258
    
    ---------
    
    Co-authored-by: Zhongpeng Lin <zplin@uber.com>
    JamyDev and linzhp authored Jun 12, 2025
    Configuration menu
    Copy the full SHA
    aa11bfc View commit details
    Browse the repository at this point in the history

Commits on Jul 1, 2025

  1. feat(bazel): mock_names flag support in archive mode (#262)

    Hi! In #259 was introduced archive mode for bazel rule, but no support
    for mock_names.
    This PR added `mock_names` attr to `_gomock_archive` rule.
    MrDan4es authored Jul 1, 2025
    Configuration menu
    Copy the full SHA
    6a0445c View commit details
    Browse the repository at this point in the history

Commits on Aug 18, 2025

  1. update golang.org/x/tools to v0.36.0 (#276)

    Fixes #274.
    
    ---------
    
    Co-authored-by: Jacob Oaks <joaks@uber.com>
    marten-seemann and JacobOaks authored Aug 18, 2025
    Configuration menu
    Copy the full SHA
    5900c74 View commit details
    Browse the repository at this point in the history
  2. Update CI to run 1.24/1.25 (#277)

    go1.25 was released, let's test it in CI.
    JacobOaks authored Aug 18, 2025
    Configuration menu
    Copy the full SHA
    c654195 View commit details
    Browse the repository at this point in the history
  3. Prepare release v0.6.0 (#278)

    This includes fixes for go1.25 and the new archive mode.
    JacobOaks authored Aug 18, 2025
    Configuration menu
    Copy the full SHA
    2d1c581 View commit details
    Browse the repository at this point in the history
Loading