gojuno / minimock

Powerful mock generation tool for Go programming language
MIT License
574 stars 38 forks source link

Bugs/improvements on union interfaces, diff displaying and version setting #102

Closed zcolleen closed 1 month ago

zcolleen commented 2 months ago

In this pr i introduce 3 bugs/improvements:

  1. We have to update gowrap when pr https://github.com/hexdigest/gowrap/pull/86 is merged, to fix generation of interfaces with unions and type approximations.

  2. Improvement with diff displaying: when test fails because expectations failed and we used minimock.Anycontext, the diff will show arguments that are different as well as context argument, e.g.

        Diff:
        --- Expected params
        +++ Actual params
        @@ -1,6 +1,4 @@
         (tests.ContextAccepterMockAcceptContextWithOtherArgsParams) {
        - ctx: (minimock.anyContext) {
        -  Context: (context.Context) <nil>
        - },
        - i1: (int) 24
        + ctx: (context.backgroundCtx) context.Background,
        + i1: (int) 123
         }

    It is very confusing for developers as they think that there is also some issue with context, that anyContext is not working. So i improved diff displaying in that way that it wont show difference between context if anyContext is used, e.g.

        Diff:
        --- Expected params
        +++ Actual params
        @@ -4,3 +4,3 @@
          },
        - i1: (int) 24
        + i1: (int) 123
         }
  1. Improved version when displaying --version or setting it in generated code. The issue is that if you install minimock binary with go install, the version is set to 'dev', so in generated code minimock version is set to 'dev' making it impossible to understand which version of minimock has generated code, e.g.
    // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT.

So in this pr if version is not set, we will take version and commit from debug.ReadBuildInfo() .

  1. Some minor documentation update.
hexdigest commented 2 months ago

Hey @zcolleen!

Thank you for the fix! I released v1.3.7 version of Gowrap, can you please update this pr (remove replace directive from go.mod).

zcolleen commented 2 months ago

Hey @hexdigest ! Updated go.mod, double checked everything