[
  {
    "path": ".github/CODEOWNERS",
    "content": "*                   @codyoss\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.md",
    "content": "---\nname: Bug report\nabout: Report a bug in gomock\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Actual behavior** A clear and concise description of what the bug is.\n\n**Expected behavior** A clear and concise description of what you expected to\nhappen.\n\n**To Reproduce** Steps to reproduce the behavior\n\n1.  ...\n2.  ...\n\n**Additional Information**\n\n-   gomock mode (reflect or source):\n-   gomock version or git ref:\n-   golang version:\n\n**Triage Notes for the Maintainers**\n\n<!-- 🎉🎉🎉 Thank you for an opening an issue !!! 🎉🎉🎉 We are doing our best to get to this. -->\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/config.yml",
    "content": "blank_issues_enabled: true\n#contact_links:\n#  - name: GitHub Community Forum\n#    url: https://github.community/\n#    about: Please ask and answer questions here.\n#  - name: GitHub Security Bug Bounty\n#    url: https://bounty.github.com/\n#    about: Please report security vulnerabilities here.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "content": "---\nname: Feature request\nabout: Propose a new feature for gomock\ntitle: ''\nlabels: 'type: feature request'\nassignees: ''\n\n---\n\n*Requested feature* A clear description of the desired feature and an example of\nhow it would be used.\n\n*Why the feature is needed* A clear description of how this feature is not\nserved by existing functionality in gomock.\n\n*(Optional) Proposed solution* A clear description of a proposed method for\nadding this feature to gomock.\n"
  },
  {
    "path": ".github/workflows/test.yaml",
    "content": "name: Run tests\non:\n  push:\n    branches: [main]\n  pull_request:\n    branches: [main]\nenv:\n  GO111MODULE: on\njobs:\n  test:\n    strategy:\n      matrix:\n        go-version: [1.15.x, 1.18.x]\n        os: [ubuntu-latest]\n    runs-on: ${{ matrix.os }}\n    steps:\n\n    - name: Install Go\n      uses: actions/setup-go@v2\n      with:\n        go-version: ${{ matrix.go-version }}\n\n    - name: Checkout code\n      uses: actions/checkout@v2\n\n    - name: Vet and build\n      run: |\n        go vet ./...\n        go build ./...\n\n    - name: Install mockgen\n      run: |\n        go install github.com/golang/mock/mockgen\n\n    - name: Run test script\n      run: |\n        ./ci/test.sh\n        ./ci/check_panic_handling.sh\n\n    - name: Run Go tests all\n      if: ${{ startsWith(matrix.go-version, '1.18') }}\n      run: |\n        for i in $(find $PWD -name go.mod); do\n          pushd $(dirname $i)\n          go test ./...\n          popd\n        done \n\n    - name: Run Go tests some\n      if: ${{ startsWith(matrix.go-version, '1.18') == false }}\n      run: |\n          go test ./...\n"
  },
  {
    "path": ".gitignore",
    "content": "# Object files and binaries from go.\n*.[568]\n\n# Library files.\n*.a\n\n# Any file prefixed by an underscore.\n*/_*\n\n# System\n.*.swp\n.DS_Store\n\n# The mockgen binary.\nmockgen/mockgen\n\n# Editors\n.vscode\n.idea\n\n# vendor directory used for IDEs\n/vendor\n"
  },
  {
    "path": ".goreleaser.yml",
    "content": "# Release automation via GoReleaser (goreleaser.com)\n# Requires a valid GITHUB_TOKEN envar prior to running `goreleaser`\n# See https://goreleaser.com/environment/ for more info\n---\nrelease:\n  github:\n    owner: golang\n    name: mock\n\nbuilds:\n  - binary: mockgen\n    goos:\n      - darwin\n      - windows\n      - linux\n    goarch:\n      - amd64\n      - arm64\n      - 386\n    env:\n      - CGO_ENABLED=0\n      - GO111MODULE=on\n      - GOPROXY=https://proxy.golang.org\n      - GOSUMDB=sum.golang.org\n    main: ./mockgen/\n\narchives:\n - format: tar.gz\n   wrap_in_directory: true\n   files:\n     - LICENSE\n     - README.md\nchecksum:\nsnapshot:\n  name_template: \"snap-{{ .Commit }}\"\nchangelog:\n  sort: asc\n  filters:\n    exclude:\n      - '^docs:'\n      - '^test:'\n      - 'README'\n"
  },
  {
    "path": "AUTHORS",
    "content": "# This is the official list of GoMock authors for copyright purposes.\n# This file is distinct from the CONTRIBUTORS files.\n# See the latter for an explanation.\n\n# Names should be added to this file as\n#\tName or Organization <email address>\n# The email address is not required for organizations.\n\n# Please keep the list sorted.\n\nAlex Reece <awreece@gmail.com>\nGoogle Inc.\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Contributing\n\nFirst off, thank you for taking an interest to contribute to this project!\n\n## Opening issues\n\nWhen opening a [new issue](https://github.com/golang/mock/issues/new/choose)\nplease:\n\n1. Make sure there are not other open/closed issues asking/reporting/requesting\n   the same thing.\n1. Choose one of our provided templates and fill out as much information as\n   possible.\n\n## Opening a Pull Requests\n\nWe gladly accept contributions from the community. Before opening a pull request\nplease make sure to create an issue for discussion first. This helps us decide\nwhat action should be taken in regards to the issue.\n"
  },
  {
    "path": "CONTRIBUTORS",
    "content": "# This is the official list of people who can contribute (and typically\n# have contributed) code to the gomock repository.\n# The AUTHORS file lists the copyright holders; this file\n# lists people.  For example, Google employees are listed here\n# but not in AUTHORS, because Google holds the copyright.\n#\n# The submission process automatically checks to make sure\n# that people submitting code are listed in this file (by email address).\n#\n# Names should be added to this file only after verifying that\n# the individual or the individual's organization has agreed to\n# the appropriate Contributor License Agreement, found here:\n#\n#     http://code.google.com/legal/individual-cla-v1.0.html\n#     http://code.google.com/legal/corporate-cla-v1.0.html\n#\n# The agreement for individuals can be filled out on the web.\n#\n# When adding J Random Contributor's name to this file,\n# either J's name or J's organization's name should be\n# added to the AUTHORS file, depending on whether the\n# individual or corporate CLA was used.\n\n# Names should be added to this file like so:\n#     Name <email address>\n#\n# An entry with two email addresses specifies that the\n# first address should be used in the submit logs and\n# that the second address should be recognized as the\n# same person when interacting with Rietveld.\n\n# Please keep the list sorted.\n\nAaron Jacobs <jacobsa@google.com> <aaronjjacobs@gmail.com>\nAlex Reece <awreece@gmail.com>\nDavid Symonds <dsymonds@golang.org>\nRyan Barrett <ryanb@google.com>\n"
  },
  {
    "path": "LICENSE",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# gomock\n\n**Update, June 2023**: _This repo and tool are no longer maintained.\nPlease see [go.uber.org/mock](https://github.com/uber/mock) for a maintained fork instead._\n\n[![Build Status][ci-badge]][ci-runs] [![Go Reference][reference-badge]][reference]\n\ngomock is a mocking framework for the [Go programming language][golang]. It\nintegrates well with Go's built-in `testing` package, but can be used in other\ncontexts too.\n\n## Installation\n\nOnce you have [installed Go][golang-install], install the `mockgen` tool.\n\n**Note**: If you have not done so already be sure to add `$GOPATH/bin` to your\n`PATH`.\n\nTo get the latest released version use:\n\n### Go version < 1.16\n\n```bash\nGO111MODULE=on go get github.com/golang/mock/mockgen@v1.6.0\n```\n\n### Go 1.16+\n\n```bash\ngo install github.com/golang/mock/mockgen@v1.6.0\n```\n\nIf you use `mockgen` in your CI pipeline, it may be more appropriate to fixate\non a specific mockgen version. You should try to keep the library in sync with\nthe version of mockgen used to generate your mocks.\n\n## Running mockgen\n\n`mockgen` has two modes of operation: source and reflect.\n\n### Source mode\n\nSource mode generates mock interfaces from a source file.\nIt is enabled by using the -source flag. Other flags that\nmay be useful in this mode are -imports and -aux_files.\n\nExample:\n\n```bash\nmockgen -source=foo.go [other options]\n```\n\n### Reflect mode\n\nReflect mode generates mock interfaces by building a program\nthat uses reflection to understand interfaces. It is enabled\nby passing two non-flag arguments: an import path, and a\ncomma-separated list of symbols.\n\nYou can use \".\" to refer to the current path's package.\n\nExample:\n\n```bash\nmockgen database/sql/driver Conn,Driver\n\n# Convenient for `go:generate`.\nmockgen . Conn,Driver\n```\n\n### Flags\n\nThe `mockgen` command is used to generate source code for a mock\nclass given a Go source file containing interfaces to be mocked.\nIt supports the following flags:\n\n- `-source`: A file containing interfaces to be mocked.\n\n- `-destination`: A file to which to write the resulting source code. If you\n  don't set this, the code is printed to standard output.\n\n- `-package`: The package to use for the resulting mock class\n  source code. If you don't set this, the package name is `mock_` concatenated\n  with the package of the input file.\n\n- `-imports`: A list of explicit imports that should be used in the resulting\n  source code, specified as a comma-separated list of elements of the form\n  `foo=bar/baz`, where `bar/baz` is the package being imported and `foo` is\n  the identifier to use for the package in the generated source code.\n\n- `-aux_files`: A list of additional files that should be consulted to\n  resolve e.g. embedded interfaces defined in a different file. This is\n  specified as a comma-separated list of elements of the form\n  `foo=bar/baz.go`, where `bar/baz.go` is the source file and `foo` is the\n  package name of that file used by the -source file.\n\n- `-build_flags`: (reflect mode only) Flags passed verbatim to `go build`.\n\n- `-mock_names`: A list of custom names for generated mocks. This is specified\n  as a comma-separated list of elements of the form\n  `Repository=MockSensorRepository,Endpoint=MockSensorEndpoint`, where\n  `Repository` is the interface name and `MockSensorRepository` is the desired\n  mock name (mock factory method and mock recorder will be named after the mock).\n  If one of the interfaces has no custom name specified, then default naming\n  convention will be used.\n\n- `-self_package`: The full package import path for the generated code. The\n  purpose of this flag is to prevent import cycles in the generated code by\n  trying to include its own package. This can happen if the mock's package is\n  set to one of its inputs (usually the main one) and the output is stdio so\n  mockgen cannot detect the final output package. Setting this flag will then\n  tell mockgen which import to exclude.\n\n- `-copyright_file`: Copyright file used to add copyright header to the resulting source code.\n\n- `-debug_parser`: Print out parser results only.\n\n- `-exec_only`: (reflect mode) If set, execute this reflection program.\n\n- `-prog_only`: (reflect mode) Only generate the reflection program; write it to stdout and exit.\n\n- `-write_package_comment`: Writes package documentation comment (godoc) if true. (default true)\n\nFor an example of the use of `mockgen`, see the `sample/` directory. In simple\ncases, you will need only the `-source` flag.\n\n## Building Mocks\n\n```go\ntype Foo interface {\n  Bar(x int) int\n}\n\nfunc SUT(f Foo) {\n // ...\n}\n\n```\n\n```go\nfunc TestFoo(t *testing.T) {\n  ctrl := gomock.NewController(t)\n\n  // Assert that Bar() is invoked.\n  defer ctrl.Finish()\n\n  m := NewMockFoo(ctrl)\n\n  // Asserts that the first and only call to Bar() is passed 99.\n  // Anything else will fail.\n  m.\n    EXPECT().\n    Bar(gomock.Eq(99)).\n    Return(101)\n\n  SUT(m)\n}\n```\n\nIf you are using a Go version of 1.14+, a mockgen version of 1.5.0+, and are\npassing a *testing.T into `gomock.NewController(t)` you no longer need to call\n`ctrl.Finish()` explicitly. It will be called for you automatically from a self\nregistered [Cleanup](https://pkg.go.dev/testing?tab=doc#T.Cleanup) function.\n\n## Building Stubs\n\n```go\ntype Foo interface {\n  Bar(x int) int\n}\n\nfunc SUT(f Foo) {\n // ...\n}\n\n```\n\n```go\nfunc TestFoo(t *testing.T) {\n  ctrl := gomock.NewController(t)\n  defer ctrl.Finish()\n\n  m := NewMockFoo(ctrl)\n\n  // Does not make any assertions. Executes the anonymous functions and returns\n  // its result when Bar is invoked with 99.\n  m.\n    EXPECT().\n    Bar(gomock.Eq(99)).\n    DoAndReturn(func(_ int) int {\n      time.Sleep(1*time.Second)\n      return 101\n    }).\n    AnyTimes()\n\n  // Does not make any assertions. Returns 103 when Bar is invoked with 101.\n  m.\n    EXPECT().\n    Bar(gomock.Eq(101)).\n    Return(103).\n    AnyTimes()\n\n  SUT(m)\n}\n```\n\n## Modifying Failure Messages\n\nWhen a matcher reports a failure, it prints the received (`Got`) vs the\nexpected (`Want`) value.\n\n```shell\nGot: [3]\nWant: is equal to 2\nExpected call at user_test.go:33 doesn't match the argument at index 1.\nGot: [0 1 1 2 3]\nWant: is equal to 1\n```\n\n### Modifying `Want`\n\nThe `Want` value comes from the matcher's `String()` method. If the matcher's\ndefault output doesn't meet your needs, then it can be modified as follows:\n\n```go\ngomock.WantFormatter(\n  gomock.StringerFunc(func() string { return \"is equal to fifteen\" }),\n  gomock.Eq(15),\n)\n```\n\nThis modifies the `gomock.Eq(15)` matcher's output for `Want:` from `is equal\nto 15` to `is equal to fifteen`.\n\n### Modifying `Got`\n\nThe `Got` value comes from the object's `String()` method if it is available.\nIn some cases the output of an object is difficult to read (e.g., `[]byte`) and\nit would be helpful for the test to print it differently. The following\nmodifies how the `Got` value is formatted:\n\n```go\ngomock.GotFormatterAdapter(\n  gomock.GotFormatterFunc(func(i interface{}) string {\n    // Leading 0s\n    return fmt.Sprintf(\"%02d\", i)\n  }),\n  gomock.Eq(15),\n)\n```\n\nIf the received value is `3`, then it will be printed as `03`.\n\n[golang]:              http://golang.org/\n[golang-install]:      http://golang.org/doc/install.html#releases\n[gomock-reference]:    https://pkg.go.dev/github.com/golang/mock/gomock\n[ci-badge]:            https://github.com/golang/mock/actions/workflows/test.yaml/badge.svg\n[ci-runs]:             https://github.com/golang/mock/actions\n[reference-badge]:     https://pkg.go.dev/badge/github.com/golang/mock.svg\n[reference]:           https://pkg.go.dev/github.com/golang/mock\n\n## Debugging Errors\n\n### reflect vendoring error\n\n```text\ncannot find package \".\"\n... github.com/golang/mock/mockgen/model\n```\n\nIf you come across this error while using reflect mode and vendoring\ndependencies there are three workarounds you can choose from:\n\n1. Use source mode.\n2. Include an empty import `import _ \"github.com/golang/mock/mockgen/model\"`.\n3. Add `--build_flags=--mod=mod` to your mockgen command.\n\nThis error is due to changes in default behavior of the `go` command in more\nrecent versions. More details can be found in\n[#494](https://github.com/golang/mock/issues/494).\n"
  },
  {
    "path": "ci/check_panic_handling.sh",
    "content": "#!/bin/bash\n# Copyright 2010 Google LLC.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# This script is used to ensure that panics are properly reported in tests.\n\nset -eux\n\npushd mockgen/internal/tests/panicing_test\ngo test -v -tags=panictest -run TestDanger_Panics_Explicit | grep \"Danger, Will Robinson!\"\ngo test -v -tags=panictest -run TestDanger_Panics_Implicit | grep \"Danger, Will Robinson!\"\npopd\n"
  },
  {
    "path": "ci/test.sh",
    "content": "#!/bin/bash\n# This script is used to ensure that the go.mod file is up to date.\n\nset -euo pipefail\n\nif [[ $(go version) != *\"go1.18\"* ]]; then\n  exit 0\nfi\n\nfor i in $(find $PWD -name go.mod); do\n  pushd $(dirname $i)\n  go mod tidy\n  popd\ndone\n\nif [ ! -z \"$(git status --porcelain)\" ]; then\n  git status\n  git diff\n  echo\n  echo \"The go.mod is not up to date.\"\n  exit 1\nfi\n\nBASE_DIR=\"$PWD\"\nTEMP_DIR=$(mktemp -d)\nfunction cleanup() {\n  rm -rf \"${TEMP_DIR}\"\n}\ntrap cleanup EXIT\n\ncp -r . \"${TEMP_DIR}/\"\ncd $TEMP_DIR\n\nfor i in $(find $PWD -name go.mod); do\n  pushd $(dirname $i)\n  go generate ./...\n  popd\ndone\n\nif ! diff -r . \"${BASE_DIR}\"; then\n  echo\n  echo \"The generated files aren't up to date.\"\n  echo \"Update them with the 'go generate ./...' command.\"\n  exit 1\nfi\n"
  },
  {
    "path": "go.mod",
    "content": "module github.com/golang/mock\n\nrequire (\n\tgolang.org/x/mod v0.5.1\n\tgolang.org/x/tools v0.1.8\n)\n\ngo 1.15\n"
  },
  {
    "path": "go.sum",
    "content": "github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM=\ngithub.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=\ngolang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\ngolang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=\ngolang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=\ngolang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=\ngolang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=\ngolang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=\ngolang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=\ngolang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=\ngolang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=\ngolang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\ngolang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=\ngolang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=\ngolang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=\ngolang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=\ngolang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w=\ngolang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=\ngolang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\ngolang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\ngolang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\ngolang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\n"
  },
  {
    "path": "gomock/call.go",
    "content": "// Copyright 2010 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage gomock\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// Call represents an expected call to a mock.\ntype Call struct {\n\tt TestHelper // for triggering test failures on invalid call setup\n\n\treceiver   interface{}  // the receiver of the method call\n\tmethod     string       // the name of the method\n\tmethodType reflect.Type // the type of the method\n\targs       []Matcher    // the args\n\torigin     string       // file and line number of call setup\n\n\tpreReqs []*Call // prerequisite calls\n\n\t// Expectations\n\tminCalls, maxCalls int\n\n\tnumCalls int // actual number made\n\n\t// actions are called when this Call is called. Each action gets the args and\n\t// can set the return values by returning a non-nil slice. Actions run in the\n\t// order they are created.\n\tactions []func([]interface{}) []interface{}\n}\n\n// newCall creates a *Call. It requires the method type in order to support\n// unexported methods.\nfunc newCall(t TestHelper, receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {\n\tt.Helper()\n\n\t// TODO: check arity, types.\n\tmArgs := make([]Matcher, len(args))\n\tfor i, arg := range args {\n\t\tif m, ok := arg.(Matcher); ok {\n\t\t\tmArgs[i] = m\n\t\t} else if arg == nil {\n\t\t\t// Handle nil specially so that passing a nil interface value\n\t\t\t// will match the typed nils of concrete args.\n\t\t\tmArgs[i] = Nil()\n\t\t} else {\n\t\t\tmArgs[i] = Eq(arg)\n\t\t}\n\t}\n\n\t// callerInfo's skip should be updated if the number of calls between the user's test\n\t// and this line changes, i.e. this code is wrapped in another anonymous function.\n\t// 0 is us, 1 is RecordCallWithMethodType(), 2 is the generated recorder, and 3 is the user's test.\n\torigin := callerInfo(3)\n\tactions := []func([]interface{}) []interface{}{func([]interface{}) []interface{} {\n\t\t// Synthesize the zero value for each of the return args' types.\n\t\trets := make([]interface{}, methodType.NumOut())\n\t\tfor i := 0; i < methodType.NumOut(); i++ {\n\t\t\trets[i] = reflect.Zero(methodType.Out(i)).Interface()\n\t\t}\n\t\treturn rets\n\t}}\n\treturn &Call{t: t, receiver: receiver, method: method, methodType: methodType,\n\t\targs: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions}\n}\n\n// AnyTimes allows the expectation to be called 0 or more times\nfunc (c *Call) AnyTimes() *Call {\n\tc.minCalls, c.maxCalls = 0, 1e8 // close enough to infinity\n\treturn c\n}\n\n// MinTimes requires the call to occur at least n times. If AnyTimes or MaxTimes have not been called or if MaxTimes\n// was previously called with 1, MinTimes also sets the maximum number of calls to infinity.\nfunc (c *Call) MinTimes(n int) *Call {\n\tc.minCalls = n\n\tif c.maxCalls == 1 {\n\t\tc.maxCalls = 1e8\n\t}\n\treturn c\n}\n\n// MaxTimes limits the number of calls to n times. If AnyTimes or MinTimes have not been called or if MinTimes was\n// previously called with 1, MaxTimes also sets the minimum number of calls to 0.\nfunc (c *Call) MaxTimes(n int) *Call {\n\tc.maxCalls = n\n\tif c.minCalls == 1 {\n\t\tc.minCalls = 0\n\t}\n\treturn c\n}\n\n// DoAndReturn declares the action to run when the call is matched.\n// The return values from this function are returned by the mocked function.\n// It takes an interface{} argument to support n-arity functions.\n// The anonymous function must match the function signature mocked method.\nfunc (c *Call) DoAndReturn(f interface{}) *Call {\n\t// TODO: Check arity and types here, rather than dying badly elsewhere.\n\tv := reflect.ValueOf(f)\n\n\tc.addAction(func(args []interface{}) []interface{} {\n\t\tc.t.Helper()\n\t\tft := v.Type()\n\t\tif c.methodType.NumIn() != ft.NumIn() {\n\t\t\tif ft.IsVariadic() {\n\t\t\t\tc.t.Fatalf(\"wrong number of arguments in DoAndReturn func for %T.%v The function signature must match the mocked method, a variadic function cannot be used.\",\n\t\t\t\t\tc.receiver, c.method)\n\t\t\t} else {\n\t\t\t\tc.t.Fatalf(\"wrong number of arguments in DoAndReturn func for %T.%v: got %d, want %d [%s]\",\n\t\t\t\t\tc.receiver, c.method, ft.NumIn(), c.methodType.NumIn(), c.origin)\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\t\tvArgs := make([]reflect.Value, len(args))\n\t\tfor i := 0; i < len(args); i++ {\n\t\t\tif args[i] != nil {\n\t\t\t\tvArgs[i] = reflect.ValueOf(args[i])\n\t\t\t} else {\n\t\t\t\t// Use the zero value for the arg.\n\t\t\t\tvArgs[i] = reflect.Zero(ft.In(i))\n\t\t\t}\n\t\t}\n\t\tvRets := v.Call(vArgs)\n\t\trets := make([]interface{}, len(vRets))\n\t\tfor i, ret := range vRets {\n\t\t\trets[i] = ret.Interface()\n\t\t}\n\t\treturn rets\n\t})\n\treturn c\n}\n\n// Do declares the action to run when the call is matched. The function's\n// return values are ignored to retain backward compatibility. To use the\n// return values call DoAndReturn.\n// It takes an interface{} argument to support n-arity functions.\n// The anonymous function must match the function signature mocked method.\nfunc (c *Call) Do(f interface{}) *Call {\n\t// TODO: Check arity and types here, rather than dying badly elsewhere.\n\tv := reflect.ValueOf(f)\n\n\tc.addAction(func(args []interface{}) []interface{} {\n\t\tc.t.Helper()\n\t\tft := v.Type()\n\t\tif c.methodType.NumIn() != ft.NumIn() {\n\t\t\tif ft.IsVariadic() {\n\t\t\t\tc.t.Fatalf(\"wrong number of arguments in Do func for %T.%v The function signature must match the mocked method, a variadic function cannot be used.\",\n\t\t\t\t\tc.receiver, c.method)\n\t\t\t} else {\n\t\t\t\tc.t.Fatalf(\"wrong number of arguments in Do func for %T.%v: got %d, want %d [%s]\",\n\t\t\t\t\tc.receiver, c.method, ft.NumIn(), c.methodType.NumIn(), c.origin)\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\t\tvArgs := make([]reflect.Value, len(args))\n\t\tfor i := 0; i < len(args); i++ {\n\t\t\tif args[i] != nil {\n\t\t\t\tvArgs[i] = reflect.ValueOf(args[i])\n\t\t\t} else {\n\t\t\t\t// Use the zero value for the arg.\n\t\t\t\tvArgs[i] = reflect.Zero(ft.In(i))\n\t\t\t}\n\t\t}\n\t\tv.Call(vArgs)\n\t\treturn nil\n\t})\n\treturn c\n}\n\n// Return declares the values to be returned by the mocked function call.\nfunc (c *Call) Return(rets ...interface{}) *Call {\n\tc.t.Helper()\n\n\tmt := c.methodType\n\tif len(rets) != mt.NumOut() {\n\t\tc.t.Fatalf(\"wrong number of arguments to Return for %T.%v: got %d, want %d [%s]\",\n\t\t\tc.receiver, c.method, len(rets), mt.NumOut(), c.origin)\n\t}\n\tfor i, ret := range rets {\n\t\tif got, want := reflect.TypeOf(ret), mt.Out(i); got == want {\n\t\t\t// Identical types; nothing to do.\n\t\t} else if got == nil {\n\t\t\t// Nil needs special handling.\n\t\t\tswitch want.Kind() {\n\t\t\tcase reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:\n\t\t\t\t// ok\n\t\t\tdefault:\n\t\t\t\tc.t.Fatalf(\"argument %d to Return for %T.%v is nil, but %v is not nillable [%s]\",\n\t\t\t\t\ti, c.receiver, c.method, want, c.origin)\n\t\t\t}\n\t\t} else if got.AssignableTo(want) {\n\t\t\t// Assignable type relation. Make the assignment now so that the generated code\n\t\t\t// can return the values with a type assertion.\n\t\t\tv := reflect.New(want).Elem()\n\t\t\tv.Set(reflect.ValueOf(ret))\n\t\t\trets[i] = v.Interface()\n\t\t} else {\n\t\t\tc.t.Fatalf(\"wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]\",\n\t\t\t\ti, c.receiver, c.method, got, want, c.origin)\n\t\t}\n\t}\n\n\tc.addAction(func([]interface{}) []interface{} {\n\t\treturn rets\n\t})\n\n\treturn c\n}\n\n// Times declares the exact number of times a function call is expected to be executed.\nfunc (c *Call) Times(n int) *Call {\n\tc.minCalls, c.maxCalls = n, n\n\treturn c\n}\n\n// SetArg declares an action that will set the nth argument's value,\n// indirected through a pointer. Or, in the case of a slice and map, SetArg\n// will copy value's elements/key-value pairs into the nth argument.\nfunc (c *Call) SetArg(n int, value interface{}) *Call {\n\tc.t.Helper()\n\n\tmt := c.methodType\n\t// TODO: This will break on variadic methods.\n\t// We will need to check those at invocation time.\n\tif n < 0 || n >= mt.NumIn() {\n\t\tc.t.Fatalf(\"SetArg(%d, ...) called for a method with %d args [%s]\",\n\t\t\tn, mt.NumIn(), c.origin)\n\t}\n\t// Permit setting argument through an interface.\n\t// In the interface case, we don't (nay, can't) check the type here.\n\tat := mt.In(n)\n\tswitch at.Kind() {\n\tcase reflect.Ptr:\n\t\tdt := at.Elem()\n\t\tif vt := reflect.TypeOf(value); !vt.AssignableTo(dt) {\n\t\t\tc.t.Fatalf(\"SetArg(%d, ...) argument is a %v, not assignable to %v [%s]\",\n\t\t\t\tn, vt, dt, c.origin)\n\t\t}\n\tcase reflect.Interface:\n\t\t// nothing to do\n\tcase reflect.Slice:\n\t\t// nothing to do\n\tcase reflect.Map:\n\t\t// nothing to do\n\tdefault:\n\t\tc.t.Fatalf(\"SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice non-map type %v [%s]\",\n\t\t\tn, at, c.origin)\n\t}\n\n\tc.addAction(func(args []interface{}) []interface{} {\n\t\tv := reflect.ValueOf(value)\n\t\tswitch reflect.TypeOf(args[n]).Kind() {\n\t\tcase reflect.Slice:\n\t\t\tsetSlice(args[n], v)\n\t\tcase reflect.Map:\n\t\t\tsetMap(args[n], v)\n\t\tdefault:\n\t\t\treflect.ValueOf(args[n]).Elem().Set(v)\n\t\t}\n\t\treturn nil\n\t})\n\treturn c\n}\n\n// isPreReq returns true if other is a direct or indirect prerequisite to c.\nfunc (c *Call) isPreReq(other *Call) bool {\n\tfor _, preReq := range c.preReqs {\n\t\tif other == preReq || preReq.isPreReq(other) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n// After declares that the call may only match after preReq has been exhausted.\nfunc (c *Call) After(preReq *Call) *Call {\n\tc.t.Helper()\n\n\tif c == preReq {\n\t\tc.t.Fatalf(\"A call isn't allowed to be its own prerequisite\")\n\t}\n\tif preReq.isPreReq(c) {\n\t\tc.t.Fatalf(\"Loop in call order: %v is a prerequisite to %v (possibly indirectly).\", c, preReq)\n\t}\n\n\tc.preReqs = append(c.preReqs, preReq)\n\treturn c\n}\n\n// Returns true if the minimum number of calls have been made.\nfunc (c *Call) satisfied() bool {\n\treturn c.numCalls >= c.minCalls\n}\n\n// Returns true if the maximum number of calls have been made.\nfunc (c *Call) exhausted() bool {\n\treturn c.numCalls >= c.maxCalls\n}\n\nfunc (c *Call) String() string {\n\targs := make([]string, len(c.args))\n\tfor i, arg := range c.args {\n\t\targs[i] = arg.String()\n\t}\n\targuments := strings.Join(args, \", \")\n\treturn fmt.Sprintf(\"%T.%v(%s) %s\", c.receiver, c.method, arguments, c.origin)\n}\n\n// Tests if the given call matches the expected call.\n// If yes, returns nil. If no, returns error with message explaining why it does not match.\nfunc (c *Call) matches(args []interface{}) error {\n\tif !c.methodType.IsVariadic() {\n\t\tif len(args) != len(c.args) {\n\t\t\treturn fmt.Errorf(\"expected call at %s has the wrong number of arguments. Got: %d, want: %d\",\n\t\t\t\tc.origin, len(args), len(c.args))\n\t\t}\n\n\t\tfor i, m := range c.args {\n\t\t\tif !m.Matches(args[i]) {\n\t\t\t\treturn fmt.Errorf(\n\t\t\t\t\t\"expected call at %s doesn't match the argument at index %d.\\nGot: %v\\nWant: %v\",\n\t\t\t\t\tc.origin, i, formatGottenArg(m, args[i]), m,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif len(c.args) < c.methodType.NumIn()-1 {\n\t\t\treturn fmt.Errorf(\"expected call at %s has the wrong number of matchers. Got: %d, want: %d\",\n\t\t\t\tc.origin, len(c.args), c.methodType.NumIn()-1)\n\t\t}\n\t\tif len(c.args) != c.methodType.NumIn() && len(args) != len(c.args) {\n\t\t\treturn fmt.Errorf(\"expected call at %s has the wrong number of arguments. Got: %d, want: %d\",\n\t\t\t\tc.origin, len(args), len(c.args))\n\t\t}\n\t\tif len(args) < len(c.args)-1 {\n\t\t\treturn fmt.Errorf(\"expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d\",\n\t\t\t\tc.origin, len(args), len(c.args)-1)\n\t\t}\n\n\t\tfor i, m := range c.args {\n\t\t\tif i < c.methodType.NumIn()-1 {\n\t\t\t\t// Non-variadic args\n\t\t\t\tif !m.Matches(args[i]) {\n\t\t\t\t\treturn fmt.Errorf(\"expected call at %s doesn't match the argument at index %s.\\nGot: %v\\nWant: %v\",\n\t\t\t\t\t\tc.origin, strconv.Itoa(i), formatGottenArg(m, args[i]), m)\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\t// The last arg has a possibility of a variadic argument, so let it branch\n\n\t\t\t// sample: Foo(a int, b int, c ...int)\n\t\t\tif i < len(c.args) && i < len(args) {\n\t\t\t\tif m.Matches(args[i]) {\n\t\t\t\t\t// Got Foo(a, b, c) want Foo(matcherA, matcherB, gomock.Any())\n\t\t\t\t\t// Got Foo(a, b, c) want Foo(matcherA, matcherB, someSliceMatcher)\n\t\t\t\t\t// Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC)\n\t\t\t\t\t// Got Foo(a, b) want Foo(matcherA, matcherB)\n\t\t\t\t\t// Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The number of actual args don't match the number of matchers,\n\t\t\t// or the last matcher is a slice and the last arg is not.\n\t\t\t// If this function still matches it is because the last matcher\n\t\t\t// matches all the remaining arguments or the lack of any.\n\t\t\t// Convert the remaining arguments, if any, into a slice of the\n\t\t\t// expected type.\n\t\t\tvArgsType := c.methodType.In(c.methodType.NumIn() - 1)\n\t\t\tvArgs := reflect.MakeSlice(vArgsType, 0, len(args)-i)\n\t\t\tfor _, arg := range args[i:] {\n\t\t\t\tvArgs = reflect.Append(vArgs, reflect.ValueOf(arg))\n\t\t\t}\n\t\t\tif m.Matches(vArgs.Interface()) {\n\t\t\t\t// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, gomock.Any())\n\t\t\t\t// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, someSliceMatcher)\n\t\t\t\t// Got Foo(a, b) want Foo(matcherA, matcherB, gomock.Any())\n\t\t\t\t// Got Foo(a, b) want Foo(matcherA, matcherB, someEmptySliceMatcher)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\t// Wrong number of matchers or not match. Fail.\n\t\t\t// Got Foo(a, b) want Foo(matcherA, matcherB, matcherC, matcherD)\n\t\t\t// Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC, matcherD)\n\t\t\t// Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD, matcherE)\n\t\t\t// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, matcherC, matcherD)\n\t\t\t// Got Foo(a, b, c) want Foo(matcherA, matcherB)\n\n\t\t\treturn fmt.Errorf(\"expected call at %s doesn't match the argument at index %s.\\nGot: %v\\nWant: %v\",\n\t\t\t\tc.origin, strconv.Itoa(i), formatGottenArg(m, args[i:]), c.args[i])\n\t\t}\n\t}\n\n\t// Check that all prerequisite calls have been satisfied.\n\tfor _, preReqCall := range c.preReqs {\n\t\tif !preReqCall.satisfied() {\n\t\t\treturn fmt.Errorf(\"expected call at %s doesn't have a prerequisite call satisfied:\\n%v\\nshould be called before:\\n%v\",\n\t\t\t\tc.origin, preReqCall, c)\n\t\t}\n\t}\n\n\t// Check that the call is not exhausted.\n\tif c.exhausted() {\n\t\treturn fmt.Errorf(\"expected call at %s has already been called the max number of times\", c.origin)\n\t}\n\n\treturn nil\n}\n\n// dropPrereqs tells the expected Call to not re-check prerequisite calls any\n// longer, and to return its current set.\nfunc (c *Call) dropPrereqs() (preReqs []*Call) {\n\tpreReqs = c.preReqs\n\tc.preReqs = nil\n\treturn\n}\n\nfunc (c *Call) call() []func([]interface{}) []interface{} {\n\tc.numCalls++\n\treturn c.actions\n}\n\n// InOrder declares that the given calls should occur in order.\nfunc InOrder(calls ...*Call) {\n\tfor i := 1; i < len(calls); i++ {\n\t\tcalls[i].After(calls[i-1])\n\t}\n}\n\nfunc setSlice(arg interface{}, v reflect.Value) {\n\tva := reflect.ValueOf(arg)\n\tfor i := 0; i < v.Len(); i++ {\n\t\tva.Index(i).Set(v.Index(i))\n\t}\n}\n\nfunc setMap(arg interface{}, v reflect.Value) {\n\tva := reflect.ValueOf(arg)\n\tfor _, e := range va.MapKeys() {\n\t\tva.SetMapIndex(e, reflect.Value{})\n\t}\n\tfor _, e := range v.MapKeys() {\n\t\tva.SetMapIndex(e, v.MapIndex(e))\n\t}\n}\n\nfunc (c *Call) addAction(action func([]interface{}) []interface{}) {\n\tc.actions = append(c.actions, action)\n}\n\nfunc formatGottenArg(m Matcher, arg interface{}) string {\n\tgot := fmt.Sprintf(\"%v (%T)\", arg, arg)\n\tif gs, ok := m.(GotFormatter); ok {\n\t\tgot = gs.Got(arg)\n\t}\n\treturn got\n}\n"
  },
  {
    "path": "gomock/call_test.go",
    "content": "// Copyright 2020 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage gomock\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n\t\"testing\"\n)\n\ntype foo struct{}\n\nfunc (f foo) String() string {\n\treturn \"meow\"\n}\n\ntype a struct {\n\tname string\n}\n\nfunc (testObj a) Name() string {\n\treturn testObj.name\n}\n\ntype b struct {\n\tfoo string\n}\n\nfunc (testObj b) Foo() string {\n\treturn testObj.foo\n}\n\ntype mockTestReporter struct {\n\terrorCalls int\n\tfatalCalls int\n}\n\nfunc (o *mockTestReporter) Errorf(format string, args ...interface{}) {\n\to.errorCalls++\n}\n\nfunc (o *mockTestReporter) Fatalf(format string, args ...interface{}) {\n\to.fatalCalls++\n}\n\nfunc (o *mockTestReporter) Helper() {}\n\nfunc TestCall_After(t *testing.T) {\n\tt.Run(\"SelfPrereqCallsFatalf\", func(t *testing.T) {\n\t\ttr1 := &mockTestReporter{}\n\n\t\tc := &Call{t: tr1}\n\t\tc.After(c)\n\n\t\tif tr1.fatalCalls != 1 {\n\t\t\tt.Errorf(\"number of fatal calls == %v, want 1\", tr1.fatalCalls)\n\t\t}\n\t})\n\n\tt.Run(\"LoopInCallOrderCallsFatalf\", func(t *testing.T) {\n\t\ttr1 := &mockTestReporter{}\n\t\ttr2 := &mockTestReporter{}\n\n\t\tc1 := &Call{t: tr1}\n\t\tc2 := &Call{t: tr2}\n\t\tc1.After(c2)\n\t\tc2.After(c1)\n\n\t\tif tr1.errorCalls != 0 || tr1.fatalCalls != 0 {\n\t\t\tt.Error(\"unexpected errors\")\n\t\t}\n\n\t\tif tr2.fatalCalls != 1 {\n\t\t\tt.Errorf(\"number of fatal calls == %v, want 1\", tr2.fatalCalls)\n\t\t}\n\t})\n}\n\nfunc prepareDoCall(doFunc, callFunc interface{}) *Call {\n\ttr := &mockTestReporter{}\n\n\tc := &Call{\n\t\tt:          tr,\n\t\tmethodType: reflect.TypeOf(callFunc),\n\t}\n\n\tc.Do(doFunc)\n\n\treturn c\n}\n\nfunc prepareDoAndReturnCall(doFunc, callFunc interface{}) *Call {\n\ttr := &mockTestReporter{}\n\n\tc := &Call{\n\t\tt:          tr,\n\t\tmethodType: reflect.TypeOf(callFunc),\n\t}\n\n\tc.DoAndReturn(doFunc)\n\n\treturn c\n}\n\ntype testCase struct {\n\tdescription string\n\tdoFunc      interface{}\n\tcallFunc    interface{}\n\targs        []interface{}\n\texpectPanic bool\n}\n\nvar testCases []testCase = []testCase{\n\t{\n\t\tdescription: \"argument to Do is not a function\",\n\t\tdoFunc:      \"meow\",\n\t\tcallFunc:    func(x int, y int) {},\n\t\targs:        []interface{}{0, 1},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"argument to Do is not a function\",\n\t\tdoFunc:      \"meow\",\n\t\tcallFunc: func(x int, y int) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{0, 1},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"number of args for Do func don't match Call func\",\n\t\tdoFunc:      func(x int) {},\n\t\tcallFunc:    func(x int, y int) {},\n\t\targs:        []interface{}{0, 1},\n\t\texpectPanic: false,\n\t}, {\n\t\tdescription: \"number of args for Do func don't match Call func\",\n\t\tdoFunc: func(x int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x int, y int) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{0, 1},\n\t\texpectPanic: false,\n\t}, {\n\t\tdescription: \"arg type for Do func incompatible with Call func\",\n\t\tdoFunc:      func(x int) {},\n\t\tcallFunc:    func(x string) {},\n\t\targs:        []interface{}{\"meow\"},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"arg type for Do func incompatible with Call func\",\n\t\tdoFunc: func(x int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x string) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{\"meow\"},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(int) Call func(int)\",\n\t\tdoFunc:      func(x int) {},\n\t\tcallFunc:    func(x int) {},\n\t\targs:        []interface{}{0},\n\t}, {\n\t\tdescription: \"Do func(int) Call func(interface{})\",\n\t\tdoFunc:      func(x int) {},\n\t\tcallFunc:    func(x interface{}) {},\n\t\targs:        []interface{}{0},\n\t}, {\n\t\tdescription: \"Do func(int) bool Call func(int) bool\",\n\t\tdoFunc: func(x int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x int) bool {\n\t\t\treturn true\n\t\t},\n\t\targs: []interface{}{0},\n\t}, {\n\t\tdescription: \"Do func(int) bool Call func(interface{}) bool\",\n\t\tdoFunc: func(x int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x interface{}) bool {\n\t\t\treturn true\n\t\t},\n\t\targs: []interface{}{0},\n\t}, {\n\t\tdescription: \"Do func(string) Call func([]byte)\",\n\t\tdoFunc:      func(x string) {},\n\t\tcallFunc:    func(x []byte) {},\n\t\targs:        []interface{}{[]byte(\"meow\")},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(string) bool Call func([]byte) bool\",\n\t\tdoFunc: func(x string) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x []byte) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{[]byte(\"meow\")},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(map[int]string) Call func(map[interface{}]int)\",\n\t\tdoFunc:      func(x map[int]string) {},\n\t\tcallFunc:    func(x map[interface{}]int) {},\n\t\targs:        []interface{}{map[interface{}]int{\"meow\": 0}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(map[int]string) Call func(map[interface{}]interface{})\",\n\t\tdoFunc:      func(x map[int]string) {},\n\t\tcallFunc:    func(x map[interface{}]interface{}) {},\n\t\targs:        []interface{}{map[interface{}]interface{}{\"meow\": \"meow\"}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(map[int]string) bool Call func(map[interface{}]int) bool\",\n\t\tdoFunc: func(x map[int]string) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x map[interface{}]int) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{map[interface{}]int{\"meow\": 0}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(map[int]string) bool Call func(map[interface{}]interface{}) bool\",\n\t\tdoFunc: func(x map[int]string) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x map[interface{}]interface{}) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{map[interface{}]interface{}{\"meow\": \"meow\"}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]string) Call func([]interface{})\",\n\t\tdoFunc:      func(x []string) {},\n\t\tcallFunc:    func(x []interface{}) {},\n\t\targs:        []interface{}{[]interface{}{0}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]string) Call func([]int)\",\n\t\tdoFunc:      func(x []string) {},\n\t\tcallFunc:    func(x []int) {},\n\t\targs:        []interface{}{[]int{0, 1}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]int) Call func([]int)\",\n\t\tdoFunc:      func(x []int) {},\n\t\tcallFunc:    func(x []int) {},\n\t\targs:        []interface{}{[]int{0, 1}},\n\t}, {\n\t\tdescription: \"Do func([]int) Call func([]interface{})\",\n\t\tdoFunc:      func(x []int) {},\n\t\tcallFunc:    func(x []interface{}) {},\n\t\targs:        []interface{}{[]interface{}{0}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]int) Call func(...interface{})\",\n\t\tdoFunc:      func(x []int) {},\n\t\tcallFunc:    func(x ...interface{}) {},\n\t\targs:        []interface{}{0, 1},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]int) Call func(...int)\",\n\t\tdoFunc:      func(x []int) {},\n\t\tcallFunc:    func(x ...int) {},\n\t\targs:        []interface{}{0, 1},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]string) bool Call func([]interface{}) bool\",\n\t\tdoFunc: func(x []string) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x []interface{}) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{[]interface{}{0}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]string) bool Call func([]int) bool\",\n\t\tdoFunc: func(x []string) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x []int) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{[]int{0, 1}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]int) bool Call func([]int) bool\",\n\t\tdoFunc: func(x []int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x []int) bool {\n\t\t\treturn true\n\t\t},\n\t\targs: []interface{}{[]int{0, 1}},\n\t}, {\n\t\tdescription: \"Do func([]int) bool Call func([]interface{}) bool\",\n\t\tdoFunc: func(x []int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x []interface{}) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{[]interface{}{0}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]int) bool Call func(...interface{}) bool\",\n\t\tdoFunc: func(x []int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x ...interface{}) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{0, 1},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func([]int) bool Call func(...int) bool\",\n\t\tdoFunc: func(x []int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x ...int) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{0, 1},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(...int) Call func([]int)\",\n\t\tdoFunc:      func(x ...int) {},\n\t\tcallFunc:    func(x []int) {},\n\t\targs:        []interface{}{[]int{0, 1}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(...int) Call func([]interface{})\",\n\t\tdoFunc:      func(x ...int) {},\n\t\tcallFunc:    func(x []interface{}) {},\n\t\targs:        []interface{}{[]interface{}{0, 1}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(...int) Call func(...interface{})\",\n\t\tdoFunc:      func(x ...int) {},\n\t\tcallFunc:    func(x ...interface{}) {},\n\t\targs:        []interface{}{0, 1},\n\t}, {\n\t\tdescription: \"Do func(...int) bool Call func(...int) bool\",\n\t\tdoFunc: func(x ...int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x ...int) bool {\n\t\t\treturn true\n\t\t},\n\t\targs: []interface{}{0, 1},\n\t}, {\n\t\tdescription: \"Do func(...int) bool Call func([]int) bool\",\n\t\tdoFunc: func(x ...int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x []int) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{[]int{0, 1}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(...int) bool Call func([]interface{}) bool\",\n\t\tdoFunc: func(x ...int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x []interface{}) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{[]interface{}{0, 1}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(...int) bool Call func(...interface{}) bool\",\n\t\tdoFunc: func(x ...int) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x ...interface{}) bool {\n\t\t\treturn true\n\t\t},\n\t\targs: []interface{}{0, 1},\n\t}, {\n\t\tdescription: \"Do func(...int) Call func(...int)\",\n\t\tdoFunc:      func(x ...int) {},\n\t\tcallFunc:    func(x ...int) {},\n\t\targs:        []interface{}{0, 1},\n\t}, {\n\t\tdescription: \"Do func(foo); foo implements interface X Call func(interface X)\",\n\t\tdoFunc:      func(x foo) {},\n\t\tcallFunc:    func(x fmt.Stringer) {},\n\t\targs:        []interface{}{foo{}},\n\t}, {\n\t\tdescription: \"Do func(b); b does not implement interface X Call func(interface X)\",\n\t\tdoFunc:      func(x b) {},\n\t\tcallFunc:    func(x fmt.Stringer) {},\n\t\targs:        []interface{}{foo{}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(b) Call func(a); a and b are not aliases\",\n\t\tdoFunc:      func(x b) {},\n\t\tcallFunc:    func(x a) {},\n\t\targs:        []interface{}{a{}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(foo) bool; foo implements interface X Call func(interface X) bool\",\n\t\tdoFunc: func(x foo) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x fmt.Stringer) bool {\n\t\t\treturn true\n\t\t},\n\t\targs: []interface{}{foo{}},\n\t}, {\n\t\tdescription: \"Do func(b) bool; b does not implement interface X Call func(interface X) bool\",\n\t\tdoFunc: func(x b) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x fmt.Stringer) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{foo{}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(b) bool Call func(a) bool; a and b are not aliases\",\n\t\tdoFunc: func(x b) bool {\n\t\t\treturn true\n\t\t},\n\t\tcallFunc: func(x a) bool {\n\t\t\treturn true\n\t\t},\n\t\targs:        []interface{}{a{}},\n\t\texpectPanic: true,\n\t}, {\n\t\tdescription: \"Do func(bool) b Call func(bool) a; a and b are not aliases\",\n\t\tdoFunc: func(x bool) b {\n\t\t\treturn b{}\n\t\t},\n\t\tcallFunc: func(x bool) a {\n\t\t\treturn a{}\n\t\t},\n\t\targs: []interface{}{true},\n\t},\n}\n\nfunc TestCall_Do(t *testing.T) {\n\tfor _, tc := range testCases {\n\t\tt.Run(tc.description, func(t *testing.T) {\n\t\t\tc := prepareDoCall(tc.doFunc, tc.callFunc)\n\n\t\t\tif len(c.actions) != 1 {\n\t\t\t\tt.Errorf(\"expected %d actions but got %d\", 1, len(c.actions))\n\t\t\t}\n\n\t\t\taction := c.actions[0]\n\n\t\t\tif tc.expectPanic {\n\t\t\t\tdefer func() {\n\t\t\t\t\tif r := recover(); r == nil {\n\t\t\t\t\t\tt.Error(\"expected Do to panic\")\n\t\t\t\t\t}\n\t\t\t\t}()\n\t\t\t}\n\n\t\t\taction(tc.args)\n\t\t})\n\t}\n}\n\nfunc TestCall_Do_NumArgValidation(t *testing.T) {\n\ttests := []struct {\n\t\tname       string\n\t\tmethodType reflect.Type\n\t\tdoFn       interface{}\n\t\targs       []interface{}\n\t\twantErr    bool\n\t}{\n\t\t{\n\t\t\tname:       \"too few\",\n\t\t\tmethodType: reflect.TypeOf(func(one, two string) {}),\n\t\t\tdoFn:       func(one string) {},\n\t\t\targs:       []interface{}{\"too\", \"few\"},\n\t\t\twantErr:    true,\n\t\t},\n\t\t{\n\t\t\tname:       \"too many\",\n\t\t\tmethodType: reflect.TypeOf(func(one, two string) {}),\n\t\t\tdoFn:       func(one, two, three string) {},\n\t\t\targs:       []interface{}{\"too\", \"few\"},\n\t\t\twantErr:    true,\n\t\t},\n\t\t{\n\t\t\tname:       \"just right\",\n\t\t\tmethodType: reflect.TypeOf(func(one, two string) {}),\n\t\t\tdoFn:       func(one string, two string) {},\n\t\t\targs:       []interface{}{\"just\", \"right\"},\n\t\t\twantErr:    false,\n\t\t},\n\t\t{\n\t\t\tname:       \"variadic\",\n\t\t\tmethodType: reflect.TypeOf(func(one, two string) {}),\n\t\t\tdoFn:       func(args ...interface{}) {},\n\t\t\targs:       []interface{}{\"just\", \"right\"},\n\t\t\twantErr:    true,\n\t\t},\n\t}\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\ttr := &mockTestReporter{}\n\t\t\tcall := &Call{\n\t\t\t\tt:          tr,\n\t\t\t\tmethodType: tt.methodType,\n\t\t\t}\n\t\t\tcall.Do(tt.doFn)\n\t\t\tcall.actions[0](tt.args)\n\t\t\tif tt.wantErr && tr.fatalCalls != 1 {\n\t\t\t\tt.Fatalf(\"expected call to fail\")\n\t\t\t}\n\t\t\tif !tt.wantErr && tr.fatalCalls != 0 {\n\t\t\t\tt.Fatalf(\"expected call to pass\")\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestCall_DoAndReturn_NumArgValidation(t *testing.T) {\n\ttests := []struct {\n\t\tname       string\n\t\tmethodType reflect.Type\n\t\tdoFn       interface{}\n\t\targs       []interface{}\n\t\twantErr    bool\n\t}{\n\t\t{\n\t\t\tname:       \"too few\",\n\t\t\tmethodType: reflect.TypeOf(func(one, two string) string { return \"\" }),\n\t\t\tdoFn:       func(one string) {},\n\t\t\targs:       []interface{}{\"too\", \"few\"},\n\t\t\twantErr:    true,\n\t\t},\n\t\t{\n\t\t\tname:       \"too many\",\n\t\t\tmethodType: reflect.TypeOf(func(one, two string) string { return \"\" }),\n\t\t\tdoFn:       func(one, two, three string) string { return \"\" },\n\t\t\targs:       []interface{}{\"too\", \"few\"},\n\t\t\twantErr:    true,\n\t\t},\n\t\t{\n\t\t\tname:       \"just right\",\n\t\t\tmethodType: reflect.TypeOf(func(one, two string) string { return \"\" }),\n\t\t\tdoFn:       func(one string, two string) string { return \"\" },\n\t\t\targs:       []interface{}{\"just\", \"right\"},\n\t\t\twantErr:    false,\n\t\t},\n\t\t{\n\t\t\tname:       \"variadic\",\n\t\t\tmethodType: reflect.TypeOf(func(one, two string) {}),\n\t\t\tdoFn:       func(args ...interface{}) string { return \"\" },\n\t\t\targs:       []interface{}{\"just\", \"right\"},\n\t\t\twantErr:    true,\n\t\t},\n\t}\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\ttr := &mockTestReporter{}\n\t\t\tcall := &Call{\n\t\t\t\tt:          tr,\n\t\t\t\tmethodType: tt.methodType,\n\t\t\t}\n\t\t\tcall.DoAndReturn(tt.doFn)\n\t\t\tcall.actions[0](tt.args)\n\t\t\tif tt.wantErr && tr.fatalCalls != 1 {\n\t\t\t\tt.Fatalf(\"expected call to fail\")\n\t\t\t}\n\t\t\tif !tt.wantErr && tr.fatalCalls != 0 {\n\t\t\t\tt.Fatalf(\"expected call to pass\")\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestCall_DoAndReturn(t *testing.T) {\n\tfor _, tc := range testCases {\n\t\tt.Run(tc.description, func(t *testing.T) {\n\t\t\tc := prepareDoAndReturnCall(tc.doFunc, tc.callFunc)\n\n\t\t\tif len(c.actions) != 1 {\n\t\t\t\tt.Errorf(\"expected %d actions but got %d\", 1, len(c.actions))\n\t\t\t}\n\n\t\t\taction := c.actions[0]\n\n\t\t\tif tc.expectPanic {\n\t\t\t\tdefer func() {\n\t\t\t\t\tif r := recover(); r == nil {\n\t\t\t\t\t\tt.Error(\"expected DoAndReturn to panic\")\n\t\t\t\t\t}\n\t\t\t\t}()\n\t\t\t}\n\n\t\t\taction(tc.args)\n\t\t})\n\t}\n}\n"
  },
  {
    "path": "gomock/callset.go",
    "content": "// Copyright 2011 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage gomock\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n\t\"fmt\"\n)\n\n// callSet represents a set of expected calls, indexed by receiver and method\n// name.\ntype callSet struct {\n\t// Calls that are still expected.\n\texpected map[callSetKey][]*Call\n\t// Calls that have been exhausted.\n\texhausted map[callSetKey][]*Call\n}\n\n// callSetKey is the key in the maps in callSet\ntype callSetKey struct {\n\treceiver interface{}\n\tfname    string\n}\n\nfunc newCallSet() *callSet {\n\treturn &callSet{make(map[callSetKey][]*Call), make(map[callSetKey][]*Call)}\n}\n\n// Add adds a new expected call.\nfunc (cs callSet) Add(call *Call) {\n\tkey := callSetKey{call.receiver, call.method}\n\tm := cs.expected\n\tif call.exhausted() {\n\t\tm = cs.exhausted\n\t}\n\tm[key] = append(m[key], call)\n}\n\n// Remove removes an expected call.\nfunc (cs callSet) Remove(call *Call) {\n\tkey := callSetKey{call.receiver, call.method}\n\tcalls := cs.expected[key]\n\tfor i, c := range calls {\n\t\tif c == call {\n\t\t\t// maintain order for remaining calls\n\t\t\tcs.expected[key] = append(calls[:i], calls[i+1:]...)\n\t\t\tcs.exhausted[key] = append(cs.exhausted[key], call)\n\t\t\tbreak\n\t\t}\n\t}\n}\n\n// FindMatch searches for a matching call. Returns error with explanation message if no call matched.\nfunc (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) {\n\tkey := callSetKey{receiver, method}\n\n\t// Search through the expected calls.\n\texpected := cs.expected[key]\n\tvar callsErrors bytes.Buffer\n\tfor _, call := range expected {\n\t\terr := call.matches(args)\n\t\tif err != nil {\n\t\t\t_, _ = fmt.Fprintf(&callsErrors, \"\\n%v\", err)\n\t\t} else {\n\t\t\treturn call, nil\n\t\t}\n\t}\n\n\t// If we haven't found a match then search through the exhausted calls so we\n\t// get useful error messages.\n\texhausted := cs.exhausted[key]\n\tfor _, call := range exhausted {\n\t\tif err := call.matches(args); err != nil {\n\t\t\t_, _ = fmt.Fprintf(&callsErrors, \"\\n%v\", err)\n\t\t\tcontinue\n\t\t}\n\t\t_, _ = fmt.Fprintf(\n\t\t\t&callsErrors, \"all expected calls for method %q have been exhausted\", method,\n\t\t)\n\t}\n\n\tif len(expected)+len(exhausted) == 0 {\n\t\t_, _ = fmt.Fprintf(&callsErrors, \"there are no expected calls of the method %q for that receiver\", method)\n\t}\n\n\treturn nil, errors.New(callsErrors.String())\n}\n\n// Failures returns the calls that are not satisfied.\nfunc (cs callSet) Failures() []*Call {\n\tfailures := make([]*Call, 0, len(cs.expected))\n\tfor _, calls := range cs.expected {\n\t\tfor _, call := range calls {\n\t\t\tif !call.satisfied() {\n\t\t\t\tfailures = append(failures, call)\n\t\t\t}\n\t\t}\n\t}\n\treturn failures\n}\n"
  },
  {
    "path": "gomock/callset_test.go",
    "content": "// Copyright 2011 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage gomock\n\nimport (\n\t\"reflect\"\n\t\"testing\"\n)\n\ntype receiverType struct{}\n\nfunc (receiverType) Func() {}\n\nfunc TestCallSetAdd(t *testing.T) {\n\tmethod := \"TestMethod\"\n\tvar receiver interface{} = \"TestReceiver\"\n\tcs := newCallSet()\n\n\tnumCalls := 10\n\tfor i := 0; i < numCalls; i++ {\n\t\tcs.Add(newCall(t, receiver, method, reflect.TypeOf(receiverType{}.Func)))\n\t}\n\n\tcall, err := cs.FindMatch(receiver, method, []interface{}{})\n\tif err != nil {\n\t\tt.Fatalf(\"FindMatch: %v\", err)\n\t}\n\tif call == nil {\n\t\tt.Fatalf(\"FindMatch: Got nil, want non-nil *Call\")\n\t}\n}\n\nfunc TestCallSetRemove(t *testing.T) {\n\tmethod := \"TestMethod\"\n\tvar receiver interface{} = \"TestReceiver\"\n\n\tcs := newCallSet()\n\tourCalls := []*Call{}\n\n\tnumCalls := 10\n\tfor i := 0; i < numCalls; i++ {\n\t\t// NOTE: abuse the `numCalls` value to convey initial ordering of mocked calls\n\t\tgeneratedCall := &Call{receiver: receiver, method: method, numCalls: i}\n\t\tcs.Add(generatedCall)\n\t\tourCalls = append(ourCalls, generatedCall)\n\t}\n\n\t// validateOrder validates that the calls in the array are ordered as they were added\n\tvalidateOrder := func(calls []*Call) {\n\t\t// lastNum tracks the last `numCalls` (call order) value seen\n\t\tlastNum := -1\n\t\tfor _, c := range calls {\n\t\t\tif lastNum >= c.numCalls {\n\t\t\t\tt.Errorf(\"found call %d after call %d\", c.numCalls, lastNum)\n\t\t\t}\n\t\t\tlastNum = c.numCalls\n\t\t}\n\t}\n\n\tfor _, c := range ourCalls {\n\t\tvalidateOrder(cs.expected[callSetKey{receiver, method}])\n\t\tcs.Remove(c)\n\t}\n}\n\nfunc TestCallSetFindMatch(t *testing.T) {\n\tt.Run(\"call is exhausted\", func(t *testing.T) {\n\t\tcs := callSet{}\n\t\tvar receiver interface{} = \"TestReceiver\"\n\t\tmethod := \"TestMethod\"\n\t\targs := []interface{}{}\n\n\t\tc1 := newCall(t, receiver, method, reflect.TypeOf(receiverType{}.Func))\n\t\tcs.exhausted = map[callSetKey][]*Call{\n\t\t\t{receiver: receiver, fname: method}: {c1},\n\t\t}\n\n\t\t_, err := cs.FindMatch(receiver, method, args)\n\t\tif err == nil {\n\t\t\tt.Fatal(\"expected error, but was nil\")\n\t\t}\n\n\t\tif err.Error() == \"\" {\n\t\t\tt.Fatal(\"expected error to have message, but was empty\")\n\t\t}\n\t})\n}\n"
  },
  {
    "path": "gomock/controller.go",
    "content": "// Copyright 2010 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage gomock\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"reflect\"\n\t\"runtime\"\n\t\"sync\"\n)\n\n// A TestReporter is something that can be used to report test failures.  It\n// is satisfied by the standard library's *testing.T.\ntype TestReporter interface {\n\tErrorf(format string, args ...interface{})\n\tFatalf(format string, args ...interface{})\n}\n\n// TestHelper is a TestReporter that has the Helper method.  It is satisfied\n// by the standard library's *testing.T.\ntype TestHelper interface {\n\tTestReporter\n\tHelper()\n}\n\n// cleanuper is used to check if TestHelper also has the `Cleanup` method. A\n// common pattern is to pass in a `*testing.T` to\n// `NewController(t TestReporter)`. In Go 1.14+, `*testing.T` has a cleanup\n// method. This can be utilized to call `Finish()` so the caller of this library\n// does not have to.\ntype cleanuper interface {\n\tCleanup(func())\n}\n\n// A Controller represents the top-level control of a mock ecosystem.  It\n// defines the scope and lifetime of mock objects, as well as their\n// expectations.  It is safe to call Controller's methods from multiple\n// goroutines. Each test should create a new Controller and invoke Finish via\n// defer.\n//\n//   func TestFoo(t *testing.T) {\n//     ctrl := gomock.NewController(t)\n//     defer ctrl.Finish()\n//     // ..\n//   }\n//\n//   func TestBar(t *testing.T) {\n//     t.Run(\"Sub-Test-1\", st) {\n//       ctrl := gomock.NewController(st)\n//       defer ctrl.Finish()\n//       // ..\n//     })\n//     t.Run(\"Sub-Test-2\", st) {\n//       ctrl := gomock.NewController(st)\n//       defer ctrl.Finish()\n//       // ..\n//     })\n//   })\ntype Controller struct {\n\t// T should only be called within a generated mock. It is not intended to\n\t// be used in user code and may be changed in future versions. T is the\n\t// TestReporter passed in when creating the Controller via NewController.\n\t// If the TestReporter does not implement a TestHelper it will be wrapped\n\t// with a nopTestHelper.\n\tT             TestHelper\n\tmu            sync.Mutex\n\texpectedCalls *callSet\n\tfinished      bool\n}\n\n// NewController returns a new Controller. It is the preferred way to create a\n// Controller.\n//\n// New in go1.14+, if you are passing a *testing.T into this function you no\n// longer need to call ctrl.Finish() in your test methods.\nfunc NewController(t TestReporter) *Controller {\n\th, ok := t.(TestHelper)\n\tif !ok {\n\t\th = &nopTestHelper{t}\n\t}\n\tctrl := &Controller{\n\t\tT:             h,\n\t\texpectedCalls: newCallSet(),\n\t}\n\tif c, ok := isCleanuper(ctrl.T); ok {\n\t\tc.Cleanup(func() {\n\t\t\tctrl.T.Helper()\n\t\t\tctrl.finish(true, nil)\n\t\t})\n\t}\n\n\treturn ctrl\n}\n\ntype cancelReporter struct {\n\tt      TestHelper\n\tcancel func()\n}\n\nfunc (r *cancelReporter) Errorf(format string, args ...interface{}) {\n\tr.t.Errorf(format, args...)\n}\nfunc (r *cancelReporter) Fatalf(format string, args ...interface{}) {\n\tdefer r.cancel()\n\tr.t.Fatalf(format, args...)\n}\n\nfunc (r *cancelReporter) Helper() {\n\tr.t.Helper()\n}\n\n// WithContext returns a new Controller and a Context, which is cancelled on any\n// fatal failure.\nfunc WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) {\n\th, ok := t.(TestHelper)\n\tif !ok {\n\t\th = &nopTestHelper{t: t}\n\t}\n\n\tctx, cancel := context.WithCancel(ctx)\n\treturn NewController(&cancelReporter{t: h, cancel: cancel}), ctx\n}\n\ntype nopTestHelper struct {\n\tt TestReporter\n}\n\nfunc (h *nopTestHelper) Errorf(format string, args ...interface{}) {\n\th.t.Errorf(format, args...)\n}\nfunc (h *nopTestHelper) Fatalf(format string, args ...interface{}) {\n\th.t.Fatalf(format, args...)\n}\n\nfunc (h nopTestHelper) Helper() {}\n\n// RecordCall is called by a mock. It should not be called by user code.\nfunc (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call {\n\tctrl.T.Helper()\n\n\trecv := reflect.ValueOf(receiver)\n\tfor i := 0; i < recv.Type().NumMethod(); i++ {\n\t\tif recv.Type().Method(i).Name == method {\n\t\t\treturn ctrl.RecordCallWithMethodType(receiver, method, recv.Method(i).Type(), args...)\n\t\t}\n\t}\n\tctrl.T.Fatalf(\"gomock: failed finding method %s on %T\", method, receiver)\n\tpanic(\"unreachable\")\n}\n\n// RecordCallWithMethodType is called by a mock. It should not be called by user code.\nfunc (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {\n\tctrl.T.Helper()\n\n\tcall := newCall(ctrl.T, receiver, method, methodType, args...)\n\n\tctrl.mu.Lock()\n\tdefer ctrl.mu.Unlock()\n\tctrl.expectedCalls.Add(call)\n\n\treturn call\n}\n\n// Call is called by a mock. It should not be called by user code.\nfunc (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} {\n\tctrl.T.Helper()\n\n\t// Nest this code so we can use defer to make sure the lock is released.\n\tactions := func() []func([]interface{}) []interface{} {\n\t\tctrl.T.Helper()\n\t\tctrl.mu.Lock()\n\t\tdefer ctrl.mu.Unlock()\n\n\t\texpected, err := ctrl.expectedCalls.FindMatch(receiver, method, args)\n\t\tif err != nil {\n\t\t\t// callerInfo's skip should be updated if the number of calls between the user's test\n\t\t\t// and this line changes, i.e. this code is wrapped in another anonymous function.\n\t\t\t// 0 is us, 1 is controller.Call(), 2 is the generated mock, and 3 is the user's test.\n\t\t\torigin := callerInfo(3)\n\t\t\tctrl.T.Fatalf(\"Unexpected call to %T.%v(%v) at %s because: %s\", receiver, method, args, origin, err)\n\t\t}\n\n\t\t// Two things happen here:\n\t\t// * the matching call no longer needs to check prerequite calls,\n\t\t// * and the prerequite calls are no longer expected, so remove them.\n\t\tpreReqCalls := expected.dropPrereqs()\n\t\tfor _, preReqCall := range preReqCalls {\n\t\t\tctrl.expectedCalls.Remove(preReqCall)\n\t\t}\n\n\t\tactions := expected.call()\n\t\tif expected.exhausted() {\n\t\t\tctrl.expectedCalls.Remove(expected)\n\t\t}\n\t\treturn actions\n\t}()\n\n\tvar rets []interface{}\n\tfor _, action := range actions {\n\t\tif r := action(args); r != nil {\n\t\t\trets = r\n\t\t}\n\t}\n\n\treturn rets\n}\n\n// Finish checks to see if all the methods that were expected to be called\n// were called. It should be invoked for each Controller. It is not idempotent\n// and therefore can only be invoked once.\n//\n// New in go1.14+, if you are passing a *testing.T into NewController function you no\n// longer need to call ctrl.Finish() in your test methods.\nfunc (ctrl *Controller) Finish() {\n\t// If we're currently panicking, probably because this is a deferred call.\n\t// This must be recovered in the deferred function.\n\terr := recover()\n\tctrl.finish(false, err)\n}\n\nfunc (ctrl *Controller) finish(cleanup bool, panicErr interface{}) {\n\tctrl.T.Helper()\n\n\tctrl.mu.Lock()\n\tdefer ctrl.mu.Unlock()\n\n\tif ctrl.finished {\n\t\tif _, ok := isCleanuper(ctrl.T); !ok {\n\t\t\tctrl.T.Fatalf(\"Controller.Finish was called more than once. It has to be called exactly once.\")\n\t\t}\n\t\treturn\n\t}\n\tctrl.finished = true\n\n\t// Short-circuit, pass through the panic.\n\tif panicErr != nil {\n\t\tpanic(panicErr)\n\t}\n\n\t// Check that all remaining expected calls are satisfied.\n\tfailures := ctrl.expectedCalls.Failures()\n\tfor _, call := range failures {\n\t\tctrl.T.Errorf(\"missing call(s) to %v\", call)\n\t}\n\tif len(failures) != 0 {\n\t\tif !cleanup {\n\t\t\tctrl.T.Fatalf(\"aborting test due to missing call(s)\")\n\t\t\treturn\n\t\t}\n\t\tctrl.T.Errorf(\"aborting test due to missing call(s)\")\n\t}\n}\n\n// callerInfo returns the file:line of the call site. skip is the number\n// of stack frames to skip when reporting. 0 is callerInfo's call site.\nfunc callerInfo(skip int) string {\n\tif _, file, line, ok := runtime.Caller(skip + 1); ok {\n\t\treturn fmt.Sprintf(\"%s:%d\", file, line)\n\t}\n\treturn \"unknown file\"\n}\n\n// isCleanuper checks it if t's base TestReporter has a Cleanup method.\nfunc isCleanuper(t TestReporter) (cleanuper, bool) {\n\ttr := unwrapTestReporter(t)\n\tc, ok := tr.(cleanuper)\n\treturn c, ok\n}\n\n// unwrapTestReporter unwraps TestReporter to the base implementation.\nfunc unwrapTestReporter(t TestReporter) TestReporter {\n\ttr := t\n\tswitch nt := t.(type) {\n\tcase *cancelReporter:\n\t\ttr = nt.t\n\t\tif h, check := tr.(*nopTestHelper); check {\n\t\t\ttr = h.t\n\t\t}\n\tcase *nopTestHelper:\n\t\ttr = nt.t\n\tdefault:\n\t\t// not wrapped\n\t}\n\treturn tr\n}\n"
  },
  {
    "path": "gomock/controller_test.go",
    "content": "// Copyright 2011 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage gomock_test\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n\t\"testing\"\n\n\t\"strings\"\n\n\t\"github.com/golang/mock/gomock\"\n)\n\ntype ErrorReporter struct {\n\tt          *testing.T\n\tlog        []string\n\tfailed     bool\n\tfatalToken struct{}\n}\n\nfunc NewErrorReporter(t *testing.T) *ErrorReporter {\n\treturn &ErrorReporter{t: t}\n}\n\nfunc (e *ErrorReporter) reportLog() {\n\tfor _, entry := range e.log {\n\t\te.t.Log(entry)\n\t}\n}\n\nfunc (e *ErrorReporter) assertPass(msg string) {\n\tif e.failed {\n\t\te.t.Errorf(\"Expected pass, but got failure(s): %s\", msg)\n\t\te.reportLog()\n\t}\n}\n\nfunc (e *ErrorReporter) assertFail(msg string) {\n\tif !e.failed {\n\t\te.t.Errorf(\"Expected failure, but got pass: %s\", msg)\n\t}\n}\n\n// Use to check that code triggers a fatal test failure.\nfunc (e *ErrorReporter) assertFatal(fn func(), expectedErrMsgs ...string) {\n\tdefer func() {\n\t\terr := recover()\n\t\tif err == nil {\n\t\t\tvar actual string\n\t\t\tif e.failed {\n\t\t\t\tactual = \"non-fatal failure\"\n\t\t\t} else {\n\t\t\t\tactual = \"pass\"\n\t\t\t}\n\t\t\te.t.Error(\"Expected fatal failure, but got a\", actual)\n\t\t} else if token, ok := err.(*struct{}); ok && token == &e.fatalToken {\n\t\t\t// This is okay - the panic is from Fatalf().\n\t\t\tif expectedErrMsgs != nil {\n\t\t\t\t// assert that the actual error message\n\t\t\t\t// contains expectedErrMsgs\n\n\t\t\t\t// check the last actualErrMsg, because the previous messages come from previous errors\n\t\t\t\tactualErrMsg := e.log[len(e.log)-1]\n\t\t\t\tfor _, expectedErrMsg := range expectedErrMsgs {\n\t\t\t\t\tif !strings.Contains(actualErrMsg, expectedErrMsg) {\n\t\t\t\t\t\te.t.Errorf(\"Error message:\\ngot: %q\\nwant to contain: %q\\n\", actualErrMsg, expectedErrMsg)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn\n\t\t} else {\n\t\t\t// Some other panic.\n\t\t\tpanic(err)\n\t\t}\n\t}()\n\n\tfn()\n}\n\n// recoverUnexpectedFatal can be used as a deferred call in test cases to\n// recover from and display a call to ErrorReporter.Fatalf().\nfunc (e *ErrorReporter) recoverUnexpectedFatal() {\n\terr := recover()\n\tif err == nil {\n\t\t// No panic.\n\t} else if token, ok := err.(*struct{}); ok && token == &e.fatalToken {\n\t\t// Unexpected fatal error happened.\n\t\te.t.Error(\"Got unexpected fatal error(s). All errors up to this point:\")\n\t\te.reportLog()\n\t\treturn\n\t} else {\n\t\t// Some other panic.\n\t\tpanic(err)\n\t}\n}\n\nfunc (e *ErrorReporter) Log(args ...interface{}) {\n\te.log = append(e.log, fmt.Sprint(args...))\n}\n\nfunc (e *ErrorReporter) Logf(format string, args ...interface{}) {\n\te.log = append(e.log, fmt.Sprintf(format, args...))\n}\n\nfunc (e *ErrorReporter) Errorf(format string, args ...interface{}) {\n\te.Logf(format, args...)\n\te.failed = true\n}\n\nfunc (e *ErrorReporter) Fatalf(format string, args ...interface{}) {\n\te.Logf(format, args...)\n\te.failed = true\n\tpanic(&e.fatalToken)\n}\n\ntype HelperReporter struct {\n\tgomock.TestReporter\n\thelper int\n}\n\nfunc (h *HelperReporter) Helper() {\n\th.helper++\n}\n\n// A type purely for use as a receiver in testing the Controller.\ntype Subject struct{}\n\nfunc (s *Subject) FooMethod(arg string) int {\n\treturn 0\n}\n\nfunc (s *Subject) BarMethod(arg string) int {\n\treturn 0\n}\n\nfunc (s *Subject) VariadicMethod(arg int, vararg ...string) {}\n\n// A type purely for ActOnTestStructMethod\ntype TestStruct struct {\n\tNumber  int\n\tMessage string\n}\n\nfunc (s *Subject) ActOnTestStructMethod(arg TestStruct, arg1 int) int {\n\treturn 0\n}\n\nfunc (s *Subject) SetArgMethod(sliceArg []byte, ptrArg *int, mapArg map[interface{}]interface{}) {}\nfunc (s *Subject) SetArgMethodInterface(sliceArg, ptrArg, mapArg interface{})                    {}\n\nfunc assertEqual(t *testing.T, expected interface{}, actual interface{}) {\n\tif !reflect.DeepEqual(expected, actual) {\n\t\tt.Errorf(\"Expected %+v, but got %+v\", expected, actual)\n\t}\n}\n\nfunc createFixtures(t *testing.T) (reporter *ErrorReporter, ctrl *gomock.Controller) {\n\t// reporter acts as a testing.T-like object that we pass to the\n\t// Controller. We use it to test that the mock considered tests\n\t// successful or failed.\n\treporter = NewErrorReporter(t)\n\tctrl = gomock.NewController(reporter)\n\treturn\n}\n\nfunc TestNoCalls(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tctrl.Finish()\n\treporter.assertPass(\"No calls expected or made.\")\n}\n\nfunc TestNoRecordedCallsForAReceiver(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"NotRecordedMethod\", \"argument\")\n\t}, \"Unexpected call to\", \"there are no expected calls of the method \\\"NotRecordedMethod\\\" for that receiver\")\n\tctrl.Finish()\n}\n\nfunc TestNoRecordedMatchingMethodNameForAReceiver(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\")\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"NotRecordedMethod\", \"argument\")\n\t}, \"Unexpected call to\", \"there are no expected calls of the method \\\"NotRecordedMethod\\\" for that receiver\")\n\treporter.assertFatal(func() {\n\t\t// The expected call wasn't made.\n\t\tctrl.Finish()\n\t})\n}\n\n// This tests that a call with an arguments of some primitive type matches a recorded call.\nfunc TestExpectedMethodCall(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\")\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\tctrl.Finish()\n\n\treporter.assertPass(\"Expected method call made.\")\n}\n\nfunc TestUnexpectedMethodCall(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\t})\n\n\tctrl.Finish()\n}\n\nfunc TestRepeatedCall(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").Times(3)\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\treporter.assertPass(\"After expected repeated method calls.\")\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\t})\n\tctrl.Finish()\n\treporter.assertFail(\"After calling one too many times.\")\n}\n\nfunc TestUnexpectedArgCount(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tdefer reporter.recoverUnexpectedFatal()\n\tsubject := new(Subject)\n\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\")\n\treporter.assertFatal(func() {\n\t\t// This call is made with the wrong number of arguments...\n\t\tctrl.Call(subject, \"FooMethod\", \"argument\", \"extra_argument\")\n\t}, \"Unexpected call to\", \"wrong number of arguments\", \"Got: 2, want: 1\")\n\treporter.assertFatal(func() {\n\t\t// ... so is this.\n\t\tctrl.Call(subject, \"FooMethod\")\n\t}, \"Unexpected call to\", \"wrong number of arguments\", \"Got: 0, want: 1\")\n\treporter.assertFatal(func() {\n\t\t// The expected call wasn't made.\n\t\tctrl.Finish()\n\t})\n}\n\n// This tests that a call with complex arguments (a struct and some primitive type) matches a recorded call.\nfunc TestExpectedMethodCall_CustomStruct(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\texpectedArg0 := TestStruct{Number: 123, Message: \"hello\"}\n\tctrl.RecordCall(subject, \"ActOnTestStructMethod\", expectedArg0, 15)\n\tctrl.Call(subject, \"ActOnTestStructMethod\", expectedArg0, 15)\n\n\treporter.assertPass(\"Expected method call made.\")\n}\n\nfunc TestUnexpectedArgValue_FirstArg(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tdefer reporter.recoverUnexpectedFatal()\n\tsubject := new(Subject)\n\n\texpectedArg0 := TestStruct{Number: 123, Message: \"hello %s\"}\n\tctrl.RecordCall(subject, \"ActOnTestStructMethod\", expectedArg0, 15)\n\n\treporter.assertFatal(func() {\n\t\t// the method argument (of TestStruct type) has 1 unexpected value (for the Message field)\n\t\tctrl.Call(subject, \"ActOnTestStructMethod\", TestStruct{Number: 123, Message: \"no message\"}, 15)\n\t}, \"Unexpected call to\", \"doesn't match the argument at index 0\",\n\t\t\"Got: {123 no message} (gomock_test.TestStruct)\\nWant: is equal to {123 hello %s} (gomock_test.TestStruct)\")\n\n\treporter.assertFatal(func() {\n\t\t// the method argument (of TestStruct type) has 2 unexpected values (for both fields)\n\t\tctrl.Call(subject, \"ActOnTestStructMethod\", TestStruct{Number: 11, Message: \"no message\"}, 15)\n\t}, \"Unexpected call to\", \"doesn't match the argument at index 0\",\n\t\t\"Got: {11 no message} (gomock_test.TestStruct)\\nWant: is equal to {123 hello %s} (gomock_test.TestStruct)\")\n\n\treporter.assertFatal(func() {\n\t\t// The expected call wasn't made.\n\t\tctrl.Finish()\n\t})\n}\n\nfunc TestUnexpectedArgValue_SecondArg(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tdefer reporter.recoverUnexpectedFatal()\n\tsubject := new(Subject)\n\n\texpectedArg0 := TestStruct{Number: 123, Message: \"hello\"}\n\tctrl.RecordCall(subject, \"ActOnTestStructMethod\", expectedArg0, 15)\n\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"ActOnTestStructMethod\", TestStruct{Number: 123, Message: \"hello\"}, 3)\n\t}, \"Unexpected call to\", \"doesn't match the argument at index 1\",\n\t\t\"Got: 3 (int)\\nWant: is equal to 15 (int)\")\n\n\treporter.assertFatal(func() {\n\t\t// The expected call wasn't made.\n\t\tctrl.Finish()\n\t})\n}\n\nfunc TestUnexpectedArgValue_WantFormatter(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tdefer reporter.recoverUnexpectedFatal()\n\tsubject := new(Subject)\n\n\texpectedArg0 := TestStruct{Number: 123, Message: \"hello\"}\n\tctrl.RecordCall(\n\t\tsubject,\n\t\t\"ActOnTestStructMethod\",\n\t\texpectedArg0,\n\t\tgomock.WantFormatter(\n\t\t\tgomock.StringerFunc(func() string { return \"is equal to fifteen\" }),\n\t\t\tgomock.Eq(15),\n\t\t),\n\t)\n\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"ActOnTestStructMethod\", TestStruct{Number: 123, Message: \"hello\"}, 3)\n\t}, \"Unexpected call to\", \"doesn't match the argument at index 1\",\n\t\t\"Got: 3 (int)\\nWant: is equal to fifteen\")\n\n\treporter.assertFatal(func() {\n\t\t// The expected call wasn't made.\n\t\tctrl.Finish()\n\t})\n}\n\nfunc TestUnexpectedArgValue_GotFormatter(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tdefer reporter.recoverUnexpectedFatal()\n\tsubject := new(Subject)\n\n\texpectedArg0 := TestStruct{Number: 123, Message: \"hello\"}\n\tctrl.RecordCall(\n\t\tsubject,\n\t\t\"ActOnTestStructMethod\",\n\t\texpectedArg0,\n\t\tgomock.GotFormatterAdapter(\n\t\t\tgomock.GotFormatterFunc(func(i interface{}) string {\n\t\t\t\t// Leading 0s\n\t\t\t\treturn fmt.Sprintf(\"%02d\", i)\n\t\t\t}),\n\t\t\tgomock.Eq(15),\n\t\t),\n\t)\n\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"ActOnTestStructMethod\", TestStruct{Number: 123, Message: \"hello\"}, 3)\n\t}, \"Unexpected call to\", \"doesn't match the argument at index 1\",\n\t\t\"Got: 03\\nWant: is equal to 15\")\n\n\treporter.assertFatal(func() {\n\t\t// The expected call wasn't made.\n\t\tctrl.Finish()\n\t})\n}\n\nfunc TestAnyTimes(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").AnyTimes()\n\tfor i := 0; i < 100; i++ {\n\t\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\t}\n\treporter.assertPass(\"After 100 method calls.\")\n\tctrl.Finish()\n}\n\nfunc TestMinTimes1(t *testing.T) {\n\t// It fails if there are no calls\n\treporter, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MinTimes(1)\n\treporter.assertFatal(func() {\n\t\tctrl.Finish()\n\t})\n\n\t// It succeeds if there is one call\n\t_, ctrl = createFixtures(t)\n\tsubject = new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MinTimes(1)\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\tctrl.Finish()\n\n\t// It succeeds if there are many calls\n\t_, ctrl = createFixtures(t)\n\tsubject = new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MinTimes(1)\n\tfor i := 0; i < 100; i++ {\n\t\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\t}\n\tctrl.Finish()\n}\n\nfunc TestMaxTimes1(t *testing.T) {\n\t// It succeeds if there are no calls\n\t_, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MaxTimes(1)\n\tctrl.Finish()\n\n\t// It succeeds if there is one call\n\t_, ctrl = createFixtures(t)\n\tsubject = new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MaxTimes(1)\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\tctrl.Finish()\n\n\t// It fails if there are more\n\treporter, ctrl := createFixtures(t)\n\tsubject = new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MaxTimes(1)\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\t})\n\tctrl.Finish()\n}\n\nfunc TestMinMaxTimes(t *testing.T) {\n\t// It fails if there are less calls than specified\n\treporter, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MinTimes(2).MaxTimes(2)\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\treporter.assertFatal(func() {\n\t\tctrl.Finish()\n\t})\n\n\t// It fails if there are more calls than specified\n\treporter, ctrl = createFixtures(t)\n\tsubject = new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MinTimes(2).MaxTimes(2)\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\t})\n\n\t// It succeeds if there is just the right number of calls\n\t_, ctrl = createFixtures(t)\n\tsubject = new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MaxTimes(2).MinTimes(2)\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\tctrl.Finish()\n\n\t// If MaxTimes is called after MinTimes is called with 1, MaxTimes takes precedence.\n\treporter, ctrl = createFixtures(t)\n\tsubject = new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MinTimes(1).MaxTimes(2)\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\treporter.assertFatal(func() {\n\t\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\t})\n\n\t// If MinTimes is called after MaxTimes is called with 1, MinTimes takes precedence.\n\t_, ctrl = createFixtures(t)\n\tsubject = new(Subject)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\").MaxTimes(1).MinTimes(2)\n\tfor i := 0; i < 100; i++ {\n\t\tctrl.Call(subject, \"FooMethod\", \"argument\")\n\t}\n\tctrl.Finish()\n}\n\nfunc TestDo(t *testing.T) {\n\t_, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\tdoCalled := false\n\tvar argument string\n\twantArg := \"argument\"\n\tctrl.RecordCall(subject, \"FooMethod\", wantArg).Do(\n\t\tfunc(arg string) {\n\t\t\tdoCalled = true\n\t\t\targument = arg\n\t\t})\n\tif doCalled {\n\t\tt.Error(\"Do() callback called too early.\")\n\t}\n\n\tctrl.Call(subject, \"FooMethod\", wantArg)\n\n\tif !doCalled {\n\t\tt.Error(\"Do() callback not called.\")\n\t}\n\tif wantArg != argument {\n\t\tt.Error(\"Do callback received wrong argument.\")\n\t}\n\n\tctrl.Finish()\n}\n\nfunc TestDoAndReturn(t *testing.T) {\n\t_, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\tdoCalled := false\n\tvar argument string\n\twantArg := \"argument\"\n\tctrl.RecordCall(subject, \"FooMethod\", wantArg).DoAndReturn(\n\t\tfunc(arg string) int {\n\t\t\tdoCalled = true\n\t\t\targument = arg\n\t\t\treturn 5\n\t\t})\n\tif doCalled {\n\t\tt.Error(\"Do() callback called too early.\")\n\t}\n\n\trets := ctrl.Call(subject, \"FooMethod\", wantArg)\n\n\tif !doCalled {\n\t\tt.Error(\"Do() callback not called.\")\n\t}\n\tif wantArg != argument {\n\t\tt.Error(\"Do callback received wrong argument.\")\n\t}\n\tif len(rets) != 1 {\n\t\tt.Fatalf(\"Return values from Call: got %d, want 1\", len(rets))\n\t}\n\tif ret, ok := rets[0].(int); !ok {\n\t\tt.Fatalf(\"Return value is not an int\")\n\t} else if ret != 5 {\n\t\tt.Errorf(\"DoAndReturn return value: got %d, want 5\", ret)\n\t}\n\n\tctrl.Finish()\n}\n\nfunc TestSetArgSlice(t *testing.T) {\n\t_, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\tvar in = []byte{4, 5, 6}\n\tvar set = []byte{1, 2, 3}\n\tctrl.RecordCall(subject, \"SetArgMethod\", in, nil, nil).SetArg(0, set)\n\tctrl.Call(subject, \"SetArgMethod\", in, nil, nil)\n\n\tif !reflect.DeepEqual(in, set) {\n\t\tt.Error(\"Expected SetArg() to modify input slice argument\")\n\t}\n\n\tctrl.RecordCall(subject, \"SetArgMethodInterface\", in, nil, nil).SetArg(0, set)\n\tctrl.Call(subject, \"SetArgMethodInterface\", in, nil, nil)\n\n\tif !reflect.DeepEqual(in, set) {\n\t\tt.Error(\"Expected SetArg() to modify input slice argument as interface{}\")\n\t}\n\n\tctrl.Finish()\n}\n\nfunc TestSetArgMap(t *testing.T) {\n\t_, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\tvar in = map[interface{}]interface{}{\"int\": 1, \"string\": \"random string\", 1: \"1\", 0: 0}\n\tvar set = map[interface{}]interface{}{\"int\": 2, 1: \"2\", 2: 100}\n\tctrl.RecordCall(subject, \"SetArgMethod\", nil, nil, in).SetArg(2, set)\n\tctrl.Call(subject, \"SetArgMethod\", nil, nil, in)\n\n\tif !reflect.DeepEqual(in, set) {\n\t\tt.Error(\"Expected SetArg() to modify input map argument\")\n\t}\n\n\tctrl.RecordCall(subject, \"SetArgMethodInterface\", nil, nil, in).SetArg(2, set)\n\tctrl.Call(subject, \"SetArgMethodInterface\", nil, nil, in)\n\n\tif !reflect.DeepEqual(in, set) {\n\t\tt.Error(\"Expected SetArg() to modify input map argument as interface{}\")\n\t}\n\n\tctrl.Finish()\n}\n\nfunc TestSetArgPtr(t *testing.T) {\n\t_, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\tvar in int = 43\n\tconst set = 42\n\tctrl.RecordCall(subject, \"SetArgMethod\", nil, &in, nil).SetArg(1, set)\n\tctrl.Call(subject, \"SetArgMethod\", nil, &in, nil)\n\n\tif in != set {\n\t\tt.Error(\"Expected SetArg() to modify value pointed to by argument\")\n\t}\n\n\tctrl.RecordCall(subject, \"SetArgMethodInterface\", nil, &in, nil).SetArg(1, set)\n\tctrl.Call(subject, \"SetArgMethodInterface\", nil, &in, nil)\n\n\tif in != set {\n\t\tt.Error(\"Expected SetArg() to modify value pointed to by argument as interface{}\")\n\t}\n\tctrl.Finish()\n}\n\nfunc TestReturn(t *testing.T) {\n\t_, ctrl := createFixtures(t)\n\tsubject := new(Subject)\n\n\t// Unspecified return should produce \"zero\" result.\n\tctrl.RecordCall(subject, \"FooMethod\", \"zero\")\n\tctrl.RecordCall(subject, \"FooMethod\", \"five\").Return(5)\n\n\tassertEqual(\n\t\tt,\n\t\t[]interface{}{0},\n\t\tctrl.Call(subject, \"FooMethod\", \"zero\"))\n\n\tassertEqual(\n\t\tt,\n\t\t[]interface{}{5},\n\t\tctrl.Call(subject, \"FooMethod\", \"five\"))\n\tctrl.Finish()\n}\n\nfunc TestUnorderedCalls(t *testing.T) {\n\treporter, ctrl := createFixtures(t)\n\tdefer reporter.recoverUnexpectedFatal()\n\tsubjectTwo := new(Subject)\n\tsubjectOne := new(Subject)\n\n\tctrl.RecordCall(subjectOne, \"FooMethod\", \"1\")\n\tctrl.RecordCall(subjectOne, \"BarMethod\", \"2\")\n\tctrl.RecordCall(subjectTwo, \"FooMethod\", \"3\")\n\tctrl.RecordCall(subjectTwo, \"BarMethod\", \"4\")\n\n\t// Make the calls in a different order, which should be fine.\n\tctrl.Call(subjectOne, \"BarMethod\", \"2\")\n\tctrl.Call(subjectTwo, \"FooMethod\", \"3\")\n\tctrl.Call(subjectTwo, \"BarMethod\", \"4\")\n\tctrl.Call(subjectOne, \"FooMethod\", \"1\")\n\n\treporter.assertPass(\"After making all calls in different order\")\n\n\tctrl.Finish()\n\n\treporter.assertPass(\"After finish\")\n}\n\nfunc commonTestOrderedCalls(t *testing.T) (reporter *ErrorReporter, ctrl *gomock.Controller, subjectOne, subjectTwo *Subject) {\n\treporter, ctrl = createFixtures(t)\n\n\tsubjectOne = new(Subject)\n\tsubjectTwo = new(Subject)\n\n\tgomock.InOrder(\n\t\tctrl.RecordCall(subjectOne, \"FooMethod\", \"1\").AnyTimes(),\n\t\tctrl.RecordCall(subjectTwo, \"FooMethod\", \"2\"),\n\t\tctrl.RecordCall(subjectTwo, \"BarMethod\", \"3\"),\n\t)\n\n\treturn\n}\n\nfunc TestOrderedCallsCorrect(t *testing.T) {\n\treporter, ctrl, subjectOne, subjectTwo := commonTestOrderedCalls(t)\n\n\tctrl.Call(subjectOne, \"FooMethod\", \"1\")\n\tctrl.Call(subjectTwo, \"FooMethod\", \"2\")\n\tctrl.Call(subjectTwo, \"BarMethod\", \"3\")\n\n\tctrl.Finish()\n\n\treporter.assertPass(\"After finish\")\n}\n\nfunc TestPanicOverridesExpectationChecks(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\treporter := NewErrorReporter(t)\n\n\treporter.assertFatal(func() {\n\t\tctrl.RecordCall(new(Subject), \"FooMethod\", \"1\")\n\t\tdefer ctrl.Finish()\n\t\treporter.Fatalf(\"Intentional panic\")\n\t})\n}\n\nfunc TestSetArgWithBadType(t *testing.T) {\n\trep, ctrl := createFixtures(t)\n\tdefer ctrl.Finish()\n\n\ts := new(Subject)\n\t// This should catch a type error:\n\trep.assertFatal(func() {\n\t\tctrl.RecordCall(s, \"FooMethod\", \"1\").SetArg(0, \"blah\")\n\t})\n\tctrl.Call(s, \"FooMethod\", \"1\")\n}\n\nfunc TestTimes0(t *testing.T) {\n\trep, ctrl := createFixtures(t)\n\tdefer ctrl.Finish()\n\n\ts := new(Subject)\n\tctrl.RecordCall(s, \"FooMethod\", \"arg\").Times(0)\n\trep.assertFatal(func() {\n\t\tctrl.Call(s, \"FooMethod\", \"arg\")\n\t})\n}\n\nfunc TestVariadicMatching(t *testing.T) {\n\trep, ctrl := createFixtures(t)\n\tdefer rep.recoverUnexpectedFatal()\n\n\ts := new(Subject)\n\tctrl.RecordCall(s, \"VariadicMethod\", 0, \"1\", \"2\")\n\tctrl.Call(s, \"VariadicMethod\", 0, \"1\", \"2\")\n\tctrl.Finish()\n\trep.assertPass(\"variadic matching works\")\n}\n\nfunc TestVariadicNoMatch(t *testing.T) {\n\trep, ctrl := createFixtures(t)\n\tdefer rep.recoverUnexpectedFatal()\n\n\ts := new(Subject)\n\tctrl.RecordCall(s, \"VariadicMethod\", 0)\n\trep.assertFatal(func() {\n\t\tctrl.Call(s, \"VariadicMethod\", 1)\n\t}, \"expected call at\", \"doesn't match the argument at index 0\",\n\t\t\"Got: 1 (int)\\nWant: is equal to 0 (int)\")\n\tctrl.Call(s, \"VariadicMethod\", 0)\n\tctrl.Finish()\n}\n\nfunc TestVariadicMatchingWithSlice(t *testing.T) {\n\ttestCases := [][]string{\n\t\t{\"1\"},\n\t\t{\"1\", \"2\"},\n\t}\n\tfor _, tc := range testCases {\n\t\tt.Run(fmt.Sprintf(\"%d arguments\", len(tc)), func(t *testing.T) {\n\t\t\trep, ctrl := createFixtures(t)\n\t\t\tdefer rep.recoverUnexpectedFatal()\n\n\t\t\ts := new(Subject)\n\t\t\tctrl.RecordCall(s, \"VariadicMethod\", 1, tc)\n\t\t\targs := make([]interface{}, len(tc)+1)\n\t\t\targs[0] = 1\n\t\t\tfor i, arg := range tc {\n\t\t\t\targs[i+1] = arg\n\t\t\t}\n\t\t\tctrl.Call(s, \"VariadicMethod\", args...)\n\t\t\tctrl.Finish()\n\t\t\trep.assertPass(\"slices can be used as matchers for variadic arguments\")\n\t\t})\n\t}\n}\n\nfunc TestVariadicArgumentsGotFormatter(t *testing.T) {\n\trep, ctrl := createFixtures(t)\n\tdefer rep.recoverUnexpectedFatal()\n\n\ts := new(Subject)\n\tctrl.RecordCall(\n\t\ts,\n\t\t\"VariadicMethod\",\n\t\tgomock.GotFormatterAdapter(\n\t\t\tgomock.GotFormatterFunc(func(i interface{}) string {\n\t\t\t\treturn fmt.Sprintf(\"test{%v}\", i)\n\t\t\t}),\n\t\t\tgomock.Eq(0),\n\t\t),\n\t)\n\n\trep.assertFatal(func() {\n\t\tctrl.Call(s, \"VariadicMethod\", 1)\n\t}, \"expected call to\", \"doesn't match the argument at index 0\",\n\t\t\"Got: test{1}\\nWant: is equal to 0\")\n\tctrl.Call(s, \"VariadicMethod\", 0)\n\tctrl.Finish()\n}\n\nfunc TestVariadicArgumentsGotFormatterTooManyArgsFailure(t *testing.T) {\n\trep, ctrl := createFixtures(t)\n\tdefer rep.recoverUnexpectedFatal()\n\n\ts := new(Subject)\n\tctrl.RecordCall(\n\t\ts,\n\t\t\"VariadicMethod\",\n\t\t0,\n\t\tgomock.GotFormatterAdapter(\n\t\t\tgomock.GotFormatterFunc(func(i interface{}) string {\n\t\t\t\treturn fmt.Sprintf(\"test{%v}\", i)\n\t\t\t}),\n\t\t\tgomock.Eq(\"1\"),\n\t\t),\n\t)\n\n\trep.assertFatal(func() {\n\t\tctrl.Call(s, \"VariadicMethod\", 0, \"2\", \"3\")\n\t}, \"expected call to\", \"doesn't match the argument at index 1\",\n\t\t\"Got: test{[2 3]}\\nWant: is equal to 1\")\n\tctrl.Call(s, \"VariadicMethod\", 0, \"1\")\n\tctrl.Finish()\n}\n\nfunc TestNoHelper(t *testing.T) {\n\tctrlNoHelper := gomock.NewController(NewErrorReporter(t))\n\n\t// doesn't panic\n\tctrlNoHelper.T.Helper()\n}\n\nfunc TestWithHelper(t *testing.T) {\n\twithHelper := &HelperReporter{TestReporter: NewErrorReporter(t)}\n\tctrlWithHelper := gomock.NewController(withHelper)\n\n\tctrlWithHelper.T.Helper()\n\n\tif withHelper.helper == 0 {\n\t\tt.Fatal(\"expected Helper to be invoked\")\n\t}\n}\n\nfunc (e *ErrorReporter) Cleanup(f func()) {\n\te.t.Helper()\n\te.t.Cleanup(f)\n}\n\nfunc TestMultipleDefers(t *testing.T) {\n\treporter := NewErrorReporter(t)\n\treporter.Cleanup(func() {\n\t\treporter.assertPass(\"No errors for multiple calls to Finish\")\n\t})\n\tctrl := gomock.NewController(reporter)\n\tctrl.Finish()\n}\n\n// Equivalent to the TestNoRecordedCallsForAReceiver, but without explicitly\n// calling Finish.\nfunc TestDeferNotNeededFail(t *testing.T) {\n\treporter := NewErrorReporter(t)\n\tsubject := new(Subject)\n\tvar ctrl *gomock.Controller\n\treporter.Cleanup(func() {\n\t\treporter.assertFatal(func() {\n\t\t\tctrl.Call(subject, \"NotRecordedMethod\", \"argument\")\n\t\t}, \"Unexpected call to\", \"there are no expected calls of the method \\\"NotRecordedMethod\\\" for that receiver\")\n\t})\n\tctrl = gomock.NewController(reporter)\n}\n\nfunc TestDeferNotNeededPass(t *testing.T) {\n\treporter := NewErrorReporter(t)\n\tsubject := new(Subject)\n\tvar ctrl *gomock.Controller\n\treporter.Cleanup(func() {\n\t\treporter.assertPass(\"Expected method call made.\")\n\t})\n\tctrl = gomock.NewController(reporter)\n\tctrl.RecordCall(subject, \"FooMethod\", \"argument\")\n\tctrl.Call(subject, \"FooMethod\", \"argument\")\n}\n\nfunc TestOrderedCallsInCorrect(t *testing.T) {\n\treporter := NewErrorReporter(t)\n\tsubjectOne := new(Subject)\n\tsubjectTwo := new(Subject)\n\tvar ctrl *gomock.Controller\n\treporter.Cleanup(func() {\n\t\treporter.assertFatal(func() {\n\t\t\tgomock.InOrder(\n\t\t\t\tctrl.RecordCall(subjectOne, \"FooMethod\", \"1\").AnyTimes(),\n\t\t\t\tctrl.RecordCall(subjectTwo, \"FooMethod\", \"2\"),\n\t\t\t\tctrl.RecordCall(subjectTwo, \"BarMethod\", \"3\"),\n\t\t\t)\n\t\t\tctrl.Call(subjectOne, \"FooMethod\", \"1\")\n\t\t\t// FooMethod(2) should be called before BarMethod(3)\n\t\t\tctrl.Call(subjectTwo, \"BarMethod\", \"3\")\n\t\t}, \"Unexpected call to\", \"Subject.BarMethod([3])\", \"doesn't have a prerequisite call satisfied\")\n\t})\n\tctrl = gomock.NewController(reporter)\n}\n\n// Test that calls that are prerequisites to other calls but have maxCalls >\n// minCalls are removed from the expected call set.\nfunc TestOrderedCallsWithPreReqMaxUnbounded(t *testing.T) {\n\treporter := NewErrorReporter(t)\n\tsubjectOne := new(Subject)\n\tsubjectTwo := new(Subject)\n\tvar ctrl *gomock.Controller\n\treporter.Cleanup(func() {\n\t\treporter.assertFatal(func() {\n\t\t\t// Initially we should be able to call FooMethod(\"1\") as many times as we\n\t\t\t// want.\n\t\t\tctrl.Call(subjectOne, \"FooMethod\", \"1\")\n\t\t\tctrl.Call(subjectOne, \"FooMethod\", \"1\")\n\n\t\t\t// But calling something that has it as a prerequite should remove it from\n\t\t\t// the expected call set. This allows tests to ensure that FooMethod(\"1\") is\n\t\t\t// *not* called after FooMethod(\"2\").\n\t\t\tctrl.Call(subjectTwo, \"FooMethod\", \"2\")\n\n\t\t\tctrl.Call(subjectOne, \"FooMethod\", \"1\")\n\t\t})\n\t})\n\tctrl = gomock.NewController(reporter)\n}\n\nfunc TestCallAfterLoopPanic(t *testing.T) {\n\treporter := NewErrorReporter(t)\n\tsubject := new(Subject)\n\tvar ctrl *gomock.Controller\n\treporter.Cleanup(func() {\n\t\tfirstCall := ctrl.RecordCall(subject, \"FooMethod\", \"1\")\n\t\tsecondCall := ctrl.RecordCall(subject, \"FooMethod\", \"2\")\n\t\tthirdCall := ctrl.RecordCall(subject, \"FooMethod\", \"3\")\n\n\t\tgomock.InOrder(firstCall, secondCall, thirdCall)\n\n\t\tdefer func() {\n\t\t\terr := recover()\n\t\t\tif err == nil {\n\t\t\t\tt.Error(\"Call.After creation of dependency loop did not panic.\")\n\t\t\t}\n\t\t}()\n\n\t\t// This should panic due to dependency loop.\n\t\tfirstCall.After(thirdCall)\n\t})\n\tctrl = gomock.NewController(reporter)\n}\n"
  },
  {
    "path": "gomock/doc.go",
    "content": "// Copyright 2022 Google LLC\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Package gomock is a mock framework for Go.\n//\n// Standard usage:\n//   (1) Define an interface that you wish to mock.\n//         type MyInterface interface {\n//           SomeMethod(x int64, y string)\n//         }\n//   (2) Use mockgen to generate a mock from the interface.\n//   (3) Use the mock in a test:\n//         func TestMyThing(t *testing.T) {\n//           mockCtrl := gomock.NewController(t)//\n//           mockObj := something.NewMockMyInterface(mockCtrl)\n//           mockObj.EXPECT().SomeMethod(4, \"blah\")\n//           // pass mockObj to a real object and play with it.\n//         }\n//\n// By default, expected calls are not enforced to run in any particular order.\n// Call order dependency can be enforced by use of InOrder and/or Call.After.\n// Call.After can create more varied call order dependencies, but InOrder is\n// often more convenient.\n//\n// The following examples create equivalent call order dependencies.\n//\n// Example of using Call.After to chain expected call order:\n//\n//     firstCall := mockObj.EXPECT().SomeMethod(1, \"first\")\n//     secondCall := mockObj.EXPECT().SomeMethod(2, \"second\").After(firstCall)\n//     mockObj.EXPECT().SomeMethod(3, \"third\").After(secondCall)\n//\n// Example of using InOrder to declare expected call order:\n//\n//     gomock.InOrder(\n//         mockObj.EXPECT().SomeMethod(1, \"first\"),\n//         mockObj.EXPECT().SomeMethod(2, \"second\"),\n//         mockObj.EXPECT().SomeMethod(3, \"third\"),\n//     )\n//\n// The standard TestReporter most users will pass to `NewController` is a\n// `*testing.T` from the context of the test. Note that this will use the\n// standard `t.Error` and `t.Fatal` methods to report what happened in the test.\n// In some cases this can leave your testing package in a weird state if global\n// state is used since `t.Fatal` is like calling panic in the middle of a\n// function. In these cases it is recommended that you pass in your own\n// `TestReporter`.\npackage gomock\n"
  },
  {
    "path": "gomock/example_test.go",
    "content": "package gomock_test\n\n//go:generate mockgen -destination mock_test.go -package gomock_test -source example_test.go\n\nimport (\n\t\"fmt\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/golang/mock/gomock\"\n)\n\ntype Foo interface {\n\tBar(string) string\n}\n\nfunc ExampleCall_DoAndReturn_latency() {\n\tt := &testing.T{} // provided by test\n\tctrl := gomock.NewController(t)\n\tmockIndex := NewMockFoo(ctrl)\n\n\tmockIndex.EXPECT().Bar(gomock.Any()).DoAndReturn(\n\t\tfunc(arg string) string {\n\t\t\ttime.Sleep(1 * time.Millisecond)\n\t\t\treturn \"I'm sleepy\"\n\t\t},\n\t)\n\n\tr := mockIndex.Bar(\"foo\")\n\tfmt.Println(r)\n\t// Output: I'm sleepy\n}\n\nfunc ExampleCall_DoAndReturn_captureArguments() {\n\tt := &testing.T{} // provided by test\n\tctrl := gomock.NewController(t)\n\tmockIndex := NewMockFoo(ctrl)\n\tvar s string\n\n\tmockIndex.EXPECT().Bar(gomock.AssignableToTypeOf(s)).DoAndReturn(\n\t\tfunc(arg string) interface{} {\n\t\t\ts = arg\n\t\t\treturn \"I'm sleepy\"\n\t\t},\n\t)\n\n\tr := mockIndex.Bar(\"foo\")\n\tfmt.Printf(\"%s %s\", r, s)\n\t// Output: I'm sleepy foo\n}\n"
  },
  {
    "path": "gomock/internal/mock_gomock/mock_matcher.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: github.com/golang/mock/gomock (interfaces: Matcher)\n\n// Package mock_gomock is a generated GoMock package.\npackage mock_gomock\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockMatcher is a mock of Matcher interface.\ntype MockMatcher struct {\n\tctrl     *gomock.Controller\n\trecorder *MockMatcherMockRecorder\n}\n\n// MockMatcherMockRecorder is the mock recorder for MockMatcher.\ntype MockMatcherMockRecorder struct {\n\tmock *MockMatcher\n}\n\n// NewMockMatcher creates a new mock instance.\nfunc NewMockMatcher(ctrl *gomock.Controller) *MockMatcher {\n\tmock := &MockMatcher{ctrl: ctrl}\n\tmock.recorder = &MockMatcherMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockMatcher) EXPECT() *MockMatcherMockRecorder {\n\treturn m.recorder\n}\n\n// Matches mocks base method.\nfunc (m *MockMatcher) Matches(arg0 interface{}) bool {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Matches\", arg0)\n\tret0, _ := ret[0].(bool)\n\treturn ret0\n}\n\n// Matches indicates an expected call of Matches.\nfunc (mr *MockMatcherMockRecorder) Matches(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Matches\", reflect.TypeOf((*MockMatcher)(nil).Matches), arg0)\n}\n\n// String mocks base method.\nfunc (m *MockMatcher) String() string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"String\")\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// String indicates an expected call of String.\nfunc (mr *MockMatcherMockRecorder) String() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"String\", reflect.TypeOf((*MockMatcher)(nil).String))\n}\n"
  },
  {
    "path": "gomock/matchers.go",
    "content": "// Copyright 2010 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage gomock\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n\t\"strings\"\n)\n\n// A Matcher is a representation of a class of values.\n// It is used to represent the valid or expected arguments to a mocked method.\ntype Matcher interface {\n\t// Matches returns whether x is a match.\n\tMatches(x interface{}) bool\n\n\t// String describes what the matcher matches.\n\tString() string\n}\n\n// WantFormatter modifies the given Matcher's String() method to the given\n// Stringer. This allows for control on how the \"Want\" is formatted when\n// printing .\nfunc WantFormatter(s fmt.Stringer, m Matcher) Matcher {\n\ttype matcher interface {\n\t\tMatches(x interface{}) bool\n\t}\n\n\treturn struct {\n\t\tmatcher\n\t\tfmt.Stringer\n\t}{\n\t\tmatcher:  m,\n\t\tStringer: s,\n\t}\n}\n\n// StringerFunc type is an adapter to allow the use of ordinary functions as\n// a Stringer. If f is a function with the appropriate signature,\n// StringerFunc(f) is a Stringer that calls f.\ntype StringerFunc func() string\n\n// String implements fmt.Stringer.\nfunc (f StringerFunc) String() string {\n\treturn f()\n}\n\n// GotFormatter is used to better print failure messages. If a matcher\n// implements GotFormatter, it will use the result from Got when printing\n// the failure message.\ntype GotFormatter interface {\n\t// Got is invoked with the received value. The result is used when\n\t// printing the failure message.\n\tGot(got interface{}) string\n}\n\n// GotFormatterFunc type is an adapter to allow the use of ordinary\n// functions as a GotFormatter. If f is a function with the appropriate\n// signature, GotFormatterFunc(f) is a GotFormatter that calls f.\ntype GotFormatterFunc func(got interface{}) string\n\n// Got implements GotFormatter.\nfunc (f GotFormatterFunc) Got(got interface{}) string {\n\treturn f(got)\n}\n\n// GotFormatterAdapter attaches a GotFormatter to a Matcher.\nfunc GotFormatterAdapter(s GotFormatter, m Matcher) Matcher {\n\treturn struct {\n\t\tGotFormatter\n\t\tMatcher\n\t}{\n\t\tGotFormatter: s,\n\t\tMatcher:      m,\n\t}\n}\n\ntype anyMatcher struct{}\n\nfunc (anyMatcher) Matches(interface{}) bool {\n\treturn true\n}\n\nfunc (anyMatcher) String() string {\n\treturn \"is anything\"\n}\n\ntype eqMatcher struct {\n\tx interface{}\n}\n\nfunc (e eqMatcher) Matches(x interface{}) bool {\n\t// In case, some value is nil\n\tif e.x == nil || x == nil {\n\t\treturn reflect.DeepEqual(e.x, x)\n\t}\n\n\t// Check if types assignable and convert them to common type\n\tx1Val := reflect.ValueOf(e.x)\n\tx2Val := reflect.ValueOf(x)\n\n\tif x1Val.Type().AssignableTo(x2Val.Type()) {\n\t\tx1ValConverted := x1Val.Convert(x2Val.Type())\n\t\treturn reflect.DeepEqual(x1ValConverted.Interface(), x2Val.Interface())\n\t}\n\n\treturn false\n}\n\nfunc (e eqMatcher) String() string {\n\treturn fmt.Sprintf(\"is equal to %v (%T)\", e.x, e.x)\n}\n\ntype nilMatcher struct{}\n\nfunc (nilMatcher) Matches(x interface{}) bool {\n\tif x == nil {\n\t\treturn true\n\t}\n\n\tv := reflect.ValueOf(x)\n\tswitch v.Kind() {\n\tcase reflect.Chan, reflect.Func, reflect.Interface, reflect.Map,\n\t\treflect.Ptr, reflect.Slice:\n\t\treturn v.IsNil()\n\t}\n\n\treturn false\n}\n\nfunc (nilMatcher) String() string {\n\treturn \"is nil\"\n}\n\ntype notMatcher struct {\n\tm Matcher\n}\n\nfunc (n notMatcher) Matches(x interface{}) bool {\n\treturn !n.m.Matches(x)\n}\n\nfunc (n notMatcher) String() string {\n\treturn \"not(\" + n.m.String() + \")\"\n}\n\ntype assignableToTypeOfMatcher struct {\n\ttargetType reflect.Type\n}\n\nfunc (m assignableToTypeOfMatcher) Matches(x interface{}) bool {\n\treturn reflect.TypeOf(x).AssignableTo(m.targetType)\n}\n\nfunc (m assignableToTypeOfMatcher) String() string {\n\treturn \"is assignable to \" + m.targetType.Name()\n}\n\ntype allMatcher struct {\n\tmatchers []Matcher\n}\n\nfunc (am allMatcher) Matches(x interface{}) bool {\n\tfor _, m := range am.matchers {\n\t\tif !m.Matches(x) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\nfunc (am allMatcher) String() string {\n\tss := make([]string, 0, len(am.matchers))\n\tfor _, matcher := range am.matchers {\n\t\tss = append(ss, matcher.String())\n\t}\n\treturn strings.Join(ss, \"; \")\n}\n\ntype lenMatcher struct {\n\ti int\n}\n\nfunc (m lenMatcher) Matches(x interface{}) bool {\n\tv := reflect.ValueOf(x)\n\tswitch v.Kind() {\n\tcase reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String:\n\t\treturn v.Len() == m.i\n\tdefault:\n\t\treturn false\n\t}\n}\n\nfunc (m lenMatcher) String() string {\n\treturn fmt.Sprintf(\"has length %d\", m.i)\n}\n\ntype inAnyOrderMatcher struct {\n\tx interface{}\n}\n\nfunc (m inAnyOrderMatcher) Matches(x interface{}) bool {\n\tgiven, ok := m.prepareValue(x)\n\tif !ok {\n\t\treturn false\n\t}\n\twanted, ok := m.prepareValue(m.x)\n\tif !ok {\n\t\treturn false\n\t}\n\n\tif given.Len() != wanted.Len() {\n\t\treturn false\n\t}\n\n\tusedFromGiven := make([]bool, given.Len())\n\tfoundFromWanted := make([]bool, wanted.Len())\n\tfor i := 0; i < wanted.Len(); i++ {\n\t\twantedMatcher := Eq(wanted.Index(i).Interface())\n\t\tfor j := 0; j < given.Len(); j++ {\n\t\t\tif usedFromGiven[j] {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif wantedMatcher.Matches(given.Index(j).Interface()) {\n\t\t\t\tfoundFromWanted[i] = true\n\t\t\t\tusedFromGiven[j] = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tmissingFromWanted := 0\n\tfor _, found := range foundFromWanted {\n\t\tif !found {\n\t\t\tmissingFromWanted++\n\t\t}\n\t}\n\textraInGiven := 0\n\tfor _, used := range usedFromGiven {\n\t\tif !used {\n\t\t\textraInGiven++\n\t\t}\n\t}\n\n\treturn extraInGiven == 0 && missingFromWanted == 0\n}\n\nfunc (m inAnyOrderMatcher) prepareValue(x interface{}) (reflect.Value, bool) {\n\txValue := reflect.ValueOf(x)\n\tswitch xValue.Kind() {\n\tcase reflect.Slice, reflect.Array:\n\t\treturn xValue, true\n\tdefault:\n\t\treturn reflect.Value{}, false\n\t}\n}\n\nfunc (m inAnyOrderMatcher) String() string {\n\treturn fmt.Sprintf(\"has the same elements as %v\", m.x)\n}\n\n// Constructors\n\n// All returns a composite Matcher that returns true if and only all of the\n// matchers return true.\nfunc All(ms ...Matcher) Matcher { return allMatcher{ms} }\n\n// Any returns a matcher that always matches.\nfunc Any() Matcher { return anyMatcher{} }\n\n// Eq returns a matcher that matches on equality.\n//\n// Example usage:\n//   Eq(5).Matches(5) // returns true\n//   Eq(5).Matches(4) // returns false\nfunc Eq(x interface{}) Matcher { return eqMatcher{x} }\n\n// Len returns a matcher that matches on length. This matcher returns false if\n// is compared to a type that is not an array, chan, map, slice, or string.\nfunc Len(i int) Matcher {\n\treturn lenMatcher{i}\n}\n\n// Nil returns a matcher that matches if the received value is nil.\n//\n// Example usage:\n//   var x *bytes.Buffer\n//   Nil().Matches(x) // returns true\n//   x = &bytes.Buffer{}\n//   Nil().Matches(x) // returns false\nfunc Nil() Matcher { return nilMatcher{} }\n\n// Not reverses the results of its given child matcher.\n//\n// Example usage:\n//   Not(Eq(5)).Matches(4) // returns true\n//   Not(Eq(5)).Matches(5) // returns false\nfunc Not(x interface{}) Matcher {\n\tif m, ok := x.(Matcher); ok {\n\t\treturn notMatcher{m}\n\t}\n\treturn notMatcher{Eq(x)}\n}\n\n// AssignableToTypeOf is a Matcher that matches if the parameter to the mock\n// function is assignable to the type of the parameter to this function.\n//\n// Example usage:\n//   var s fmt.Stringer = &bytes.Buffer{}\n//   AssignableToTypeOf(s).Matches(time.Second) // returns true\n//   AssignableToTypeOf(s).Matches(99) // returns false\n//\n//   var ctx = reflect.TypeOf((*context.Context)(nil)).Elem()\n//   AssignableToTypeOf(ctx).Matches(context.Background()) // returns true\nfunc AssignableToTypeOf(x interface{}) Matcher {\n\tif xt, ok := x.(reflect.Type); ok {\n\t\treturn assignableToTypeOfMatcher{xt}\n\t}\n\treturn assignableToTypeOfMatcher{reflect.TypeOf(x)}\n}\n\n// InAnyOrder is a Matcher that returns true for collections of the same elements ignoring the order.\n//\n// Example usage:\n//   InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 3, 2}) // returns true\n//   InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 2}) // returns false\nfunc InAnyOrder(x interface{}) Matcher {\n\treturn inAnyOrderMatcher{x}\n}\n"
  },
  {
    "path": "gomock/matchers_test.go",
    "content": "// Copyright 2010 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage gomock_test\n\n//go:generate mockgen -destination internal/mock_gomock/mock_matcher.go github.com/golang/mock/gomock Matcher\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"reflect\"\n\t\"testing\"\n\n\t\"github.com/golang/mock/gomock\"\n\t\"github.com/golang/mock/gomock/internal/mock_gomock\"\n)\n\ntype A []string\n\nfunc TestMatchers(t *testing.T) {\n\ttype e interface{}\n\ttests := []struct {\n\t\tname    string\n\t\tmatcher gomock.Matcher\n\t\tyes, no []e\n\t}{\n\t\t{\"test Any\", gomock.Any(), []e{3, nil, \"foo\"}, nil},\n\t\t{\"test All\", gomock.Eq(4), []e{4}, []e{3, \"blah\", nil, int64(4)}},\n\t\t{\"test Nil\", gomock.Nil(),\n\t\t\t[]e{nil, (error)(nil), (chan bool)(nil), (*int)(nil)},\n\t\t\t[]e{\"\", 0, make(chan bool), errors.New(\"err\"), new(int)}},\n\t\t{\"test Not\", gomock.Not(gomock.Eq(4)), []e{3, \"blah\", nil, int64(4)}, []e{4}},\n\t\t{\"test All\", gomock.All(gomock.Any(), gomock.Eq(4)), []e{4}, []e{3, \"blah\", nil, int64(4)}},\n\t\t{\"test Len\", gomock.Len(2),\n\t\t\t[]e{[]int{1, 2}, \"ab\", map[string]int{\"a\": 0, \"b\": 1}, [2]string{\"a\", \"b\"}},\n\t\t\t[]e{[]int{1}, \"a\", 42, 42.0, false, [1]string{\"a\"}},\n\t\t},\n\t\t{\"test assignable types\", gomock.Eq(A{\"a\", \"b\"}),\n\t\t\t[]e{[]string{\"a\", \"b\"}, A{\"a\", \"b\"}},\n\t\t\t[]e{[]string{\"a\"}, A{\"b\"}},\n\t\t},\n\t}\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tfor _, x := range tt.yes {\n\t\t\t\tif !tt.matcher.Matches(x) {\n\t\t\t\t\tt.Errorf(`\"%v %s\": got false, want true.`, x, tt.matcher)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor _, x := range tt.no {\n\t\t\t\tif tt.matcher.Matches(x) {\n\t\t\t\t\tt.Errorf(`\"%v %s\": got true, want false.`, x, tt.matcher)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\n// A more thorough test of notMatcher\nfunc TestNotMatcher(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\tmockMatcher := mock_gomock.NewMockMatcher(ctrl)\n\tnotMatcher := gomock.Not(mockMatcher)\n\n\tmockMatcher.EXPECT().Matches(4).Return(true)\n\tif match := notMatcher.Matches(4); match {\n\t\tt.Errorf(\"notMatcher should not match 4\")\n\t}\n\n\tmockMatcher.EXPECT().Matches(5).Return(false)\n\tif match := notMatcher.Matches(5); !match {\n\t\tt.Errorf(\"notMatcher should match 5\")\n\t}\n}\n\ntype Dog struct {\n\tBreed, Name string\n}\n\ntype ctxKey struct{}\n\n// A thorough test of assignableToTypeOfMatcher\nfunc TestAssignableToTypeOfMatcher(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\taStr := \"def\"\n\tanotherStr := \"ghi\"\n\n\tif match := gomock.AssignableToTypeOf(\"abc\").Matches(4); match {\n\t\tt.Errorf(`AssignableToTypeOf(\"abc\") should not match 4`)\n\t}\n\tif match := gomock.AssignableToTypeOf(\"abc\").Matches(&aStr); match {\n\t\tt.Errorf(`AssignableToTypeOf(\"abc\") should not match &aStr (*string)`)\n\t}\n\tif match := gomock.AssignableToTypeOf(\"abc\").Matches(\"def\"); !match {\n\t\tt.Errorf(`AssignableToTypeOf(\"abc\") should match \"def\"`)\n\t}\n\tif match := gomock.AssignableToTypeOf(&aStr).Matches(\"abc\"); match {\n\t\tt.Errorf(`AssignableToTypeOf(&aStr) should not match \"abc\"`)\n\t}\n\tif match := gomock.AssignableToTypeOf(&aStr).Matches(&anotherStr); !match {\n\t\tt.Errorf(`AssignableToTypeOf(&aStr) should match &anotherStr`)\n\t}\n\tif match := gomock.AssignableToTypeOf(0).Matches(4); !match {\n\t\tt.Errorf(`AssignableToTypeOf(0) should match 4`)\n\t}\n\tif match := gomock.AssignableToTypeOf(0).Matches(\"def\"); match {\n\t\tt.Errorf(`AssignableToTypeOf(0) should not match \"def\"`)\n\t}\n\tif match := gomock.AssignableToTypeOf(Dog{}).Matches(&Dog{}); match {\n\t\tt.Errorf(`AssignableToTypeOf(Dog{}) should not match &Dog{}`)\n\t}\n\tif match := gomock.AssignableToTypeOf(Dog{}).Matches(Dog{Breed: \"pug\", Name: \"Fido\"}); !match {\n\t\tt.Errorf(`AssignableToTypeOf(Dog{}) should match Dog{Breed: \"pug\", Name: \"Fido\"}`)\n\t}\n\tif match := gomock.AssignableToTypeOf(&Dog{}).Matches(Dog{}); match {\n\t\tt.Errorf(`AssignableToTypeOf(&Dog{}) should not match Dog{}`)\n\t}\n\tif match := gomock.AssignableToTypeOf(&Dog{}).Matches(&Dog{Breed: \"pug\", Name: \"Fido\"}); !match {\n\t\tt.Errorf(`AssignableToTypeOf(&Dog{}) should match &Dog{Breed: \"pug\", Name: \"Fido\"}`)\n\t}\n\n\tctxInterface := reflect.TypeOf((*context.Context)(nil)).Elem()\n\tif match := gomock.AssignableToTypeOf(ctxInterface).Matches(context.Background()); !match {\n\t\tt.Errorf(`AssignableToTypeOf(context.Context) should not match context.Background()`)\n\t}\n\n\tctxWithValue := context.WithValue(context.Background(), ctxKey{}, \"val\")\n\tif match := gomock.AssignableToTypeOf(ctxInterface).Matches(ctxWithValue); !match {\n\t\tt.Errorf(`AssignableToTypeOf(context.Context) should not match ctxWithValue`)\n\t}\n}\n\nfunc TestInAnyOrder(t *testing.T) {\n\ttests := []struct {\n\t\tname      string\n\t\twanted    interface{}\n\t\tgiven     interface{}\n\t\twantMatch bool\n\t}{\n\t\t{\n\t\t\tname:      \"match for equal slices\",\n\t\t\twanted:    []int{1, 2, 3},\n\t\t\tgiven:     []int{1, 2, 3},\n\t\t\twantMatch: true,\n\t\t},\n\t\t{\n\t\t\tname:      \"match for slices with same elements of different order\",\n\t\t\twanted:    []int{1, 2, 3},\n\t\t\tgiven:     []int{1, 3, 2},\n\t\t\twantMatch: true,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for slices with different elements\",\n\t\t\twanted:    []int{1, 2, 3},\n\t\t\tgiven:     []int{1, 2, 4},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for slices with missing elements\",\n\t\t\twanted:    []int{1, 2, 3},\n\t\t\tgiven:     []int{1, 2},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for slices with extra elements\",\n\t\t\twanted:    []int{1, 2, 3},\n\t\t\tgiven:     []int{1, 2, 3, 4},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"match for empty slices\",\n\t\t\twanted:    []int{},\n\t\t\tgiven:     []int{},\n\t\t\twantMatch: true,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for equal slices of different types\",\n\t\t\twanted:    []float64{1, 2, 3},\n\t\t\tgiven:     []int{1, 2, 3},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"match for equal arrays\",\n\t\t\twanted:    [3]int{1, 2, 3},\n\t\t\tgiven:     [3]int{1, 2, 3},\n\t\t\twantMatch: true,\n\t\t},\n\t\t{\n\t\t\tname:      \"match for equal arrays of different order\",\n\t\t\twanted:    [3]int{1, 2, 3},\n\t\t\tgiven:     [3]int{1, 3, 2},\n\t\t\twantMatch: true,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for arrays of different elements\",\n\t\t\twanted:    [3]int{1, 2, 3},\n\t\t\tgiven:     [3]int{1, 2, 4},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for arrays with extra elements\",\n\t\t\twanted:    [3]int{1, 2, 3},\n\t\t\tgiven:     [4]int{1, 2, 3, 4},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for arrays with missing elements\",\n\t\t\twanted:    [3]int{1, 2, 3},\n\t\t\tgiven:     [2]int{1, 2},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for equal strings\", // matcher shouldn't treat strings as collections\n\t\t\twanted:    \"123\",\n\t\t\tgiven:     \"123\",\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match if x type is not iterable\",\n\t\t\twanted:    123,\n\t\t\tgiven:     []int{123},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match if in type is not iterable\",\n\t\t\twanted:    []int{123},\n\t\t\tgiven:     123,\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match if both are not iterable\",\n\t\t\twanted:    123,\n\t\t\tgiven:     123,\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"match for equal slices with unhashable elements\",\n\t\t\twanted:    [][]int{{1}, {1, 2}, {1, 2, 3}},\n\t\t\tgiven:     [][]int{{1}, {1, 2}, {1, 2, 3}},\n\t\t\twantMatch: true,\n\t\t},\n\t\t{\n\t\t\tname:      \"match for equal slices with unhashable elements of different order\",\n\t\t\twanted:    [][]int{{1}, {1, 2, 3}, {1, 2}},\n\t\t\tgiven:     [][]int{{1}, {1, 2}, {1, 2, 3}},\n\t\t\twantMatch: true,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for different slices with unhashable elements\",\n\t\t\twanted:    [][]int{{1}, {1, 2, 3}, {1, 2}},\n\t\t\tgiven:     [][]int{{1}, {1, 2, 4}, {1, 3}},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for unhashable missing elements\",\n\t\t\twanted:    [][]int{{1}, {1, 2}, {1, 2, 3}},\n\t\t\tgiven:     [][]int{{1}, {1, 2}},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"not match for unhashable extra elements\",\n\t\t\twanted:    [][]int{{1}, {1, 2}},\n\t\t\tgiven:     [][]int{{1}, {1, 2}, {1, 2, 3}},\n\t\t\twantMatch: false,\n\t\t},\n\t\t{\n\t\t\tname:      \"match for equal slices of assignable types\",\n\t\t\twanted:    [][]string{{\"a\", \"b\"}},\n\t\t\tgiven:     []A{{\"a\", \"b\"}},\n\t\t\twantMatch: true,\n\t\t},\n\t}\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tif got := gomock.InAnyOrder(tt.wanted).Matches(tt.given); got != tt.wantMatch {\n\t\t\t\tt.Errorf(\"got = %v, wantMatch %v\", got, tt.wantMatch)\n\t\t\t}\n\t\t})\n\t}\n}\n"
  },
  {
    "path": "gomock/mock_test.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: example_test.go\n\n// Package gomock_test is a generated GoMock package.\npackage gomock_test\n\nimport (\n\treflect \"reflect\"\n\n\t\"github.com/golang/mock/gomock\"\n)\n\n// MockFoo is a mock of Foo interface.\ntype MockFoo struct {\n\tctrl     *gomock.Controller\n\trecorder *MockFooMockRecorder\n}\n\n// MockFooMockRecorder is the mock recorder for MockFoo.\ntype MockFooMockRecorder struct {\n\tmock *MockFoo\n}\n\n// NewMockFoo creates a new mock instance.\nfunc NewMockFoo(ctrl *gomock.Controller) *MockFoo {\n\tmock := &MockFoo{ctrl: ctrl}\n\tmock.recorder = &MockFooMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockFoo) EXPECT() *MockFooMockRecorder {\n\treturn m.recorder\n}\n\n// Bar mocks base method.\nfunc (m *MockFoo) Bar(arg0 string) string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Bar\", arg0)\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// Bar indicates an expected call of Bar.\nfunc (mr *MockFooMockRecorder) Bar(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Bar\", reflect.TypeOf((*MockFoo)(nil).Bar), arg0)\n}\n"
  },
  {
    "path": "mockgen/generic_go118.go",
    "content": "// Copyright 2022 Google LLC\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//go:build go1.18\n// +build go1.18\n\npackage main\n\nimport (\n\t\"go/ast\"\n\t\"strings\"\n\n\t\"github.com/golang/mock/mockgen/model\"\n)\n\nfunc getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field {\n\tif ts == nil || ts.TypeParams == nil {\n\t\treturn nil\n\t}\n\treturn ts.TypeParams.List\n}\n\nfunc (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) {\n\tswitch v := typ.(type) {\n\tcase *ast.IndexExpr:\n\t\tm, err := p.parseType(pkg, v.X, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tnm, ok := m.(*model.NamedType)\n\t\tif !ok {\n\t\t\treturn m, nil\n\t\t}\n\t\tt, err := p.parseType(pkg, v.Index, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tnm.TypeParams = &model.TypeParametersType{TypeParameters: []model.Type{t}}\n\t\treturn m, nil\n\tcase *ast.IndexListExpr:\n\t\tm, err := p.parseType(pkg, v.X, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tnm, ok := m.(*model.NamedType)\n\t\tif !ok {\n\t\t\treturn m, nil\n\t\t}\n\t\tvar ts []model.Type\n\t\tfor _, expr := range v.Indices {\n\t\t\tt, err := p.parseType(pkg, expr, tps)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tts = append(ts, t)\n\t\t}\n\t\tnm.TypeParams = &model.TypeParametersType{TypeParameters: ts}\n\t\treturn m, nil\n\t}\n\treturn nil, nil\n}\n\nfunc getIdentTypeParams(decl interface{}) string {\n\tif decl == nil {\n\t\treturn \"\"\n\t}\n\tts, ok := decl.(*ast.TypeSpec)\n\tif !ok {\n\t\treturn \"\"\n\t}\n\tif ts.TypeParams == nil || len(ts.TypeParams.List) == 0 {\n\t\treturn \"\"\n\t}\n\tvar sb strings.Builder\n\tsb.WriteString(\"[\")\n\tfor i, v := range ts.TypeParams.List {\n\t\tif i != 0 {\n\t\t\tsb.WriteString(\", \")\n\t\t}\n\t\tsb.WriteString(v.Names[0].Name)\n\t}\n\tsb.WriteString(\"]\")\n\treturn sb.String()\n}\n"
  },
  {
    "path": "mockgen/generic_notgo118.go",
    "content": "// Copyright 2022 Google LLC\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//go:build !go1.18\n// +build !go1.18\n\npackage main\n\nimport (\n\t\"go/ast\"\n\n\t\"github.com/golang/mock/mockgen/model\"\n)\n\nfunc getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field {\n\treturn nil\n}\n\nfunc (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) {\n\treturn nil, nil\n}\n\nfunc getIdentTypeParams(decl interface{}) string {\n\treturn \"\"\n}\n"
  },
  {
    "path": "mockgen/internal/tests/aux_imports_embedded_interface/README.md",
    "content": "# Embedded Interfaces in aux_files\n\nEmbedded interfaces in `aux_files` generate `unknown embedded interface XXX` errors.\nSee below for example of the problem:\n\n```go\n// source\nimport (\n    alias \"some.org/package/imported\"\n)\n\ntype Source interface {\n    alias.Foreign\n}\n```\n\n```go\n// some.org/package/imported\ntype Foreign interface {\n    Embedded\n}\n\ntype Embedded interface {}\n```\n\nAttempting to generate a mock will result in an `unknown embedded interface Embedded`.\nThe issue is that the `fileParser` stores `auxInterfaces` underneath the package name\nexplicitly specified in the `aux_files` flag.\n\nIn the `parseInterface` method, there is an incorrect assumption about an embedded interface\nalways being in the source file.\n\n```go\ncase *ast.Ident:\n        // Embedded interface in this package.\n        ei := p.auxInterfaces[\"\"][v.String()]\n        if ei == nil {\n                return nil, p.errorf(v.Pos(), \"unknown embedded interface %s\", v.String())\n        }\n```\n"
  },
  {
    "path": "mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go",
    "content": "package bugreport\n\n//go:generate mockgen -aux_files faux=faux/faux.go -destination bugreport_mock.go -package bugreport -source=bugreport.go Example\n\nimport (\n\t\"log\"\n\n\t\"github.com/golang/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux\"\n)\n\n// Source is an interface w/ an embedded foreign interface\ntype Source interface {\n\tfaux.Foreign\n}\n\nfunc CallForeignMethod(s Source) {\n\tlog.Println(s.Method())\n}\n"
  },
  {
    "path": "mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: bugreport.go\n\n// Package bugreport is a generated GoMock package.\npackage bugreport\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tfaux \"github.com/golang/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux\"\n)\n\n// MockSource is a mock of Source interface.\ntype MockSource struct {\n\tctrl     *gomock.Controller\n\trecorder *MockSourceMockRecorder\n}\n\n// MockSourceMockRecorder is the mock recorder for MockSource.\ntype MockSourceMockRecorder struct {\n\tmock *MockSource\n}\n\n// NewMockSource creates a new mock instance.\nfunc NewMockSource(ctrl *gomock.Controller) *MockSource {\n\tmock := &MockSource{ctrl: ctrl}\n\tmock.recorder = &MockSourceMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockSource) EXPECT() *MockSourceMockRecorder {\n\treturn m.recorder\n}\n\n// Error mocks base method.\nfunc (m *MockSource) Error() string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Error\")\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// Error indicates an expected call of Error.\nfunc (mr *MockSourceMockRecorder) Error() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Error\", reflect.TypeOf((*MockSource)(nil).Error))\n}\n\n// Method mocks base method.\nfunc (m *MockSource) Method() faux.Return {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Method\")\n\tret0, _ := ret[0].(faux.Return)\n\treturn ret0\n}\n\n// Method indicates an expected call of Method.\nfunc (mr *MockSourceMockRecorder) Method() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Method\", reflect.TypeOf((*MockSource)(nil).Method))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/aux_imports_embedded_interface/bugreport_test.go",
    "content": "package bugreport\n\nimport (\n\t\"testing\"\n\n\t\"github.com/golang/mock/gomock\"\n)\n\n// TestValidInterface assesses whether or not the generated mock is valid\nfunc TestValidInterface(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\ts := NewMockSource(ctrl)\n\ts.EXPECT().Method().Return(\"\")\n\n\tCallForeignMethod(s)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/aux_imports_embedded_interface/faux/faux.go",
    "content": "package faux\n\ntype Foreign interface {\n\tMethod() Return\n\tEmbedded\n\terror\n}\n\ntype Embedded interface{}\n\ntype Return interface{}\n"
  },
  {
    "path": "mockgen/internal/tests/const_array_length/input.go",
    "content": "package const_length\n\nimport \"math\"\n\n//go:generate mockgen -package const_length -destination mock.go -source input.go\n\nconst C = 2\n\ntype I interface {\n\tFoo() [C]int\n\tBar() [2]int\n\tBaz() [math.MaxInt8]int\n\tQux() [1 + 2]int\n\tQuux() [(1 + 2)]int\n\tCorge() [math.MaxInt8 - 120]int\n}\n"
  },
  {
    "path": "mockgen/internal/tests/const_array_length/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: input.go\n\n// Package const_length is a generated GoMock package.\npackage const_length\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockI is a mock of I interface.\ntype MockI struct {\n\tctrl     *gomock.Controller\n\trecorder *MockIMockRecorder\n}\n\n// MockIMockRecorder is the mock recorder for MockI.\ntype MockIMockRecorder struct {\n\tmock *MockI\n}\n\n// NewMockI creates a new mock instance.\nfunc NewMockI(ctrl *gomock.Controller) *MockI {\n\tmock := &MockI{ctrl: ctrl}\n\tmock.recorder = &MockIMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockI) EXPECT() *MockIMockRecorder {\n\treturn m.recorder\n}\n\n// Bar mocks base method.\nfunc (m *MockI) Bar() [2]int {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Bar\")\n\tret0, _ := ret[0].([2]int)\n\treturn ret0\n}\n\n// Bar indicates an expected call of Bar.\nfunc (mr *MockIMockRecorder) Bar() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Bar\", reflect.TypeOf((*MockI)(nil).Bar))\n}\n\n// Baz mocks base method.\nfunc (m *MockI) Baz() [127]int {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Baz\")\n\tret0, _ := ret[0].([127]int)\n\treturn ret0\n}\n\n// Baz indicates an expected call of Baz.\nfunc (mr *MockIMockRecorder) Baz() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Baz\", reflect.TypeOf((*MockI)(nil).Baz))\n}\n\n// Corge mocks base method.\nfunc (m *MockI) Corge() [7]int {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Corge\")\n\tret0, _ := ret[0].([7]int)\n\treturn ret0\n}\n\n// Corge indicates an expected call of Corge.\nfunc (mr *MockIMockRecorder) Corge() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Corge\", reflect.TypeOf((*MockI)(nil).Corge))\n}\n\n// Foo mocks base method.\nfunc (m *MockI) Foo() [2]int {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Foo\")\n\tret0, _ := ret[0].([2]int)\n\treturn ret0\n}\n\n// Foo indicates an expected call of Foo.\nfunc (mr *MockIMockRecorder) Foo() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Foo\", reflect.TypeOf((*MockI)(nil).Foo))\n}\n\n// Quux mocks base method.\nfunc (m *MockI) Quux() [3]int {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Quux\")\n\tret0, _ := ret[0].([3]int)\n\treturn ret0\n}\n\n// Quux indicates an expected call of Quux.\nfunc (mr *MockIMockRecorder) Quux() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Quux\", reflect.TypeOf((*MockI)(nil).Quux))\n}\n\n// Qux mocks base method.\nfunc (m *MockI) Qux() [3]int {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Qux\")\n\tret0, _ := ret[0].([3]int)\n\treturn ret0\n}\n\n// Qux indicates an expected call of Qux.\nfunc (mr *MockIMockRecorder) Qux() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Qux\", reflect.TypeOf((*MockI)(nil).Qux))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/copyright_file/input.go",
    "content": "package empty_interface\n\n//go:generate mockgen -package empty_interface -destination mock.go -source input.go -copyright_file=mock_copyright_header\n\ntype Empty interface{}\n"
  },
  {
    "path": "mockgen/internal/tests/copyright_file/mock.go",
    "content": "// This is a mock copyright header.\n//\n// Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n// sed do eiusmod tempor incididunt ut labore et dolore magna\n// aliqua. Velit ut tortor pretium viverra suspendisse potenti.\n//\n\n// Code generated by MockGen. DO NOT EDIT.\n// Source: input.go\n\n// Package empty_interface is a generated GoMock package.\npackage empty_interface\n\nimport (\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockEmpty is a mock of Empty interface.\ntype MockEmpty struct {\n\tctrl     *gomock.Controller\n\trecorder *MockEmptyMockRecorder\n}\n\n// MockEmptyMockRecorder is the mock recorder for MockEmpty.\ntype MockEmptyMockRecorder struct {\n\tmock *MockEmpty\n}\n\n// NewMockEmpty creates a new mock instance.\nfunc NewMockEmpty(ctrl *gomock.Controller) *MockEmpty {\n\tmock := &MockEmpty{ctrl: ctrl}\n\tmock.recorder = &MockEmptyMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockEmpty) EXPECT() *MockEmptyMockRecorder {\n\treturn m.recorder\n}\n"
  },
  {
    "path": "mockgen/internal/tests/copyright_file/mock_copyright_header",
    "content": "This is a mock copyright header.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna \naliqua. Velit ut tortor pretium viverra suspendisse potenti.\n"
  },
  {
    "path": "mockgen/internal/tests/custom_package_name/README.md",
    "content": "# Tests for custom package names\n\nThis directory contains test for mockgen generating mocks when imported package\nname does not match import path suffix. For example, package with name \"client\"\nis located under import path \"github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1\".\n\nPrior to this patch:\n\n```bash\n$ go generate greeter/greeter.go\n2018/03/05 22:44:52 Loading input failed: greeter.go:17:11: failed parsing returns: greeter.go:17:14: unknown package \"client\"\ngreeter/greeter.go:1: running \"mockgen\": exit status 1\n```\n\nThis can be fixed by manually providing `-imports` flag, like `-imports client=github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1`.\nBut, mockgen should be able to automatically resolve package names in such situations.\n\nWith this patch applied:\n\n```bash\n$ go generate greeter/greeter.go\n$ echo $?\n0\n```\n\nMockgen runs successfully, produced output is equal to [greeter_mock_test.go](greeter/greeter_mock_test.go) content.\n"
  },
  {
    "path": "mockgen/internal/tests/custom_package_name/client/v1/client.go",
    "content": "package client\n\nimport \"fmt\"\n\ntype Client struct{}\n\nfunc (c *Client) Greet(in GreetInput) string {\n\treturn fmt.Sprintf(\"Hello, %s!\", in.Name)\n}\n\ntype GreetInput struct {\n\tName string\n}\n"
  },
  {
    "path": "mockgen/internal/tests/custom_package_name/greeter/greeter.go",
    "content": "package greeter\n\n//go:generate mockgen -source greeter.go -destination greeter_mock_test.go -package greeter\n\nimport (\n\t// stdlib import\n\t\"fmt\"\n\n\t// non-matching import suffix and package name\n\t\"github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1\"\n\n\t//  matching import suffix and package name\n\t\"github.com/golang/mock/mockgen/internal/tests/custom_package_name/validator\"\n)\n\ntype InputMaker interface {\n\tMakeInput() client.GreetInput\n}\n\ntype Greeter struct {\n\tInputMaker InputMaker\n\tClient     *client.Client\n}\n\nfunc (g *Greeter) Greet() (string, error) {\n\tin := g.InputMaker.MakeInput()\n\tif err := validator.Validate(in.Name); err != nil {\n\t\treturn \"\", fmt.Errorf(\"validation failed: %v\", err)\n\t}\n\treturn g.Client.Greet(in), nil\n}\n"
  },
  {
    "path": "mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: greeter.go\n\n// Package greeter is a generated GoMock package.\npackage greeter\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tclient \"github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1\"\n)\n\n// MockInputMaker is a mock of InputMaker interface.\ntype MockInputMaker struct {\n\tctrl     *gomock.Controller\n\trecorder *MockInputMakerMockRecorder\n}\n\n// MockInputMakerMockRecorder is the mock recorder for MockInputMaker.\ntype MockInputMakerMockRecorder struct {\n\tmock *MockInputMaker\n}\n\n// NewMockInputMaker creates a new mock instance.\nfunc NewMockInputMaker(ctrl *gomock.Controller) *MockInputMaker {\n\tmock := &MockInputMaker{ctrl: ctrl}\n\tmock.recorder = &MockInputMakerMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockInputMaker) EXPECT() *MockInputMakerMockRecorder {\n\treturn m.recorder\n}\n\n// MakeInput mocks base method.\nfunc (m *MockInputMaker) MakeInput() client.GreetInput {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"MakeInput\")\n\tret0, _ := ret[0].(client.GreetInput)\n\treturn ret0\n}\n\n// MakeInput indicates an expected call of MakeInput.\nfunc (mr *MockInputMakerMockRecorder) MakeInput() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"MakeInput\", reflect.TypeOf((*MockInputMaker)(nil).MakeInput))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/custom_package_name/greeter/greeter_test.go",
    "content": "package greeter\n\nimport (\n\t\"testing\"\n\n\t\"github.com/golang/mock/gomock\"\n\t\"github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1\"\n)\n\nfunc TestGreeter_Greet(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\tinput := client.GreetInput{\n\t\tName: \"Foo\",\n\t}\n\n\tinputMaker := NewMockInputMaker(ctrl)\n\tinputMaker.EXPECT().\n\t\tMakeInput().\n\t\tReturn(input)\n\n\tg := &Greeter{\n\t\tInputMaker: inputMaker,\n\t\tClient:     &client.Client{},\n\t}\n\n\tgreeting, err := g.Greet()\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := \"Hello, Foo!\"\n\tif greeting != expected {\n\t\tt.Fatalf(\"Expected greeting to be %v but got %v\", expected, greeting)\n\t}\n}\n"
  },
  {
    "path": "mockgen/internal/tests/custom_package_name/validator/validate.go",
    "content": "package validator\n\nfunc Validate(s string) error {\n\treturn nil\n}\n"
  },
  {
    "path": "mockgen/internal/tests/dot_imports/input.go",
    "content": "package dot_imports\n\n//go:generate mockgen -package dot_imports -destination mock.go -source input.go\n\nimport (\n\t\"bytes\"\n\t. \"context\"\n\t. \"net/http\"\n)\n\ntype WithDotImports interface {\n\tMethod1() Request\n\tMethod2() *bytes.Buffer\n\tMethod3() Context\n}\n"
  },
  {
    "path": "mockgen/internal/tests/dot_imports/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: input.go\n\n// Package dot_imports is a generated GoMock package.\npackage dot_imports\n\nimport (\n\tbytes \"bytes\"\n\t. \"context\"\n\t. \"net/http\"\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockWithDotImports is a mock of WithDotImports interface.\ntype MockWithDotImports struct {\n\tctrl     *gomock.Controller\n\trecorder *MockWithDotImportsMockRecorder\n}\n\n// MockWithDotImportsMockRecorder is the mock recorder for MockWithDotImports.\ntype MockWithDotImportsMockRecorder struct {\n\tmock *MockWithDotImports\n}\n\n// NewMockWithDotImports creates a new mock instance.\nfunc NewMockWithDotImports(ctrl *gomock.Controller) *MockWithDotImports {\n\tmock := &MockWithDotImports{ctrl: ctrl}\n\tmock.recorder = &MockWithDotImportsMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockWithDotImports) EXPECT() *MockWithDotImportsMockRecorder {\n\treturn m.recorder\n}\n\n// Method1 mocks base method.\nfunc (m *MockWithDotImports) Method1() Request {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Method1\")\n\tret0, _ := ret[0].(Request)\n\treturn ret0\n}\n\n// Method1 indicates an expected call of Method1.\nfunc (mr *MockWithDotImportsMockRecorder) Method1() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Method1\", reflect.TypeOf((*MockWithDotImports)(nil).Method1))\n}\n\n// Method2 mocks base method.\nfunc (m *MockWithDotImports) Method2() *bytes.Buffer {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Method2\")\n\tret0, _ := ret[0].(*bytes.Buffer)\n\treturn ret0\n}\n\n// Method2 indicates an expected call of Method2.\nfunc (mr *MockWithDotImportsMockRecorder) Method2() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Method2\", reflect.TypeOf((*MockWithDotImports)(nil).Method2))\n}\n\n// Method3 mocks base method.\nfunc (m *MockWithDotImports) Method3() Context {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Method3\")\n\tret0, _ := ret[0].(Context)\n\treturn ret0\n}\n\n// Method3 indicates an expected call of Method3.\nfunc (mr *MockWithDotImportsMockRecorder) Method3() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Method3\", reflect.TypeOf((*MockWithDotImports)(nil).Method3))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/empty_interface/input.go",
    "content": "package empty_interface\n\n//go:generate mockgen -package empty_interface -destination mock.go -source input.go\n\ntype Empty interface{}\n"
  },
  {
    "path": "mockgen/internal/tests/empty_interface/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: input.go\n\n// Package empty_interface is a generated GoMock package.\npackage empty_interface\n\nimport (\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockEmpty is a mock of Empty interface.\ntype MockEmpty struct {\n\tctrl     *gomock.Controller\n\trecorder *MockEmptyMockRecorder\n}\n\n// MockEmptyMockRecorder is the mock recorder for MockEmpty.\ntype MockEmptyMockRecorder struct {\n\tmock *MockEmpty\n}\n\n// NewMockEmpty creates a new mock instance.\nfunc NewMockEmpty(ctrl *gomock.Controller) *MockEmpty {\n\tmock := &MockEmpty{ctrl: ctrl}\n\tmock.recorder = &MockEmptyMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockEmpty) EXPECT() *MockEmptyMockRecorder {\n\treturn m.recorder\n}\n"
  },
  {
    "path": "mockgen/internal/tests/extra_import/import.go",
    "content": "// Package extra_import makes sure output does not import it. See #515.\npackage extra_import\n\n//go:generate mockgen -destination mock.go -package extra_import . Foo\n\ntype Message struct {\n\tText string\n}\n\ntype Foo interface {\n\tBar(channels []string, message chan<- Message)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/extra_import/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: github.com/golang/mock/mockgen/internal/tests/extra_import (interfaces: Foo)\n\n// Package extra_import is a generated GoMock package.\npackage extra_import\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockFoo is a mock of Foo interface.\ntype MockFoo struct {\n\tctrl     *gomock.Controller\n\trecorder *MockFooMockRecorder\n}\n\n// MockFooMockRecorder is the mock recorder for MockFoo.\ntype MockFooMockRecorder struct {\n\tmock *MockFoo\n}\n\n// NewMockFoo creates a new mock instance.\nfunc NewMockFoo(ctrl *gomock.Controller) *MockFoo {\n\tmock := &MockFoo{ctrl: ctrl}\n\tmock.recorder = &MockFooMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockFoo) EXPECT() *MockFooMockRecorder {\n\treturn m.recorder\n}\n\n// Bar mocks base method.\nfunc (m *MockFoo) Bar(arg0 []string, arg1 chan<- Message) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Bar\", arg0, arg1)\n}\n\n// Bar indicates an expected call of Bar.\nfunc (mr *MockFooMockRecorder) Bar(arg0, arg1 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Bar\", reflect.TypeOf((*MockFoo)(nil).Bar), arg0, arg1)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/generated_identifier_conflict/README.md",
    "content": "# Generated Identifier Conflict\n\nThe generated mock methods use some hardcoded variable/receiver names that can\nhave conflicts with the argument names that are defined by the code for which\nthe mock is generated when using the source generation method.\n\nExample:\n\n```go\ntype Example interface {\n    Method(_m, _mr, m, mr int)\n}\n```\n\n```go\n// Method mocks base method\nfunc (_m *MockExample) Method(_m int, _mr int, m int, mr int) {\n    _m.ctrl.Call(_m, \"Method\", _m, _mr, m, mr)\n}\n```\n\nIn the above example one of the interface method parameters is called `_m`\nbut unfortunately the generated receiver name is also called `_m` so the\nmock code won't compile.\n\nThe generator has to make sure that generated identifiers (e.g.: the receiver\nnames) are always different from the arg names that might come from external\nsources.\n"
  },
  {
    "path": "mockgen/internal/tests/generated_identifier_conflict/bugreport.go",
    "content": "package bugreport\n\n//go:generate mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go\n\ntype Example interface {\n\t// _m and _mr were used by the buggy code: the '_' prefix was there hoping\n\t// that no one will use method argument names starting with '_' reducing\n\t// the chance of collision with generated identifiers.\n\t// m and mr are used by the bugfixed new code, the '_' prefix has been\n\t// removed because the new code generator changes the names of the\n\t// generated identifiers in case they would collide with identifiers\n\t// coming from argument names.\n\tMethod(_m, _mr, m, mr int)\n\n\tVarargMethod(_s, _x, a, ret int, varargs ...int)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: bugreport.go\n\n// Package bugreport is a generated GoMock package.\npackage bugreport\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockExample is a mock of Example interface.\ntype MockExample struct {\n\tctrl     *gomock.Controller\n\trecorder *MockExampleMockRecorder\n}\n\n// MockExampleMockRecorder is the mock recorder for MockExample.\ntype MockExampleMockRecorder struct {\n\tmock *MockExample\n}\n\n// NewMockExample creates a new mock instance.\nfunc NewMockExample(ctrl *gomock.Controller) *MockExample {\n\tmock := &MockExample{ctrl: ctrl}\n\tmock.recorder = &MockExampleMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockExample) EXPECT() *MockExampleMockRecorder {\n\treturn m.recorder\n}\n\n// Method mocks base method.\nfunc (m_2 *MockExample) Method(_m, _mr, m, mr int) {\n\tm_2.ctrl.T.Helper()\n\tm_2.ctrl.Call(m_2, \"Method\", _m, _mr, m, mr)\n}\n\n// Method indicates an expected call of Method.\nfunc (mr_2 *MockExampleMockRecorder) Method(_m, _mr, m, mr interface{}) *gomock.Call {\n\tmr_2.mock.ctrl.T.Helper()\n\treturn mr_2.mock.ctrl.RecordCallWithMethodType(mr_2.mock, \"Method\", reflect.TypeOf((*MockExample)(nil).Method), _m, _mr, m, mr)\n}\n\n// VarargMethod mocks base method.\nfunc (m *MockExample) VarargMethod(_s, _x, a, ret int, varargs ...int) {\n\tm.ctrl.T.Helper()\n\tvarargs_2 := []interface{}{_s, _x, a, ret}\n\tfor _, a_2 := range varargs {\n\t\tvarargs_2 = append(varargs_2, a_2)\n\t}\n\tm.ctrl.Call(m, \"VarargMethod\", varargs_2...)\n}\n\n// VarargMethod indicates an expected call of VarargMethod.\nfunc (mr *MockExampleMockRecorder) VarargMethod(_s, _x, a, ret interface{}, varargs ...interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\tvarargs_2 := append([]interface{}{_s, _x, a, ret}, varargs...)\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"VarargMethod\", reflect.TypeOf((*MockExample)(nil).VarargMethod), varargs_2...)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go",
    "content": "package bugreport\n\nimport (\n\t\"github.com/golang/mock/gomock\"\n\t\"testing\"\n)\n\nfunc TestExample_Method(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tm := NewMockExample(ctrl)\n\tm.EXPECT().Method(1, 2, 3, 4)\n\n\tm.Method(1, 2, 3, 4)\n\n\tctrl.Finish()\n}\n\nfunc TestExample_VarargMethod(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tm := NewMockExample(ctrl)\n\tm.EXPECT().VarargMethod(1, 2, 3, 4, 6, 7)\n\n\tm.VarargMethod(1, 2, 3, 4, 6, 7)\n\n\tctrl.Finish()\n}\n"
  },
  {
    "path": "mockgen/internal/tests/generics/external.go",
    "content": "package generics\n\nimport (\n\t\"github.com/golang/mock/mockgen/internal/tests/generics/other\"\n\t\"golang.org/x/exp/constraints\"\n)\n\n//go:generate mockgen --source=external.go --destination=source/mock_external_test.go --package source\n\ntype ExternalConstraint[I constraints.Integer, F constraints.Float] interface {\n\tOne(string) string\n\tTwo(I) string\n\tThree(I) F\n\tFour(I) Foo[I, F]\n\tFive(I) Baz[F]\n\tSix(I) *Baz[F]\n\tSeven(I) other.One[I]\n\tEight(F) other.Two[I, F]\n\tNine(Iface[I])\n\tTen(*I)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/generics/generics.go",
    "content": "package generics\n\nimport \"github.com/golang/mock/mockgen/internal/tests/generics/other\"\n\n//go:generate mockgen --source=generics.go --destination=source/mock_generics_test.go --package source\n////go:generate mockgen --destination=reflect/mock_test.go --package reflect . Bar,Bar2\n\ntype Bar[T any, R any] interface {\n\tOne(string) string\n\tTwo(T) string\n\tThree(T) R\n\tFour(T) Foo[T, R]\n\tFive(T) Baz[T]\n\tSix(T) *Baz[T]\n\tSeven(T) other.One[T]\n\tEight(T) other.Two[T, R]\n\tNine(Iface[T])\n\tTen(*T)\n\tEleven() (*other.One[T], error)\n\tTwelve() (*other.Two[T, R], error)\n\tThirteen() (Baz[StructType], error)\n\tFourteen() (*Foo[StructType, StructType2], error)\n\tFifteen() (Iface[StructType], error)\n\tSixteen() (Baz[other.Three], error)\n\tSeventeen() (*Foo[other.Three, other.Four], error)\n\tEighteen() (Iface[*other.Five], error)\n\tNineteen() AliasType\n}\n\ntype Foo[T any, R any] struct{}\n\ntype Baz[T any] struct{}\n\ntype Iface[T any] interface{}\n\ntype StructType struct{}\n\ntype StructType2 struct{}\n\ntype AliasType Baz[other.Three]\n"
  },
  {
    "path": "mockgen/internal/tests/generics/go.mod",
    "content": "module github.com/golang/mock/mockgen/internal/tests/generics\n\ngo 1.18\n\nrequire (\n\tgithub.com/golang/mock v1.6.0\n\tgolang.org/x/exp v0.0.0-20220428152302-39d4317da171\n)\n\nreplace github.com/golang/mock => ../../../..\n"
  },
  {
    "path": "mockgen/internal/tests/generics/go.sum",
    "content": "github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=\ngolang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\ngolang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=\ngolang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4=\ngolang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=\ngolang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=\ngolang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=\ngolang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=\ngolang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=\ngolang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=\ngolang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\ngolang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=\ngolang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=\ngolang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=\ngolang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=\ngolang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=\ngolang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\ngolang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\ngolang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\n"
  },
  {
    "path": "mockgen/internal/tests/generics/other/other.go",
    "content": "package other\n\ntype One[T any] struct{}\n\ntype Two[T any, R any] struct{}\n\ntype Three struct{}\n\ntype Four struct{}\n\ntype Five interface{}\n"
  },
  {
    "path": "mockgen/internal/tests/generics/source/mock_external_test.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: external.go\n\n// Package source is a generated GoMock package.\npackage source\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tgenerics \"github.com/golang/mock/mockgen/internal/tests/generics\"\n\tother \"github.com/golang/mock/mockgen/internal/tests/generics/other\"\n\tconstraints \"golang.org/x/exp/constraints\"\n)\n\n// MockExternalConstraint is a mock of ExternalConstraint interface.\ntype MockExternalConstraint[I constraints.Integer, F constraints.Float] struct {\n\tctrl     *gomock.Controller\n\trecorder *MockExternalConstraintMockRecorder[I, F]\n}\n\n// MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint.\ntype MockExternalConstraintMockRecorder[I constraints.Integer, F constraints.Float] struct {\n\tmock *MockExternalConstraint[I, F]\n}\n\n// NewMockExternalConstraint creates a new mock instance.\nfunc NewMockExternalConstraint[I constraints.Integer, F constraints.Float](ctrl *gomock.Controller) *MockExternalConstraint[I, F] {\n\tmock := &MockExternalConstraint[I, F]{ctrl: ctrl}\n\tmock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecorder[I, F] {\n\treturn m.recorder\n}\n\n// Eight mocks base method.\nfunc (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Eight\", arg0)\n\tret0, _ := ret[0].(other.Two[I, F])\n\treturn ret0\n}\n\n// Eight indicates an expected call of Eight.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Eight\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0)\n}\n\n// Five mocks base method.\nfunc (m *MockExternalConstraint[I, F]) Five(arg0 I) generics.Baz[F] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Five\", arg0)\n\tret0, _ := ret[0].(generics.Baz[F])\n\treturn ret0\n}\n\n// Five indicates an expected call of Five.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) Five(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Five\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Five), arg0)\n}\n\n// Four mocks base method.\nfunc (m *MockExternalConstraint[I, F]) Four(arg0 I) generics.Foo[I, F] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Four\", arg0)\n\tret0, _ := ret[0].(generics.Foo[I, F])\n\treturn ret0\n}\n\n// Four indicates an expected call of Four.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) Four(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Four\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Four), arg0)\n}\n\n// Nine mocks base method.\nfunc (m *MockExternalConstraint[I, F]) Nine(arg0 generics.Iface[I]) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Nine\", arg0)\n}\n\n// Nine indicates an expected call of Nine.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) Nine(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Nine\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Nine), arg0)\n}\n\n// One mocks base method.\nfunc (m *MockExternalConstraint[I, F]) One(arg0 string) string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"One\", arg0)\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// One indicates an expected call of One.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) One(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"One\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).One), arg0)\n}\n\n// Seven mocks base method.\nfunc (m *MockExternalConstraint[I, F]) Seven(arg0 I) other.One[I] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Seven\", arg0)\n\tret0, _ := ret[0].(other.One[I])\n\treturn ret0\n}\n\n// Seven indicates an expected call of Seven.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) Seven(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Seven\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Seven), arg0)\n}\n\n// Six mocks base method.\nfunc (m *MockExternalConstraint[I, F]) Six(arg0 I) *generics.Baz[F] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Six\", arg0)\n\tret0, _ := ret[0].(*generics.Baz[F])\n\treturn ret0\n}\n\n// Six indicates an expected call of Six.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) Six(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Six\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Six), arg0)\n}\n\n// Ten mocks base method.\nfunc (m *MockExternalConstraint[I, F]) Ten(arg0 *I) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Ten\", arg0)\n}\n\n// Ten indicates an expected call of Ten.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Ten\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0)\n}\n\n// Three mocks base method.\nfunc (m *MockExternalConstraint[I, F]) Three(arg0 I) F {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Three\", arg0)\n\tret0, _ := ret[0].(F)\n\treturn ret0\n}\n\n// Three indicates an expected call of Three.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Three\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0)\n}\n\n// Two mocks base method.\nfunc (m *MockExternalConstraint[I, F]) Two(arg0 I) string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Two\", arg0)\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// Two indicates an expected call of Two.\nfunc (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Two\", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/generics/source/mock_generics_test.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: generics.go\n\n// Package source is a generated GoMock package.\npackage source\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tgenerics \"github.com/golang/mock/mockgen/internal/tests/generics\"\n\tother \"github.com/golang/mock/mockgen/internal/tests/generics/other\"\n)\n\n// MockBar is a mock of Bar interface.\ntype MockBar[T any, R any] struct {\n\tctrl     *gomock.Controller\n\trecorder *MockBarMockRecorder[T, R]\n}\n\n// MockBarMockRecorder is the mock recorder for MockBar.\ntype MockBarMockRecorder[T any, R any] struct {\n\tmock *MockBar[T, R]\n}\n\n// NewMockBar creates a new mock instance.\nfunc NewMockBar[T any, R any](ctrl *gomock.Controller) *MockBar[T, R] {\n\tmock := &MockBar[T, R]{ctrl: ctrl}\n\tmock.recorder = &MockBarMockRecorder[T, R]{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockBar[T, R]) EXPECT() *MockBarMockRecorder[T, R] {\n\treturn m.recorder\n}\n\n// Eight mocks base method.\nfunc (m *MockBar[T, R]) Eight(arg0 T) other.Two[T, R] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Eight\", arg0)\n\tret0, _ := ret[0].(other.Two[T, R])\n\treturn ret0\n}\n\n// Eight indicates an expected call of Eight.\nfunc (mr *MockBarMockRecorder[T, R]) Eight(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Eight\", reflect.TypeOf((*MockBar[T, R])(nil).Eight), arg0)\n}\n\n// Eighteen mocks base method.\nfunc (m *MockBar[T, R]) Eighteen() (generics.Iface[*other.Five], error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Eighteen\")\n\tret0, _ := ret[0].(generics.Iface[*other.Five])\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Eighteen indicates an expected call of Eighteen.\nfunc (mr *MockBarMockRecorder[T, R]) Eighteen() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Eighteen\", reflect.TypeOf((*MockBar[T, R])(nil).Eighteen))\n}\n\n// Eleven mocks base method.\nfunc (m *MockBar[T, R]) Eleven() (*other.One[T], error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Eleven\")\n\tret0, _ := ret[0].(*other.One[T])\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Eleven indicates an expected call of Eleven.\nfunc (mr *MockBarMockRecorder[T, R]) Eleven() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Eleven\", reflect.TypeOf((*MockBar[T, R])(nil).Eleven))\n}\n\n// Fifteen mocks base method.\nfunc (m *MockBar[T, R]) Fifteen() (generics.Iface[generics.StructType], error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Fifteen\")\n\tret0, _ := ret[0].(generics.Iface[generics.StructType])\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Fifteen indicates an expected call of Fifteen.\nfunc (mr *MockBarMockRecorder[T, R]) Fifteen() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Fifteen\", reflect.TypeOf((*MockBar[T, R])(nil).Fifteen))\n}\n\n// Five mocks base method.\nfunc (m *MockBar[T, R]) Five(arg0 T) generics.Baz[T] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Five\", arg0)\n\tret0, _ := ret[0].(generics.Baz[T])\n\treturn ret0\n}\n\n// Five indicates an expected call of Five.\nfunc (mr *MockBarMockRecorder[T, R]) Five(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Five\", reflect.TypeOf((*MockBar[T, R])(nil).Five), arg0)\n}\n\n// Four mocks base method.\nfunc (m *MockBar[T, R]) Four(arg0 T) generics.Foo[T, R] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Four\", arg0)\n\tret0, _ := ret[0].(generics.Foo[T, R])\n\treturn ret0\n}\n\n// Four indicates an expected call of Four.\nfunc (mr *MockBarMockRecorder[T, R]) Four(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Four\", reflect.TypeOf((*MockBar[T, R])(nil).Four), arg0)\n}\n\n// Fourteen mocks base method.\nfunc (m *MockBar[T, R]) Fourteen() (*generics.Foo[generics.StructType, generics.StructType2], error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Fourteen\")\n\tret0, _ := ret[0].(*generics.Foo[generics.StructType, generics.StructType2])\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Fourteen indicates an expected call of Fourteen.\nfunc (mr *MockBarMockRecorder[T, R]) Fourteen() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Fourteen\", reflect.TypeOf((*MockBar[T, R])(nil).Fourteen))\n}\n\n// Nine mocks base method.\nfunc (m *MockBar[T, R]) Nine(arg0 generics.Iface[T]) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Nine\", arg0)\n}\n\n// Nine indicates an expected call of Nine.\nfunc (mr *MockBarMockRecorder[T, R]) Nine(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Nine\", reflect.TypeOf((*MockBar[T, R])(nil).Nine), arg0)\n}\n\n// Nineteen mocks base method.\nfunc (m *MockBar[T, R]) Nineteen() generics.AliasType {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Nineteen\")\n\tret0, _ := ret[0].(generics.AliasType)\n\treturn ret0\n}\n\n// Nineteen indicates an expected call of Nineteen.\nfunc (mr *MockBarMockRecorder[T, R]) Nineteen() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Nineteen\", reflect.TypeOf((*MockBar[T, R])(nil).Nineteen))\n}\n\n// One mocks base method.\nfunc (m *MockBar[T, R]) One(arg0 string) string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"One\", arg0)\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// One indicates an expected call of One.\nfunc (mr *MockBarMockRecorder[T, R]) One(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"One\", reflect.TypeOf((*MockBar[T, R])(nil).One), arg0)\n}\n\n// Seven mocks base method.\nfunc (m *MockBar[T, R]) Seven(arg0 T) other.One[T] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Seven\", arg0)\n\tret0, _ := ret[0].(other.One[T])\n\treturn ret0\n}\n\n// Seven indicates an expected call of Seven.\nfunc (mr *MockBarMockRecorder[T, R]) Seven(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Seven\", reflect.TypeOf((*MockBar[T, R])(nil).Seven), arg0)\n}\n\n// Seventeen mocks base method.\nfunc (m *MockBar[T, R]) Seventeen() (*generics.Foo[other.Three, other.Four], error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Seventeen\")\n\tret0, _ := ret[0].(*generics.Foo[other.Three, other.Four])\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Seventeen indicates an expected call of Seventeen.\nfunc (mr *MockBarMockRecorder[T, R]) Seventeen() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Seventeen\", reflect.TypeOf((*MockBar[T, R])(nil).Seventeen))\n}\n\n// Six mocks base method.\nfunc (m *MockBar[T, R]) Six(arg0 T) *generics.Baz[T] {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Six\", arg0)\n\tret0, _ := ret[0].(*generics.Baz[T])\n\treturn ret0\n}\n\n// Six indicates an expected call of Six.\nfunc (mr *MockBarMockRecorder[T, R]) Six(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Six\", reflect.TypeOf((*MockBar[T, R])(nil).Six), arg0)\n}\n\n// Sixteen mocks base method.\nfunc (m *MockBar[T, R]) Sixteen() (generics.Baz[other.Three], error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Sixteen\")\n\tret0, _ := ret[0].(generics.Baz[other.Three])\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Sixteen indicates an expected call of Sixteen.\nfunc (mr *MockBarMockRecorder[T, R]) Sixteen() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Sixteen\", reflect.TypeOf((*MockBar[T, R])(nil).Sixteen))\n}\n\n// Ten mocks base method.\nfunc (m *MockBar[T, R]) Ten(arg0 *T) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Ten\", arg0)\n}\n\n// Ten indicates an expected call of Ten.\nfunc (mr *MockBarMockRecorder[T, R]) Ten(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Ten\", reflect.TypeOf((*MockBar[T, R])(nil).Ten), arg0)\n}\n\n// Thirteen mocks base method.\nfunc (m *MockBar[T, R]) Thirteen() (generics.Baz[generics.StructType], error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Thirteen\")\n\tret0, _ := ret[0].(generics.Baz[generics.StructType])\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Thirteen indicates an expected call of Thirteen.\nfunc (mr *MockBarMockRecorder[T, R]) Thirteen() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Thirteen\", reflect.TypeOf((*MockBar[T, R])(nil).Thirteen))\n}\n\n// Three mocks base method.\nfunc (m *MockBar[T, R]) Three(arg0 T) R {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Three\", arg0)\n\tret0, _ := ret[0].(R)\n\treturn ret0\n}\n\n// Three indicates an expected call of Three.\nfunc (mr *MockBarMockRecorder[T, R]) Three(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Three\", reflect.TypeOf((*MockBar[T, R])(nil).Three), arg0)\n}\n\n// Twelve mocks base method.\nfunc (m *MockBar[T, R]) Twelve() (*other.Two[T, R], error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Twelve\")\n\tret0, _ := ret[0].(*other.Two[T, R])\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Twelve indicates an expected call of Twelve.\nfunc (mr *MockBarMockRecorder[T, R]) Twelve() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Twelve\", reflect.TypeOf((*MockBar[T, R])(nil).Twelve))\n}\n\n// Two mocks base method.\nfunc (m *MockBar[T, R]) Two(arg0 T) string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Two\", arg0)\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// Two indicates an expected call of Two.\nfunc (mr *MockBarMockRecorder[T, R]) Two(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Two\", reflect.TypeOf((*MockBar[T, R])(nil).Two), arg0)\n}\n\n// MockIface is a mock of Iface interface.\ntype MockIface[T any] struct {\n\tctrl     *gomock.Controller\n\trecorder *MockIfaceMockRecorder[T]\n}\n\n// MockIfaceMockRecorder is the mock recorder for MockIface.\ntype MockIfaceMockRecorder[T any] struct {\n\tmock *MockIface[T]\n}\n\n// NewMockIface creates a new mock instance.\nfunc NewMockIface[T any](ctrl *gomock.Controller) *MockIface[T] {\n\tmock := &MockIface[T]{ctrl: ctrl}\n\tmock.recorder = &MockIfaceMockRecorder[T]{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockIface[T]) EXPECT() *MockIfaceMockRecorder[T] {\n\treturn m.recorder\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/bugreport.go",
    "content": "// Copyright 2020 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bugreport\n\n//go:generate mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go\n\nimport (\n\t\"log\"\n\n\t\"github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/ersatz\"\n\t\"github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/faux\"\n)\n\n// Source is an interface w/ an embedded foreign interface\ntype Source interface {\n\tersatz.Embedded\n\tfaux.Foreign\n\terror\n\tFoo\n}\n\nfunc CallForeignMethod(s Source) {\n\tlog.Println(s.Ersatz())\n\tlog.Println(s.OtherErsatz())\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/bugreport_mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: bugreport.go\n\n// Package bugreport is a generated GoMock package.\npackage bugreport\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tersatz \"github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/ersatz\"\n\tersatz0 \"github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz\"\n)\n\n// MockSource is a mock of Source interface.\ntype MockSource struct {\n\tctrl     *gomock.Controller\n\trecorder *MockSourceMockRecorder\n}\n\n// MockSourceMockRecorder is the mock recorder for MockSource.\ntype MockSourceMockRecorder struct {\n\tmock *MockSource\n}\n\n// NewMockSource creates a new mock instance.\nfunc NewMockSource(ctrl *gomock.Controller) *MockSource {\n\tmock := &MockSource{ctrl: ctrl}\n\tmock.recorder = &MockSourceMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockSource) EXPECT() *MockSourceMockRecorder {\n\treturn m.recorder\n}\n\n// Bar mocks base method.\nfunc (m *MockSource) Bar() Baz {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Bar\")\n\tret0, _ := ret[0].(Baz)\n\treturn ret0\n}\n\n// Bar indicates an expected call of Bar.\nfunc (mr *MockSourceMockRecorder) Bar() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Bar\", reflect.TypeOf((*MockSource)(nil).Bar))\n}\n\n// Error mocks base method.\nfunc (m *MockSource) Error() string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Error\")\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// Error indicates an expected call of Error.\nfunc (mr *MockSourceMockRecorder) Error() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Error\", reflect.TypeOf((*MockSource)(nil).Error))\n}\n\n// Ersatz mocks base method.\nfunc (m *MockSource) Ersatz() ersatz.Return {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Ersatz\")\n\tret0, _ := ret[0].(ersatz.Return)\n\treturn ret0\n}\n\n// Ersatz indicates an expected call of Ersatz.\nfunc (mr *MockSourceMockRecorder) Ersatz() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Ersatz\", reflect.TypeOf((*MockSource)(nil).Ersatz))\n}\n\n// OtherErsatz mocks base method.\nfunc (m *MockSource) OtherErsatz() ersatz0.Return {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"OtherErsatz\")\n\tret0, _ := ret[0].(ersatz0.Return)\n\treturn ret0\n}\n\n// OtherErsatz indicates an expected call of OtherErsatz.\nfunc (mr *MockSourceMockRecorder) OtherErsatz() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"OtherErsatz\", reflect.TypeOf((*MockSource)(nil).OtherErsatz))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/bugreport_test.go",
    "content": "// Copyright 2020 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\npackage bugreport\n\nimport (\n\t\"testing\"\n\n\t\"github.com/golang/mock/gomock\"\n)\n\n// TestValidInterface assesses whether or not the generated mock is valid\nfunc TestValidInterface(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\ts := NewMockSource(ctrl)\n\ts.EXPECT().Ersatz().Return(\"\")\n\ts.EXPECT().OtherErsatz().Return(\"\")\n\tCallForeignMethod(s)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/ersatz/ersatz.go",
    "content": "// Copyright 2020 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\npackage ersatz\n\ntype Embedded interface {\n\tErsatz() Return\n}\n\ntype Return interface{}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/faux/conflict.go",
    "content": "// Copyright 2020 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\npackage faux\n\nimport \"github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/log\"\n\nfunc Conflict1() {\n\tlog.Foo()\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/faux/faux.go",
    "content": "// Copyright 2020 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\npackage faux\n\nimport (\n\t\"log\"\n\n\t\"github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz\"\n)\n\ntype Foreign interface {\n\tersatz.Embedded\n}\n\nfunc Conflict0() {\n\tlog.Println()\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/foo.go",
    "content": "package bugreport\n\ntype Foo interface {\n\tBar() Baz\n}\ntype Baz interface{}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/net.go",
    "content": "//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bugreport\n\n//go:generate mockgen -destination net_mock.go -package bugreport -source=net.go\n\nimport \"net/http\"\n\ntype Net interface {\n\thttp.ResponseWriter\n}\n\nfunc CallResponseWriterMethods(n Net) {\n\tn.WriteHeader(10)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/net_mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: net.go\n\n// Package bugreport is a generated GoMock package.\npackage bugreport\n\nimport (\n\thttp \"net/http\"\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockNet is a mock of Net interface.\ntype MockNet struct {\n\tctrl     *gomock.Controller\n\trecorder *MockNetMockRecorder\n}\n\n// MockNetMockRecorder is the mock recorder for MockNet.\ntype MockNetMockRecorder struct {\n\tmock *MockNet\n}\n\n// NewMockNet creates a new mock instance.\nfunc NewMockNet(ctrl *gomock.Controller) *MockNet {\n\tmock := &MockNet{ctrl: ctrl}\n\tmock.recorder = &MockNetMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockNet) EXPECT() *MockNetMockRecorder {\n\treturn m.recorder\n}\n\n// Header mocks base method.\nfunc (m *MockNet) Header() http.Header {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Header\")\n\tret0, _ := ret[0].(http.Header)\n\treturn ret0\n}\n\n// Header indicates an expected call of Header.\nfunc (mr *MockNetMockRecorder) Header() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Header\", reflect.TypeOf((*MockNet)(nil).Header))\n}\n\n// Write mocks base method.\nfunc (m *MockNet) Write(arg0 []byte) (int, error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Write\", arg0)\n\tret0, _ := ret[0].(int)\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Write indicates an expected call of Write.\nfunc (mr *MockNetMockRecorder) Write(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Write\", reflect.TypeOf((*MockNet)(nil).Write), arg0)\n}\n\n// WriteHeader mocks base method.\nfunc (m *MockNet) WriteHeader(statusCode int) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"WriteHeader\", statusCode)\n}\n\n// WriteHeader indicates an expected call of WriteHeader.\nfunc (mr *MockNetMockRecorder) WriteHeader(statusCode interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"WriteHeader\", reflect.TypeOf((*MockNet)(nil).WriteHeader), statusCode)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/net_test.go",
    "content": "// Copyright 2020 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\npackage bugreport\n\nimport (\n\t\"testing\"\n\n\t\"github.com/golang/mock/gomock\"\n)\n\n// TestValidInterface assesses whether or not the generated mock is valid\nfunc TestValidNetInterface(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\ts := NewMockNet(ctrl)\n\ts.EXPECT().WriteHeader(10)\n\tCallResponseWriterMethods(s)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/other/ersatz/ersatz.go",
    "content": "// Copyright 2020 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\npackage ersatz\n\ntype Embedded interface {\n\tOtherErsatz() Return\n}\n\ntype Return interface{}\n"
  },
  {
    "path": "mockgen/internal/tests/import_embedded_interface/other/log/log.go",
    "content": "// Copyright 2020 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\npackage log\n\nfunc Foo() {}\n"
  },
  {
    "path": "mockgen/internal/tests/import_source/README.md",
    "content": "# Import Source\n\nTest the case where the generated code uses a type defined in the source package (in source mode). There are two test cases:\n\n- the output is in a new package\n- the output is in the same package as the input\n"
  },
  {
    "path": "mockgen/internal/tests/import_source/definition/source.go",
    "content": "package source\n\n//go:generate mockgen -destination ../source_mock.go -source=source.go\n//go:generate mockgen -package source -destination source_mock.go -source=source.go\n\ntype X struct{}\n\ntype S interface {\n\tF(X)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_source/definition/source_mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: source.go\n\n// Package source is a generated GoMock package.\npackage source\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockS is a mock of S interface.\ntype MockS struct {\n\tctrl     *gomock.Controller\n\trecorder *MockSMockRecorder\n}\n\n// MockSMockRecorder is the mock recorder for MockS.\ntype MockSMockRecorder struct {\n\tmock *MockS\n}\n\n// NewMockS creates a new mock instance.\nfunc NewMockS(ctrl *gomock.Controller) *MockS {\n\tmock := &MockS{ctrl: ctrl}\n\tmock.recorder = &MockSMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockS) EXPECT() *MockSMockRecorder {\n\treturn m.recorder\n}\n\n// F mocks base method.\nfunc (m *MockS) F(arg0 X) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"F\", arg0)\n}\n\n// F indicates an expected call of F.\nfunc (mr *MockSMockRecorder) F(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"F\", reflect.TypeOf((*MockS)(nil).F), arg0)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/import_source/source_mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: source.go\n\n// Package mock_source is a generated GoMock package.\npackage mock_source\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tsource \"github.com/golang/mock/mockgen/internal/tests/import_source/definition\"\n)\n\n// MockS is a mock of S interface.\ntype MockS struct {\n\tctrl     *gomock.Controller\n\trecorder *MockSMockRecorder\n}\n\n// MockSMockRecorder is the mock recorder for MockS.\ntype MockSMockRecorder struct {\n\tmock *MockS\n}\n\n// NewMockS creates a new mock instance.\nfunc NewMockS(ctrl *gomock.Controller) *MockS {\n\tmock := &MockS{ctrl: ctrl}\n\tmock.recorder = &MockSMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockS) EXPECT() *MockSMockRecorder {\n\treturn m.recorder\n}\n\n// F mocks base method.\nfunc (m *MockS) F(arg0 source.X) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"F\", arg0)\n}\n\n// F indicates an expected call of F.\nfunc (mr *MockSMockRecorder) F(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"F\", reflect.TypeOf((*MockS)(nil).F), arg0)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/internal_pkg/generate.go",
    "content": "package test\n\n//go:generate mockgen -destination subdir/internal/pkg/reflect_output/mock.go github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg Intf\n//go:generate mockgen -source subdir/internal/pkg/input.go -destination subdir/internal/pkg/source_output/mock.go\n"
  },
  {
    "path": "mockgen/internal/tests/internal_pkg/subdir/internal/pkg/input.go",
    "content": "package pkg\n\ntype Arg interface {\n\tFoo() int\n}\n\ntype Intf interface {\n\tF() Arg\n}\n"
  },
  {
    "path": "mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg (interfaces: Intf)\n\n// Package mock_pkg is a generated GoMock package.\npackage mock_pkg\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tpkg \"github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg\"\n)\n\n// MockIntf is a mock of Intf interface.\ntype MockIntf struct {\n\tctrl     *gomock.Controller\n\trecorder *MockIntfMockRecorder\n}\n\n// MockIntfMockRecorder is the mock recorder for MockIntf.\ntype MockIntfMockRecorder struct {\n\tmock *MockIntf\n}\n\n// NewMockIntf creates a new mock instance.\nfunc NewMockIntf(ctrl *gomock.Controller) *MockIntf {\n\tmock := &MockIntf{ctrl: ctrl}\n\tmock.recorder = &MockIntfMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockIntf) EXPECT() *MockIntfMockRecorder {\n\treturn m.recorder\n}\n\n// F mocks base method.\nfunc (m *MockIntf) F() pkg.Arg {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"F\")\n\tret0, _ := ret[0].(pkg.Arg)\n\treturn ret0\n}\n\n// F indicates an expected call of F.\nfunc (mr *MockIntfMockRecorder) F() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"F\", reflect.TypeOf((*MockIntf)(nil).F))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: subdir/internal/pkg/input.go\n\n// Package mock_pkg is a generated GoMock package.\npackage mock_pkg\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tpkg \"github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg\"\n)\n\n// MockArg is a mock of Arg interface.\ntype MockArg struct {\n\tctrl     *gomock.Controller\n\trecorder *MockArgMockRecorder\n}\n\n// MockArgMockRecorder is the mock recorder for MockArg.\ntype MockArgMockRecorder struct {\n\tmock *MockArg\n}\n\n// NewMockArg creates a new mock instance.\nfunc NewMockArg(ctrl *gomock.Controller) *MockArg {\n\tmock := &MockArg{ctrl: ctrl}\n\tmock.recorder = &MockArgMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockArg) EXPECT() *MockArgMockRecorder {\n\treturn m.recorder\n}\n\n// Foo mocks base method.\nfunc (m *MockArg) Foo() int {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Foo\")\n\tret0, _ := ret[0].(int)\n\treturn ret0\n}\n\n// Foo indicates an expected call of Foo.\nfunc (mr *MockArgMockRecorder) Foo() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Foo\", reflect.TypeOf((*MockArg)(nil).Foo))\n}\n\n// MockIntf is a mock of Intf interface.\ntype MockIntf struct {\n\tctrl     *gomock.Controller\n\trecorder *MockIntfMockRecorder\n}\n\n// MockIntfMockRecorder is the mock recorder for MockIntf.\ntype MockIntfMockRecorder struct {\n\tmock *MockIntf\n}\n\n// NewMockIntf creates a new mock instance.\nfunc NewMockIntf(ctrl *gomock.Controller) *MockIntf {\n\tmock := &MockIntf{ctrl: ctrl}\n\tmock.recorder = &MockIntfMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockIntf) EXPECT() *MockIntfMockRecorder {\n\treturn m.recorder\n}\n\n// F mocks base method.\nfunc (m *MockIntf) F() pkg.Arg {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"F\")\n\tret0, _ := ret[0].(pkg.Arg)\n\treturn ret0\n}\n\n// F indicates an expected call of F.\nfunc (mr *MockIntfMockRecorder) F() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"F\", reflect.TypeOf((*MockIntf)(nil).F))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/missing_import/output/source_mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: source.go\n\n// Package source is a generated GoMock package.\npackage source\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tsource \"github.com/golang/mock/mockgen/internal/tests/missing_import/source\"\n)\n\n// MockBar is a mock of Bar interface.\ntype MockBar struct {\n\tctrl     *gomock.Controller\n\trecorder *MockBarMockRecorder\n}\n\n// MockBarMockRecorder is the mock recorder for MockBar.\ntype MockBarMockRecorder struct {\n\tmock *MockBar\n}\n\n// NewMockBar creates a new mock instance.\nfunc NewMockBar(ctrl *gomock.Controller) *MockBar {\n\tmock := &MockBar{ctrl: ctrl}\n\tmock.recorder = &MockBarMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockBar) EXPECT() *MockBarMockRecorder {\n\treturn m.recorder\n}\n\n// Baz mocks base method.\nfunc (m *MockBar) Baz(arg0 source.Foo) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Baz\", arg0)\n}\n\n// Baz indicates an expected call of Baz.\nfunc (mr *MockBarMockRecorder) Baz(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Baz\", reflect.TypeOf((*MockBar)(nil).Baz), arg0)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/missing_import/source/source.go",
    "content": "// Package source makes sure output imports its. See #505.\npackage source\n\n//go:generate mockgen -package source -destination=../output/source_mock.go -source=source.go\n\ntype Foo struct{}\n\ntype Bar interface {\n\tBaz(Foo)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/mock_in_test_package/README.md",
    "content": "# Mock in Test Package\n\nTest the case where the package has the `_test` suffix.\n\nPrior to patch:\n\n```bash\n$ go generate\n$ go test\n# github.com/golang/mock/mockgen/internal/tests/mock_in_test_package_test [github.com/golang/mock/mockgen/internal/tests/mock_in_test_package.test]\n./mock_test.go:36:44: undefined: User\n./mock_test.go:38:21: undefined: User\nFAIL    github.com/golang/mock/mockgen/internal/tests/mock_in_test_package [build failed]\n```\n\nWith this patch applied:\n\n```bash\n$ go generate\n$ go test\nok      github.com/golang/mock/mockgen/internal/tests/mock_in_test_package  0.031s\n```\n"
  },
  {
    "path": "mockgen/internal/tests/mock_in_test_package/mock_test.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: user.go\n\n// Package users_test is a generated GoMock package.\npackage users_test\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tusers \"github.com/golang/mock/mockgen/internal/tests/mock_in_test_package\"\n)\n\n// MockFinder is a mock of Finder interface.\ntype MockFinder struct {\n\tctrl     *gomock.Controller\n\trecorder *MockFinderMockRecorder\n}\n\n// MockFinderMockRecorder is the mock recorder for MockFinder.\ntype MockFinderMockRecorder struct {\n\tmock *MockFinder\n}\n\n// NewMockFinder creates a new mock instance.\nfunc NewMockFinder(ctrl *gomock.Controller) *MockFinder {\n\tmock := &MockFinder{ctrl: ctrl}\n\tmock.recorder = &MockFinderMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockFinder) EXPECT() *MockFinderMockRecorder {\n\treturn m.recorder\n}\n\n// Add mocks base method.\nfunc (m *MockFinder) Add(u users.User) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Add\", u)\n}\n\n// Add indicates an expected call of Add.\nfunc (mr *MockFinderMockRecorder) Add(u interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Add\", reflect.TypeOf((*MockFinder)(nil).Add), u)\n}\n\n// FindUser mocks base method.\nfunc (m *MockFinder) FindUser(name string) users.User {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"FindUser\", name)\n\tret0, _ := ret[0].(users.User)\n\treturn ret0\n}\n\n// FindUser indicates an expected call of FindUser.\nfunc (mr *MockFinderMockRecorder) FindUser(name interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"FindUser\", reflect.TypeOf((*MockFinder)(nil).FindUser), name)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/mock_in_test_package/user.go",
    "content": "package users\n\n//go:generate mockgen --source=user.go --destination=mock_test.go --package=users_test\n\ntype User struct {\n\tName string\n}\n\ntype Finder interface {\n\tFindUser(name string) User\n\tAdd(u User)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/overlapping_methods/interfaces.go",
    "content": "package overlap\n\ntype ReadCloser interface {\n\tRead([]byte) (int, error)\n\tClose() error\n}\n\ntype WriteCloser interface {\n\tWrite([]byte) (int, error)\n\tClose() error\n}\n"
  },
  {
    "path": "mockgen/internal/tests/overlapping_methods/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: overlap.go\n\n// Package overlap is a generated GoMock package.\npackage overlap\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockReadWriteCloser is a mock of ReadWriteCloser interface.\ntype MockReadWriteCloser struct {\n\tctrl     *gomock.Controller\n\trecorder *MockReadWriteCloserMockRecorder\n}\n\n// MockReadWriteCloserMockRecorder is the mock recorder for MockReadWriteCloser.\ntype MockReadWriteCloserMockRecorder struct {\n\tmock *MockReadWriteCloser\n}\n\n// NewMockReadWriteCloser creates a new mock instance.\nfunc NewMockReadWriteCloser(ctrl *gomock.Controller) *MockReadWriteCloser {\n\tmock := &MockReadWriteCloser{ctrl: ctrl}\n\tmock.recorder = &MockReadWriteCloserMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockReadWriteCloser) EXPECT() *MockReadWriteCloserMockRecorder {\n\treturn m.recorder\n}\n\n// Close mocks base method.\nfunc (m *MockReadWriteCloser) Close() error {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Close\")\n\tret0, _ := ret[0].(error)\n\treturn ret0\n}\n\n// Close indicates an expected call of Close.\nfunc (mr *MockReadWriteCloserMockRecorder) Close() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Close\", reflect.TypeOf((*MockReadWriteCloser)(nil).Close))\n}\n\n// Read mocks base method.\nfunc (m *MockReadWriteCloser) Read(arg0 []byte) (int, error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Read\", arg0)\n\tret0, _ := ret[0].(int)\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Read indicates an expected call of Read.\nfunc (mr *MockReadWriteCloserMockRecorder) Read(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Read\", reflect.TypeOf((*MockReadWriteCloser)(nil).Read), arg0)\n}\n\n// Write mocks base method.\nfunc (m *MockReadWriteCloser) Write(arg0 []byte) (int, error) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Write\", arg0)\n\tret0, _ := ret[0].(int)\n\tret1, _ := ret[1].(error)\n\treturn ret0, ret1\n}\n\n// Write indicates an expected call of Write.\nfunc (mr *MockReadWriteCloserMockRecorder) Write(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Write\", reflect.TypeOf((*MockReadWriteCloser)(nil).Write), arg0)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/overlapping_methods/overlap.go",
    "content": "package overlap\n\n//go:generate mockgen -package overlap -destination mock.go -source overlap.go -aux_files github.com/golang/mock/mockgen/internal/tests/overlapping_methods=interfaces.go\n\ntype ReadWriteCloser interface {\n\tReadCloser\n\tWriteCloser\n}\n"
  },
  {
    "path": "mockgen/internal/tests/overlapping_methods/overlap_test.go",
    "content": "package overlap\n\nimport (\n\t\"errors\"\n\t\"testing\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// TestValidInterface assesses whether or not the generated mock is valid\nfunc TestValidInterface(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\ts := NewMockReadWriteCloser(ctrl)\n\ts.EXPECT().Close().Return(errors.New(\"test\"))\n\n\ts.Close()\n}\n"
  },
  {
    "path": "mockgen/internal/tests/panicing_test/mock_test.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: panic.go\n\n// Package paniccode is a generated GoMock package.\npackage paniccode\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockFoo is a mock of Foo interface.\ntype MockFoo struct {\n\tctrl     *gomock.Controller\n\trecorder *MockFooMockRecorder\n}\n\n// MockFooMockRecorder is the mock recorder for MockFoo.\ntype MockFooMockRecorder struct {\n\tmock *MockFoo\n}\n\n// NewMockFoo creates a new mock instance.\nfunc NewMockFoo(ctrl *gomock.Controller) *MockFoo {\n\tmock := &MockFoo{ctrl: ctrl}\n\tmock.recorder = &MockFooMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockFoo) EXPECT() *MockFooMockRecorder {\n\treturn m.recorder\n}\n\n// Bar mocks base method.\nfunc (m *MockFoo) Bar() string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Bar\")\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// Bar indicates an expected call of Bar.\nfunc (mr *MockFooMockRecorder) Bar() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Bar\", reflect.TypeOf((*MockFoo)(nil).Bar))\n}\n\n// Baz mocks base method.\nfunc (m *MockFoo) Baz() string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Baz\")\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// Baz indicates an expected call of Baz.\nfunc (mr *MockFooMockRecorder) Baz() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Baz\", reflect.TypeOf((*MockFoo)(nil).Baz))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/panicing_test/panic.go",
    "content": "// Copyright 2020 Google LLC\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage paniccode\n\n//go:generate mockgen --source=panic.go --destination=mock_test.go --package=paniccode\n\ntype Foo interface {\n\tBar() string\n\tBaz() string\n}\n\nfunc Danger(f Foo) {\n\tif f.Bar() == \"Bar\" {\n\t\tpanic(\"Danger, Will Robinson!\")\n\t}\n}\n"
  },
  {
    "path": "mockgen/internal/tests/panicing_test/panic_test.go",
    "content": "//go:build panictest\n// +build panictest\n\n// Copyright 2020 Google LLC\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage paniccode\n\nimport (\n\t\"testing\"\n\n\t\"github.com/golang/mock/gomock\"\n)\n\nfunc TestDanger_Panics_Explicit(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\tmock := NewMockFoo(ctrl)\n\tmock.EXPECT().Bar().Return(\"Bar\")\n\tmock.EXPECT().Bar().Return(\"Baz\")\n\tDanger(mock)\n}\n\nfunc TestDanger_Panics_Implicit(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tmock := NewMockFoo(ctrl)\n\tmock.EXPECT().Bar().Return(\"Bar\")\n\tmock.EXPECT().Bar().Return(\"Baz\")\n\tDanger(mock)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/parenthesized_parameter_type/README.md",
    "content": "# Parenthesized Parameter Type\n\nTest for [Issue#416](https://github.com/golang/mock/issues/416).\n"
  },
  {
    "path": "mockgen/internal/tests/parenthesized_parameter_type/input.go",
    "content": "package parenthesized_parameter_type\n\ntype Example interface {\n\tParenthesizedParameterType(param *(int))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/parenthesized_parameter_type/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: ./mockgen/internal/tests/parenthesized_parameter_type/input.go\n\n// Package parenthesized_parameter_type is a generated GoMock package.\npackage parenthesized_parameter_type\n\nimport (\n\tgomock \"github.com/golang/mock/gomock\"\n\treflect \"reflect\"\n)\n\n// MockExample is a mock of Example interface.\ntype MockExample struct {\n\tctrl     *gomock.Controller\n\trecorder *MockExampleMockRecorder\n}\n\n// MockExampleMockRecorder is the mock recorder for MockExample.\ntype MockExampleMockRecorder struct {\n\tmock *MockExample\n}\n\n// NewMockExample creates a new mock instance.\nfunc NewMockExample(ctrl *gomock.Controller) *MockExample {\n\tmock := &MockExample{ctrl: ctrl}\n\tmock.recorder = &MockExampleMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockExample) EXPECT() *MockExampleMockRecorder {\n\treturn m.recorder\n}\n\n// ParenthesizedParameterType mocks base method.\nfunc (m *MockExample) ParenthesizedParameterType(param *int) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"ParenthesizedParameterType\", param)\n}\n\n// ParenthesizedParameterType indicates an expected call of ParenthesizedParameterType.\nfunc (mr *MockExampleMockRecorder) ParenthesizedParameterType(param interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"ParenthesizedParameterType\", reflect.TypeOf((*MockExample)(nil).ParenthesizedParameterType), param)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/performance/big_interface/big_interface.go",
    "content": "package big_interface\n\ntype Bar struct{}\n\ntype BigInterface interface {\n\tFoo1(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo2(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo3(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo4(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo5(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo6(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo7(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo8(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo9(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo10(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo11(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo12(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo13(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo14(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo15(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo16(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo17(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo18(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo19(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo20(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo21(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo22(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo23(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo24(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo25(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo26(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo27(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo28(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo29(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo30(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo31(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo32(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo33(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo34(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo35(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo36(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo37(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo38(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo39(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo40(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo41(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo42(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo43(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo44(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo45(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo46(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo47(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo48(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo49(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo50(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo51(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo52(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo53(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo54(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo55(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo56(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo57(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo58(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo59(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n\tFoo60(bool, bool, bool, bool, bool, bool, bool, bool) Bar\n}\n"
  },
  {
    "path": "mockgen/internal/tests/self_package/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: github.com/golang/mock/mockgen/internal/tests/self_package (interfaces: Methods)\n\n// Package core is a generated GoMock package.\npackage core\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockMethods is a mock of Methods interface.\ntype MockMethods struct {\n\tctrl     *gomock.Controller\n\trecorder *MockMethodsMockRecorder\n}\n\n// MockMethodsMockRecorder is the mock recorder for MockMethods.\ntype MockMethodsMockRecorder struct {\n\tmock *MockMethods\n}\n\n// NewMockMethods creates a new mock instance.\nfunc NewMockMethods(ctrl *gomock.Controller) *MockMethods {\n\tmock := &MockMethods{ctrl: ctrl}\n\tmock.recorder = &MockMethodsMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockMethods) EXPECT() *MockMethodsMockRecorder {\n\treturn m.recorder\n}\n\n// getInfo mocks base method.\nfunc (m *MockMethods) getInfo() Info {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"getInfo\")\n\tret0, _ := ret[0].(Info)\n\treturn ret0\n}\n\n// getInfo indicates an expected call of getInfo.\nfunc (mr *MockMethodsMockRecorder) getInfo() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"getInfo\", reflect.TypeOf((*MockMethods)(nil).getInfo))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/self_package/types.go",
    "content": "package core\n\n//go:generate mockgen -package core -self_package github.com/golang/mock/mockgen/internal/tests/self_package -destination mock.go github.com/golang/mock/mockgen/internal/tests/self_package Methods\n\ntype Info struct{}\n\ntype Methods interface {\n\tgetInfo() Info\n}\n"
  },
  {
    "path": "mockgen/internal/tests/test_package/foo.go",
    "content": "package users\n"
  },
  {
    "path": "mockgen/internal/tests/test_package/mock_test.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: user_test.go\n\n// Package users_test is a generated GoMock package.\npackage users_test\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockFinder is a mock of Finder interface.\ntype MockFinder struct {\n\tctrl     *gomock.Controller\n\trecorder *MockFinderMockRecorder\n}\n\n// MockFinderMockRecorder is the mock recorder for MockFinder.\ntype MockFinderMockRecorder struct {\n\tmock *MockFinder\n}\n\n// NewMockFinder creates a new mock instance.\nfunc NewMockFinder(ctrl *gomock.Controller) *MockFinder {\n\tmock := &MockFinder{ctrl: ctrl}\n\tmock.recorder = &MockFinderMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockFinder) EXPECT() *MockFinderMockRecorder {\n\treturn m.recorder\n}\n\n// Add mocks base method.\nfunc (m *MockFinder) Add(u User) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Add\", u)\n}\n\n// Add indicates an expected call of Add.\nfunc (mr *MockFinderMockRecorder) Add(u interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Add\", reflect.TypeOf((*MockFinder)(nil).Add), u)\n}\n\n// FindUser mocks base method.\nfunc (m *MockFinder) FindUser(name string) User {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"FindUser\", name)\n\tret0, _ := ret[0].(User)\n\treturn ret0\n}\n\n// FindUser indicates an expected call of FindUser.\nfunc (mr *MockFinderMockRecorder) FindUser(name interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"FindUser\", reflect.TypeOf((*MockFinder)(nil).FindUser), name)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/test_package/user_test.go",
    "content": "package users_test\n\n//go:generate mockgen --source=user_test.go --destination=mock_test.go --package=users_test\n\ntype User struct {\n\tName string\n}\n\ntype Finder interface {\n\tFindUser(name string) User\n\tAdd(u User)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/unexported_method/README.md",
    "content": "# Unexported Method\n\nFrom #52, this tests an unexported method in the mocked interface.\n"
  },
  {
    "path": "mockgen/internal/tests/unexported_method/bugreport.go",
    "content": "package bugreport\n\n//go:generate mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go Example\n\nimport \"fmt\"\n\n// Example is an interface with a non exported method\ntype Example interface {\n\tsomeMethod(string) string\n}\n\n// CallExample is a simple function that uses the interface\nfunc CallExample(e Example) {\n\tfmt.Println(e.someMethod(\"test\"))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/unexported_method/bugreport_mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: bugreport.go\n\n// Package bugreport is a generated GoMock package.\npackage bugreport\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockExample is a mock of Example interface.\ntype MockExample struct {\n\tctrl     *gomock.Controller\n\trecorder *MockExampleMockRecorder\n}\n\n// MockExampleMockRecorder is the mock recorder for MockExample.\ntype MockExampleMockRecorder struct {\n\tmock *MockExample\n}\n\n// NewMockExample creates a new mock instance.\nfunc NewMockExample(ctrl *gomock.Controller) *MockExample {\n\tmock := &MockExample{ctrl: ctrl}\n\tmock.recorder = &MockExampleMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockExample) EXPECT() *MockExampleMockRecorder {\n\treturn m.recorder\n}\n\n// someMethod mocks base method.\nfunc (m *MockExample) someMethod(arg0 string) string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"someMethod\", arg0)\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// someMethod indicates an expected call of someMethod.\nfunc (mr *MockExampleMockRecorder) someMethod(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"someMethod\", reflect.TypeOf((*MockExample)(nil).someMethod), arg0)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/unexported_method/bugreport_test.go",
    "content": "package bugreport\n\nimport (\n\t\"testing\"\n\n\t\"github.com/golang/mock/gomock\"\n)\n\nfunc TestCallExample(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\te := NewMockExample(ctrl)\n\te.EXPECT().someMethod(gomock.Any()).Return(\"it works!\")\n\n\tCallExample(e)\n}\n"
  },
  {
    "path": "mockgen/internal/tests/vendor_dep/README.md",
    "content": "# Vendor Dep\n\nTest for [Issue#4](https://github.com/golang/mock/issues/4).\nAlso see discussion on [#28](https://github.com/golang/mock/pull/28).\n"
  },
  {
    "path": "mockgen/internal/tests/vendor_dep/doc.go",
    "content": "package vendor_dep\n\n//go:generate mockgen -package vendor_dep -destination mock.go github.com/golang/mock/mockgen/internal/tests/vendor_dep VendorsDep\n//go:generate mockgen -destination source_mock_package/mock.go -source=vendor_dep.go\n"
  },
  {
    "path": "mockgen/internal/tests/vendor_dep/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: github.com/golang/mock/mockgen/internal/tests/vendor_dep (interfaces: VendorsDep)\n\n// Package vendor_dep is a generated GoMock package.\npackage vendor_dep\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tpresent \"golang.org/x/tools/present\"\n)\n\n// MockVendorsDep is a mock of VendorsDep interface.\ntype MockVendorsDep struct {\n\tctrl     *gomock.Controller\n\trecorder *MockVendorsDepMockRecorder\n}\n\n// MockVendorsDepMockRecorder is the mock recorder for MockVendorsDep.\ntype MockVendorsDepMockRecorder struct {\n\tmock *MockVendorsDep\n}\n\n// NewMockVendorsDep creates a new mock instance.\nfunc NewMockVendorsDep(ctrl *gomock.Controller) *MockVendorsDep {\n\tmock := &MockVendorsDep{ctrl: ctrl}\n\tmock.recorder = &MockVendorsDepMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockVendorsDep) EXPECT() *MockVendorsDepMockRecorder {\n\treturn m.recorder\n}\n\n// Foo mocks base method.\nfunc (m *MockVendorsDep) Foo() present.Elem {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Foo\")\n\tret0, _ := ret[0].(present.Elem)\n\treturn ret0\n}\n\n// Foo indicates an expected call of Foo.\nfunc (mr *MockVendorsDepMockRecorder) Foo() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Foo\", reflect.TypeOf((*MockVendorsDep)(nil).Foo))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/vendor_dep/source_mock_package/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: vendor_dep.go\n\n// Package mock_vendor_dep is a generated GoMock package.\npackage mock_vendor_dep\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\tpresent \"golang.org/x/tools/present\"\n)\n\n// MockVendorsDep is a mock of VendorsDep interface.\ntype MockVendorsDep struct {\n\tctrl     *gomock.Controller\n\trecorder *MockVendorsDepMockRecorder\n}\n\n// MockVendorsDepMockRecorder is the mock recorder for MockVendorsDep.\ntype MockVendorsDepMockRecorder struct {\n\tmock *MockVendorsDep\n}\n\n// NewMockVendorsDep creates a new mock instance.\nfunc NewMockVendorsDep(ctrl *gomock.Controller) *MockVendorsDep {\n\tmock := &MockVendorsDep{ctrl: ctrl}\n\tmock.recorder = &MockVendorsDepMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockVendorsDep) EXPECT() *MockVendorsDepMockRecorder {\n\treturn m.recorder\n}\n\n// Foo mocks base method.\nfunc (m *MockVendorsDep) Foo() present.Elem {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Foo\")\n\tret0, _ := ret[0].(present.Elem)\n\treturn ret0\n}\n\n// Foo indicates an expected call of Foo.\nfunc (mr *MockVendorsDepMockRecorder) Foo() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Foo\", reflect.TypeOf((*MockVendorsDep)(nil).Foo))\n}\n"
  },
  {
    "path": "mockgen/internal/tests/vendor_dep/vendor_dep.go",
    "content": "package vendor_dep\n\nimport \"golang.org/x/tools/present\"\n\ntype VendorsDep interface {\n\tFoo() present.Elem\n}\n"
  },
  {
    "path": "mockgen/internal/tests/vendor_pkg/README.md",
    "content": "# Vendor Pkg\n\nTest for [Issue#4](https://github.com/golang/mock/issues/4).\n"
  },
  {
    "path": "mockgen/internal/tests/vendor_pkg/doc.go",
    "content": "package vendor_pkg\n\n//go:generate mockgen -destination mock.go -package vendor_pkg golang.org/x/tools/present Elem\n"
  },
  {
    "path": "mockgen/internal/tests/vendor_pkg/mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: golang.org/x/tools/present (interfaces: Elem)\n\n// Package vendor_pkg is a generated GoMock package.\npackage vendor_pkg\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockElem is a mock of Elem interface.\ntype MockElem struct {\n\tctrl     *gomock.Controller\n\trecorder *MockElemMockRecorder\n}\n\n// MockElemMockRecorder is the mock recorder for MockElem.\ntype MockElemMockRecorder struct {\n\tmock *MockElem\n}\n\n// NewMockElem creates a new mock instance.\nfunc NewMockElem(ctrl *gomock.Controller) *MockElem {\n\tmock := &MockElem{ctrl: ctrl}\n\tmock.recorder = &MockElemMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockElem) EXPECT() *MockElemMockRecorder {\n\treturn m.recorder\n}\n\n// TemplateName mocks base method.\nfunc (m *MockElem) TemplateName() string {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"TemplateName\")\n\tret0, _ := ret[0].(string)\n\treturn ret0\n}\n\n// TemplateName indicates an expected call of TemplateName.\nfunc (mr *MockElemMockRecorder) TemplateName() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"TemplateName\", reflect.TypeOf((*MockElem)(nil).TemplateName))\n}\n"
  },
  {
    "path": "mockgen/mockgen.go",
    "content": "// Copyright 2010 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// MockGen generates mock implementations of Go interfaces.\npackage main\n\n// TODO: This does not support recursive embedded interfaces.\n// TODO: This does not support embedding package-local interfaces in a separate file.\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"flag\"\n\t\"fmt\"\n\t\"go/token\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"os\"\n\t\"os/exec\"\n\t\"path\"\n\t\"path/filepath\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n\t\"unicode\"\n\n\t\"github.com/golang/mock/mockgen/model\"\n\n\t\"golang.org/x/mod/modfile\"\n\ttoolsimports \"golang.org/x/tools/imports\"\n)\n\nconst (\n\tgomockImportPath = \"github.com/golang/mock/gomock\"\n)\n\nvar (\n\tversion = \"\"\n\tcommit  = \"none\"\n\tdate    = \"unknown\"\n)\n\nvar (\n\tsource          = flag.String(\"source\", \"\", \"(source mode) Input Go source file; enables source mode.\")\n\tdestination     = flag.String(\"destination\", \"\", \"Output file; defaults to stdout.\")\n\tmockNames       = flag.String(\"mock_names\", \"\", \"Comma-separated interfaceName=mockName pairs of explicit mock names to use. Mock names default to 'Mock'+ interfaceName suffix.\")\n\tpackageOut      = flag.String(\"package\", \"\", \"Package of the generated code; defaults to the package of the input with a 'mock_' prefix.\")\n\tselfPackage     = flag.String(\"self_package\", \"\", \"The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.\")\n\twritePkgComment = flag.Bool(\"write_package_comment\", true, \"Writes package documentation comment (godoc) if true.\")\n\tcopyrightFile   = flag.String(\"copyright_file\", \"\", \"Copyright file used to add copyright header\")\n\n\tdebugParser = flag.Bool(\"debug_parser\", false, \"Print out parser results only.\")\n\tshowVersion = flag.Bool(\"version\", false, \"Print version.\")\n)\n\nfunc main() {\n\tflag.Usage = usage\n\tflag.Parse()\n\n\tif *showVersion {\n\t\tprintVersion()\n\t\treturn\n\t}\n\n\tvar pkg *model.Package\n\tvar err error\n\tvar packageName string\n\tif *source != \"\" {\n\t\tpkg, err = sourceMode(*source)\n\t} else {\n\t\tif flag.NArg() != 2 {\n\t\t\tusage()\n\t\t\tlog.Fatal(\"Expected exactly two arguments\")\n\t\t}\n\t\tpackageName = flag.Arg(0)\n\t\tinterfaces := strings.Split(flag.Arg(1), \",\")\n\t\tif packageName == \".\" {\n\t\t\tdir, err := os.Getwd()\n\t\t\tif err != nil {\n\t\t\t\tlog.Fatalf(\"Get current directory failed: %v\", err)\n\t\t\t}\n\t\t\tpackageName, err = packageNameOfDir(dir)\n\t\t\tif err != nil {\n\t\t\t\tlog.Fatalf(\"Parse package name failed: %v\", err)\n\t\t\t}\n\t\t}\n\t\tpkg, err = reflectMode(packageName, interfaces)\n\t}\n\tif err != nil {\n\t\tlog.Fatalf(\"Loading input failed: %v\", err)\n\t}\n\n\tif *debugParser {\n\t\tpkg.Print(os.Stdout)\n\t\treturn\n\t}\n\n\toutputPackageName := *packageOut\n\tif outputPackageName == \"\" {\n\t\t// pkg.Name in reflect mode is the base name of the import path,\n\t\t// which might have characters that are illegal to have in package names.\n\t\toutputPackageName = \"mock_\" + sanitize(pkg.Name)\n\t}\n\n\t// outputPackagePath represents the fully qualified name of the package of\n\t// the generated code. Its purposes are to prevent the module from importing\n\t// itself and to prevent qualifying type names that come from its own\n\t// package (i.e. if there is a type called X then we want to print \"X\" not\n\t// \"package.X\" since \"package\" is this package). This can happen if the mock\n\t// is output into an already existing package.\n\toutputPackagePath := *selfPackage\n\tif outputPackagePath == \"\" && *destination != \"\" {\n\t\tdstPath, err := filepath.Abs(filepath.Dir(*destination))\n\t\tif err == nil {\n\t\t\tpkgPath, err := parsePackageImport(dstPath)\n\t\t\tif err == nil {\n\t\t\t\toutputPackagePath = pkgPath\n\t\t\t} else {\n\t\t\t\tlog.Println(\"Unable to infer -self_package from destination file path:\", err)\n\t\t\t}\n\t\t} else {\n\t\t\tlog.Println(\"Unable to determine destination file path:\", err)\n\t\t}\n\t}\n\n\tg := new(generator)\n\tif *source != \"\" {\n\t\tg.filename = *source\n\t} else {\n\t\tg.srcPackage = packageName\n\t\tg.srcInterfaces = flag.Arg(1)\n\t}\n\tg.destination = *destination\n\n\tif *mockNames != \"\" {\n\t\tg.mockNames = parseMockNames(*mockNames)\n\t}\n\tif *copyrightFile != \"\" {\n\t\theader, err := ioutil.ReadFile(*copyrightFile)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"Failed reading copyright file: %v\", err)\n\t\t}\n\n\t\tg.copyrightHeader = string(header)\n\t}\n\tif err := g.Generate(pkg, outputPackageName, outputPackagePath); err != nil {\n\t\tlog.Fatalf(\"Failed generating mock: %v\", err)\n\t}\n\toutput := g.Output()\n\tdst := os.Stdout\n\tif len(*destination) > 0 {\n\t\tif err := os.MkdirAll(filepath.Dir(*destination), os.ModePerm); err != nil {\n\t\t\tlog.Fatalf(\"Unable to create directory: %v\", err)\n\t\t}\n\t\texisting, err := ioutil.ReadFile(*destination)\n\t\tif err != nil && !errors.Is(err, os.ErrNotExist) {\n\t\t\tlog.Fatalf(\"Failed reading pre-exiting destination file: %v\", err)\n\t\t}\n\t\tif len(existing) == len(output) && bytes.Compare(existing, output) == 0 {\n\t\t\treturn\n\t\t}\n\t\tf, err := os.Create(*destination)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"Failed opening destination file: %v\", err)\n\t\t}\n\t\tdefer f.Close()\n\t\tdst = f\n\t}\n\tif _, err := dst.Write(output); err != nil {\n\t\tlog.Fatalf(\"Failed writing to destination: %v\", err)\n\t}\n}\n\nfunc parseMockNames(names string) map[string]string {\n\tmocksMap := make(map[string]string)\n\tfor _, kv := range strings.Split(names, \",\") {\n\t\tparts := strings.SplitN(kv, \"=\", 2)\n\t\tif len(parts) != 2 || parts[1] == \"\" {\n\t\t\tlog.Fatalf(\"bad mock names spec: %v\", kv)\n\t\t}\n\t\tmocksMap[parts[0]] = parts[1]\n\t}\n\treturn mocksMap\n}\n\nfunc usage() {\n\t_, _ = io.WriteString(os.Stderr, usageText)\n\tflag.PrintDefaults()\n}\n\nconst usageText = `mockgen has two modes of operation: source and reflect.\n\nSource mode generates mock interfaces from a source file.\nIt is enabled by using the -source flag. Other flags that\nmay be useful in this mode are -imports and -aux_files.\nExample:\n\tmockgen -source=foo.go [other options]\n\nReflect mode generates mock interfaces by building a program\nthat uses reflection to understand interfaces. It is enabled\nby passing two non-flag arguments: an import path, and a\ncomma-separated list of symbols.\nExample:\n\tmockgen database/sql/driver Conn,Driver\n\n`\n\ntype generator struct {\n\tbuf                       bytes.Buffer\n\tindent                    string\n\tmockNames                 map[string]string // may be empty\n\tfilename                  string            // may be empty\n\tdestination               string            // may be empty\n\tsrcPackage, srcInterfaces string            // may be empty\n\tcopyrightHeader           string\n\n\tpackageMap map[string]string // map from import path to package name\n}\n\nfunc (g *generator) p(format string, args ...interface{}) {\n\tfmt.Fprintf(&g.buf, g.indent+format+\"\\n\", args...)\n}\n\nfunc (g *generator) in() {\n\tg.indent += \"\\t\"\n}\n\nfunc (g *generator) out() {\n\tif len(g.indent) > 0 {\n\t\tg.indent = g.indent[0 : len(g.indent)-1]\n\t}\n}\n\n// sanitize cleans up a string to make a suitable package name.\nfunc sanitize(s string) string {\n\tt := \"\"\n\tfor _, r := range s {\n\t\tif t == \"\" {\n\t\t\tif unicode.IsLetter(r) || r == '_' {\n\t\t\t\tt += string(r)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t} else {\n\t\t\tif unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' {\n\t\t\t\tt += string(r)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t\tt += \"_\"\n\t}\n\tif t == \"_\" {\n\t\tt = \"x\"\n\t}\n\treturn t\n}\n\nfunc (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPackagePath string) error {\n\tif outputPkgName != pkg.Name && *selfPackage == \"\" {\n\t\t// reset outputPackagePath if it's not passed in through -self_package\n\t\toutputPackagePath = \"\"\n\t}\n\n\tif g.copyrightHeader != \"\" {\n\t\tlines := strings.Split(g.copyrightHeader, \"\\n\")\n\t\tfor _, line := range lines {\n\t\t\tg.p(\"// %s\", line)\n\t\t}\n\t\tg.p(\"\")\n\t}\n\n\tg.p(\"// Code generated by MockGen. DO NOT EDIT.\")\n\tif g.filename != \"\" {\n\t\tg.p(\"// Source: %v\", g.filename)\n\t} else {\n\t\tg.p(\"// Source: %v (interfaces: %v)\", g.srcPackage, g.srcInterfaces)\n\t}\n\tg.p(\"\")\n\n\t// Get all required imports, and generate unique names for them all.\n\tim := pkg.Imports()\n\tim[gomockImportPath] = true\n\n\t// Only import reflect if it's used. We only use reflect in mocked methods\n\t// so only import if any of the mocked interfaces have methods.\n\tfor _, intf := range pkg.Interfaces {\n\t\tif len(intf.Methods) > 0 {\n\t\t\tim[\"reflect\"] = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\t// Sort keys to make import alias generation predictable\n\tsortedPaths := make([]string, len(im))\n\tx := 0\n\tfor pth := range im {\n\t\tsortedPaths[x] = pth\n\t\tx++\n\t}\n\tsort.Strings(sortedPaths)\n\n\tpackagesName := createPackageMap(sortedPaths)\n\n\tg.packageMap = make(map[string]string, len(im))\n\tlocalNames := make(map[string]bool, len(im))\n\tfor _, pth := range sortedPaths {\n\t\tbase, ok := packagesName[pth]\n\t\tif !ok {\n\t\t\tbase = sanitize(path.Base(pth))\n\t\t}\n\n\t\t// Local names for an imported package can usually be the basename of the import path.\n\t\t// A couple of situations don't permit that, such as duplicate local names\n\t\t// (e.g. importing \"html/template\" and \"text/template\"), or where the basename is\n\t\t// a keyword (e.g. \"foo/case\").\n\t\t// try base0, base1, ...\n\t\tpkgName := base\n\t\ti := 0\n\t\tfor localNames[pkgName] || token.Lookup(pkgName).IsKeyword() {\n\t\t\tpkgName = base + strconv.Itoa(i)\n\t\t\ti++\n\t\t}\n\n\t\t// Avoid importing package if source pkg == output pkg\n\t\tif pth == pkg.PkgPath && outputPackagePath == pkg.PkgPath {\n\t\t\tcontinue\n\t\t}\n\n\t\tg.packageMap[pth] = pkgName\n\t\tlocalNames[pkgName] = true\n\t}\n\n\tif *writePkgComment {\n\t\tg.p(\"// Package %v is a generated GoMock package.\", outputPkgName)\n\t}\n\tg.p(\"package %v\", outputPkgName)\n\tg.p(\"\")\n\tg.p(\"import (\")\n\tg.in()\n\tfor pkgPath, pkgName := range g.packageMap {\n\t\tif pkgPath == outputPackagePath {\n\t\t\tcontinue\n\t\t}\n\t\tg.p(\"%v %q\", pkgName, pkgPath)\n\t}\n\tfor _, pkgPath := range pkg.DotImports {\n\t\tg.p(\". %q\", pkgPath)\n\t}\n\tg.out()\n\tg.p(\")\")\n\n\tfor _, intf := range pkg.Interfaces {\n\t\tif err := g.GenerateMockInterface(intf, outputPackagePath); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// The name of the mock type to use for the given interface identifier.\nfunc (g *generator) mockName(typeName string) string {\n\tif mockName, ok := g.mockNames[typeName]; ok {\n\t\treturn mockName\n\t}\n\n\treturn \"Mock\" + typeName\n}\n\n// formattedTypeParams returns a long and short form of type param info used for\n// printing. If analyzing a interface with type param [I any, O any] the result\n// will be:\n// \"[I any, O any]\", \"[I, O]\"\nfunc (g *generator) formattedTypeParams(it *model.Interface, pkgOverride string) (string, string) {\n\tif len(it.TypeParams) == 0 {\n\t\treturn \"\", \"\"\n\t}\n\tvar long, short strings.Builder\n\tlong.WriteString(\"[\")\n\tshort.WriteString(\"[\")\n\tfor i, v := range it.TypeParams {\n\t\tif i != 0 {\n\t\t\tlong.WriteString(\", \")\n\t\t\tshort.WriteString(\", \")\n\t\t}\n\t\tlong.WriteString(v.Name)\n\t\tshort.WriteString(v.Name)\n\t\tlong.WriteString(fmt.Sprintf(\" %s\", v.Type.String(g.packageMap, pkgOverride)))\n\t}\n\tlong.WriteString(\"]\")\n\tshort.WriteString(\"]\")\n\treturn long.String(), short.String()\n}\n\nfunc (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePath string) error {\n\tmockType := g.mockName(intf.Name)\n\tlongTp, shortTp := g.formattedTypeParams(intf, outputPackagePath)\n\n\tg.p(\"\")\n\tg.p(\"// %v is a mock of %v interface.\", mockType, intf.Name)\n\tg.p(\"type %v%v struct {\", mockType, longTp)\n\tg.in()\n\tg.p(\"ctrl     *gomock.Controller\")\n\tg.p(\"recorder *%vMockRecorder%v\", mockType, shortTp)\n\tg.out()\n\tg.p(\"}\")\n\tg.p(\"\")\n\n\tg.p(\"// %vMockRecorder is the mock recorder for %v.\", mockType, mockType)\n\tg.p(\"type %vMockRecorder%v struct {\", mockType, longTp)\n\tg.in()\n\tg.p(\"mock *%v%v\", mockType, shortTp)\n\tg.out()\n\tg.p(\"}\")\n\tg.p(\"\")\n\n\tg.p(\"// New%v creates a new mock instance.\", mockType)\n\tg.p(\"func New%v%v(ctrl *gomock.Controller) *%v%v {\", mockType, longTp, mockType, shortTp)\n\tg.in()\n\tg.p(\"mock := &%v%v{ctrl: ctrl}\", mockType, shortTp)\n\tg.p(\"mock.recorder = &%vMockRecorder%v{mock}\", mockType, shortTp)\n\tg.p(\"return mock\")\n\tg.out()\n\tg.p(\"}\")\n\tg.p(\"\")\n\n\t// XXX: possible name collision here if someone has EXPECT in their interface.\n\tg.p(\"// EXPECT returns an object that allows the caller to indicate expected use.\")\n\tg.p(\"func (m *%v%v) EXPECT() *%vMockRecorder%v {\", mockType, shortTp, mockType, shortTp)\n\tg.in()\n\tg.p(\"return m.recorder\")\n\tg.out()\n\tg.p(\"}\")\n\n\tg.GenerateMockMethods(mockType, intf, outputPackagePath, shortTp)\n\n\treturn nil\n}\n\ntype byMethodName []*model.Method\n\nfunc (b byMethodName) Len() int           { return len(b) }\nfunc (b byMethodName) Swap(i, j int)      { b[i], b[j] = b[j], b[i] }\nfunc (b byMethodName) Less(i, j int) bool { return b[i].Name < b[j].Name }\n\nfunc (g *generator) GenerateMockMethods(mockType string, intf *model.Interface, pkgOverride, shortTp string) {\n\tsort.Sort(byMethodName(intf.Methods))\n\tfor _, m := range intf.Methods {\n\t\tg.p(\"\")\n\t\t_ = g.GenerateMockMethod(mockType, m, pkgOverride, shortTp)\n\t\tg.p(\"\")\n\t\t_ = g.GenerateMockRecorderMethod(mockType, m, shortTp)\n\t}\n}\n\nfunc makeArgString(argNames, argTypes []string) string {\n\targs := make([]string, len(argNames))\n\tfor i, name := range argNames {\n\t\t// specify the type only once for consecutive args of the same type\n\t\tif i+1 < len(argTypes) && argTypes[i] == argTypes[i+1] {\n\t\t\targs[i] = name\n\t\t} else {\n\t\t\targs[i] = name + \" \" + argTypes[i]\n\t\t}\n\t}\n\treturn strings.Join(args, \", \")\n}\n\n// GenerateMockMethod generates a mock method implementation.\n// If non-empty, pkgOverride is the package in which unqualified types reside.\nfunc (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOverride, shortTp string) error {\n\targNames := g.getArgNames(m)\n\targTypes := g.getArgTypes(m, pkgOverride)\n\targString := makeArgString(argNames, argTypes)\n\n\trets := make([]string, len(m.Out))\n\tfor i, p := range m.Out {\n\t\trets[i] = p.Type.String(g.packageMap, pkgOverride)\n\t}\n\tretString := strings.Join(rets, \", \")\n\tif len(rets) > 1 {\n\t\tretString = \"(\" + retString + \")\"\n\t}\n\tif retString != \"\" {\n\t\tretString = \" \" + retString\n\t}\n\n\tia := newIdentifierAllocator(argNames)\n\tidRecv := ia.allocateIdentifier(\"m\")\n\n\tg.p(\"// %v mocks base method.\", m.Name)\n\tg.p(\"func (%v *%v%v) %v(%v)%v {\", idRecv, mockType, shortTp, m.Name, argString, retString)\n\tg.in()\n\tg.p(\"%s.ctrl.T.Helper()\", idRecv)\n\n\tvar callArgs string\n\tif m.Variadic == nil {\n\t\tif len(argNames) > 0 {\n\t\t\tcallArgs = \", \" + strings.Join(argNames, \", \")\n\t\t}\n\t} else {\n\t\t// Non-trivial. The generated code must build a []interface{},\n\t\t// but the variadic argument may be any type.\n\t\tidVarArgs := ia.allocateIdentifier(\"varargs\")\n\t\tidVArg := ia.allocateIdentifier(\"a\")\n\t\tg.p(\"%s := []interface{}{%s}\", idVarArgs, strings.Join(argNames[:len(argNames)-1], \", \"))\n\t\tg.p(\"for _, %s := range %s {\", idVArg, argNames[len(argNames)-1])\n\t\tg.in()\n\t\tg.p(\"%s = append(%s, %s)\", idVarArgs, idVarArgs, idVArg)\n\t\tg.out()\n\t\tg.p(\"}\")\n\t\tcallArgs = \", \" + idVarArgs + \"...\"\n\t}\n\tif len(m.Out) == 0 {\n\t\tg.p(`%v.ctrl.Call(%v, %q%v)`, idRecv, idRecv, m.Name, callArgs)\n\t} else {\n\t\tidRet := ia.allocateIdentifier(\"ret\")\n\t\tg.p(`%v := %v.ctrl.Call(%v, %q%v)`, idRet, idRecv, idRecv, m.Name, callArgs)\n\n\t\t// Go does not allow \"naked\" type assertions on nil values, so we use the two-value form here.\n\t\t// The value of that is either (x.(T), true) or (Z, false), where Z is the zero value for T.\n\t\t// Happily, this coincides with the semantics we want here.\n\t\tretNames := make([]string, len(rets))\n\t\tfor i, t := range rets {\n\t\t\tretNames[i] = ia.allocateIdentifier(fmt.Sprintf(\"ret%d\", i))\n\t\t\tg.p(\"%s, _ := %s[%d].(%s)\", retNames[i], idRet, i, t)\n\t\t}\n\t\tg.p(\"return \" + strings.Join(retNames, \", \"))\n\t}\n\n\tg.out()\n\tg.p(\"}\")\n\treturn nil\n}\n\nfunc (g *generator) GenerateMockRecorderMethod(mockType string, m *model.Method, shortTp string) error {\n\targNames := g.getArgNames(m)\n\n\tvar argString string\n\tif m.Variadic == nil {\n\t\targString = strings.Join(argNames, \", \")\n\t} else {\n\t\targString = strings.Join(argNames[:len(argNames)-1], \", \")\n\t}\n\tif argString != \"\" {\n\t\targString += \" interface{}\"\n\t}\n\n\tif m.Variadic != nil {\n\t\tif argString != \"\" {\n\t\t\targString += \", \"\n\t\t}\n\t\targString += fmt.Sprintf(\"%s ...interface{}\", argNames[len(argNames)-1])\n\t}\n\n\tia := newIdentifierAllocator(argNames)\n\tidRecv := ia.allocateIdentifier(\"mr\")\n\n\tg.p(\"// %v indicates an expected call of %v.\", m.Name, m.Name)\n\tg.p(\"func (%s *%vMockRecorder%v) %v(%v) *gomock.Call {\", idRecv, mockType, shortTp, m.Name, argString)\n\tg.in()\n\tg.p(\"%s.mock.ctrl.T.Helper()\", idRecv)\n\n\tvar callArgs string\n\tif m.Variadic == nil {\n\t\tif len(argNames) > 0 {\n\t\t\tcallArgs = \", \" + strings.Join(argNames, \", \")\n\t\t}\n\t} else {\n\t\tif len(argNames) == 1 {\n\t\t\t// Easy: just use ... to push the arguments through.\n\t\t\tcallArgs = \", \" + argNames[0] + \"...\"\n\t\t} else {\n\t\t\t// Hard: create a temporary slice.\n\t\t\tidVarArgs := ia.allocateIdentifier(\"varargs\")\n\t\t\tg.p(\"%s := append([]interface{}{%s}, %s...)\",\n\t\t\t\tidVarArgs,\n\t\t\t\tstrings.Join(argNames[:len(argNames)-1], \", \"),\n\t\t\t\targNames[len(argNames)-1])\n\t\t\tcallArgs = \", \" + idVarArgs + \"...\"\n\t\t}\n\t}\n\tg.p(`return %s.mock.ctrl.RecordCallWithMethodType(%s.mock, \"%s\", reflect.TypeOf((*%s%s)(nil).%s)%s)`, idRecv, idRecv, m.Name, mockType, shortTp, m.Name, callArgs)\n\n\tg.out()\n\tg.p(\"}\")\n\treturn nil\n}\n\nfunc (g *generator) getArgNames(m *model.Method) []string {\n\targNames := make([]string, len(m.In))\n\tfor i, p := range m.In {\n\t\tname := p.Name\n\t\tif name == \"\" || name == \"_\" {\n\t\t\tname = fmt.Sprintf(\"arg%d\", i)\n\t\t}\n\t\targNames[i] = name\n\t}\n\tif m.Variadic != nil {\n\t\tname := m.Variadic.Name\n\t\tif name == \"\" {\n\t\t\tname = fmt.Sprintf(\"arg%d\", len(m.In))\n\t\t}\n\t\targNames = append(argNames, name)\n\t}\n\treturn argNames\n}\n\nfunc (g *generator) getArgTypes(m *model.Method, pkgOverride string) []string {\n\targTypes := make([]string, len(m.In))\n\tfor i, p := range m.In {\n\t\targTypes[i] = p.Type.String(g.packageMap, pkgOverride)\n\t}\n\tif m.Variadic != nil {\n\t\targTypes = append(argTypes, \"...\"+m.Variadic.Type.String(g.packageMap, pkgOverride))\n\t}\n\treturn argTypes\n}\n\ntype identifierAllocator map[string]struct{}\n\nfunc newIdentifierAllocator(taken []string) identifierAllocator {\n\ta := make(identifierAllocator, len(taken))\n\tfor _, s := range taken {\n\t\ta[s] = struct{}{}\n\t}\n\treturn a\n}\n\nfunc (o identifierAllocator) allocateIdentifier(want string) string {\n\tid := want\n\tfor i := 2; ; i++ {\n\t\tif _, ok := o[id]; !ok {\n\t\t\to[id] = struct{}{}\n\t\t\treturn id\n\t\t}\n\t\tid = want + \"_\" + strconv.Itoa(i)\n\t}\n}\n\n// Output returns the generator's output, formatted in the standard Go style.\nfunc (g *generator) Output() []byte {\n\tsrc, err := toolsimports.Process(g.destination, g.buf.Bytes(), nil)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to format generated source code: %s\\n%s\", err, g.buf.String())\n\t}\n\treturn src\n}\n\n// createPackageMap returns a map of import path to package name\n// for specified importPaths.\nfunc createPackageMap(importPaths []string) map[string]string {\n\tvar pkg struct {\n\t\tName       string\n\t\tImportPath string\n\t}\n\tpkgMap := make(map[string]string)\n\tb := bytes.NewBuffer(nil)\n\targs := []string{\"list\", \"-json\"}\n\targs = append(args, importPaths...)\n\tcmd := exec.Command(\"go\", args...)\n\tcmd.Stdout = b\n\tcmd.Run()\n\tdec := json.NewDecoder(b)\n\tfor dec.More() {\n\t\terr := dec.Decode(&pkg)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"failed to decode 'go list' output: %v\", err)\n\t\t\tcontinue\n\t\t}\n\t\tpkgMap[pkg.ImportPath] = pkg.Name\n\t}\n\treturn pkgMap\n}\n\nfunc printVersion() {\n\tif version != \"\" {\n\t\tfmt.Printf(\"v%s\\nCommit: %s\\nDate: %s\\n\", version, commit, date)\n\t} else {\n\t\tprintModuleVersion()\n\t}\n}\n\n// parseImportPackage get package import path via source file\n// an alternative implementation is to use:\n// cfg := &packages.Config{Mode: packages.NeedName, Tests: true, Dir: srcDir}\n// pkgs, err := packages.Load(cfg, \"file=\"+source)\n// However, it will call \"go list\" and slow down the performance\nfunc parsePackageImport(srcDir string) (string, error) {\n\tmoduleMode := os.Getenv(\"GO111MODULE\")\n\t// trying to find the module\n\tif moduleMode != \"off\" {\n\t\tcurrentDir := srcDir\n\t\tfor {\n\t\t\tdat, err := ioutil.ReadFile(filepath.Join(currentDir, \"go.mod\"))\n\t\t\tif os.IsNotExist(err) {\n\t\t\t\tif currentDir == filepath.Dir(currentDir) {\n\t\t\t\t\t// at the root\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcurrentDir = filepath.Dir(currentDir)\n\t\t\t\tcontinue\n\t\t\t} else if err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\tmodulePath := modfile.ModulePath(dat)\n\t\t\treturn filepath.ToSlash(filepath.Join(modulePath, strings.TrimPrefix(srcDir, currentDir))), nil\n\t\t}\n\t}\n\t// fall back to GOPATH mode\n\tgoPaths := os.Getenv(\"GOPATH\")\n\tif goPaths == \"\" {\n\t\treturn \"\", fmt.Errorf(\"GOPATH is not set\")\n\t}\n\tgoPathList := strings.Split(goPaths, string(os.PathListSeparator))\n\tfor _, goPath := range goPathList {\n\t\tsourceRoot := filepath.Join(goPath, \"src\") + string(os.PathSeparator)\n\t\tif strings.HasPrefix(srcDir, sourceRoot) {\n\t\t\treturn filepath.ToSlash(strings.TrimPrefix(srcDir, sourceRoot)), nil\n\t\t}\n\t}\n\treturn \"\", errOutsideGoPath\n}\n"
  },
  {
    "path": "mockgen/mockgen_test.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"reflect\"\n\t\"regexp\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/golang/mock/mockgen/model\"\n)\n\nfunc TestMakeArgString(t *testing.T) {\n\ttestCases := []struct {\n\t\targNames  []string\n\t\targTypes  []string\n\t\targString string\n\t}{\n\t\t{\n\t\t\targNames:  nil,\n\t\t\targTypes:  nil,\n\t\t\targString: \"\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\"},\n\t\t\targTypes:  []string{\"int\"},\n\t\t\targString: \"arg0 int\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\"},\n\t\t\targTypes:  []string{\"int\", \"bool\"},\n\t\t\targString: \"arg0 int, arg1 bool\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\"},\n\t\t\targTypes:  []string{\"int\", \"int\"},\n\t\t\targString: \"arg0, arg1 int\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\"},\n\t\t\targTypes:  []string{\"bool\", \"int\", \"int\"},\n\t\t\targString: \"arg0 bool, arg1, arg2 int\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\"},\n\t\t\targTypes:  []string{\"int\", \"bool\", \"int\"},\n\t\t\targString: \"arg0 int, arg1 bool, arg2 int\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\"},\n\t\t\targTypes:  []string{\"int\", \"int\", \"bool\"},\n\t\t\targString: \"arg0, arg1 int, arg2 bool\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\"},\n\t\t\targTypes:  []string{\"int\", \"int\", \"int\"},\n\t\t\targString: \"arg0, arg1, arg2 int\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\", \"arg3\"},\n\t\t\targTypes:  []string{\"bool\", \"int\", \"int\", \"int\"},\n\t\t\targString: \"arg0 bool, arg1, arg2, arg3 int\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\", \"arg3\"},\n\t\t\targTypes:  []string{\"int\", \"bool\", \"int\", \"int\"},\n\t\t\targString: \"arg0 int, arg1 bool, arg2, arg3 int\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\", \"arg3\"},\n\t\t\targTypes:  []string{\"int\", \"int\", \"bool\", \"int\"},\n\t\t\targString: \"arg0, arg1 int, arg2 bool, arg3 int\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\", \"arg3\"},\n\t\t\targTypes:  []string{\"int\", \"int\", \"int\", \"bool\"},\n\t\t\targString: \"arg0, arg1, arg2 int, arg3 bool\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\", \"arg3\", \"arg4\"},\n\t\t\targTypes:  []string{\"bool\", \"int\", \"int\", \"int\", \"bool\"},\n\t\t\targString: \"arg0 bool, arg1, arg2, arg3 int, arg4 bool\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\", \"arg3\", \"arg4\"},\n\t\t\targTypes:  []string{\"int\", \"bool\", \"int\", \"int\", \"bool\"},\n\t\t\targString: \"arg0 int, arg1 bool, arg2, arg3 int, arg4 bool\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\", \"arg3\", \"arg4\"},\n\t\t\targTypes:  []string{\"int\", \"int\", \"bool\", \"int\", \"bool\"},\n\t\t\targString: \"arg0, arg1 int, arg2 bool, arg3 int, arg4 bool\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\", \"arg3\", \"arg4\"},\n\t\t\targTypes:  []string{\"int\", \"int\", \"int\", \"bool\", \"bool\"},\n\t\t\targString: \"arg0, arg1, arg2 int, arg3, arg4 bool\",\n\t\t},\n\t\t{\n\t\t\targNames:  []string{\"arg0\", \"arg1\", \"arg2\", \"arg3\", \"arg4\"},\n\t\t\targTypes:  []string{\"int\", \"int\", \"bool\", \"bool\", \"int\"},\n\t\t\targString: \"arg0, arg1 int, arg2, arg3 bool, arg4 int\",\n\t\t},\n\t}\n\n\tfor i, tc := range testCases {\n\t\tt.Run(fmt.Sprintf(\"#%d\", i), func(t *testing.T) {\n\t\t\ts := makeArgString(tc.argNames, tc.argTypes)\n\t\t\tif s != tc.argString {\n\t\t\t\tt.Errorf(\"result == %q, want %q\", s, tc.argString)\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestNewIdentifierAllocator(t *testing.T) {\n\ta := newIdentifierAllocator([]string{\"taken1\", \"taken2\"})\n\tif len(a) != 2 {\n\t\tt.Fatalf(\"expected 2 items, got %v\", len(a))\n\t}\n\n\t_, ok := a[\"taken1\"]\n\tif !ok {\n\t\tt.Errorf(\"allocator doesn't contain 'taken1': %#v\", a)\n\t}\n\n\t_, ok = a[\"taken2\"]\n\tif !ok {\n\t\tt.Errorf(\"allocator doesn't contain 'taken2': %#v\", a)\n\t}\n}\n\nfunc allocatorContainsIdentifiers(a identifierAllocator, ids []string) bool {\n\tif len(a) != len(ids) {\n\t\treturn false\n\t}\n\n\tfor _, id := range ids {\n\t\t_, ok := a[id]\n\t\tif !ok {\n\t\t\treturn false\n\t\t}\n\t}\n\n\treturn true\n}\n\nfunc TestIdentifierAllocator_allocateIdentifier(t *testing.T) {\n\ta := newIdentifierAllocator([]string{\"taken\"})\n\n\tt2 := a.allocateIdentifier(\"taken_2\")\n\tif t2 != \"taken_2\" {\n\t\tt.Fatalf(\"expected 'taken_2', got %q\", t2)\n\t}\n\texpected := []string{\"taken\", \"taken_2\"}\n\tif !allocatorContainsIdentifiers(a, expected) {\n\t\tt.Fatalf(\"allocator doesn't contain the expected items - allocator: %#v, expected items: %#v\", a, expected)\n\t}\n\n\tt3 := a.allocateIdentifier(\"taken\")\n\tif t3 != \"taken_3\" {\n\t\tt.Fatalf(\"expected 'taken_3', got %q\", t3)\n\t}\n\texpected = []string{\"taken\", \"taken_2\", \"taken_3\"}\n\tif !allocatorContainsIdentifiers(a, expected) {\n\t\tt.Fatalf(\"allocator doesn't contain the expected items - allocator: %#v, expected items: %#v\", a, expected)\n\t}\n\n\tt4 := a.allocateIdentifier(\"taken\")\n\tif t4 != \"taken_4\" {\n\t\tt.Fatalf(\"expected 'taken_4', got %q\", t4)\n\t}\n\texpected = []string{\"taken\", \"taken_2\", \"taken_3\", \"taken_4\"}\n\tif !allocatorContainsIdentifiers(a, expected) {\n\t\tt.Fatalf(\"allocator doesn't contain the expected items - allocator: %#v, expected items: %#v\", a, expected)\n\t}\n\n\tid := a.allocateIdentifier(\"id\")\n\tif id != \"id\" {\n\t\tt.Fatalf(\"expected 'id', got %q\", id)\n\t}\n\texpected = []string{\"taken\", \"taken_2\", \"taken_3\", \"taken_4\", \"id\"}\n\tif !allocatorContainsIdentifiers(a, expected) {\n\t\tt.Fatalf(\"allocator doesn't contain the expected items - allocator: %#v, expected items: %#v\", a, expected)\n\t}\n}\n\nfunc TestGenerateMockInterface_Helper(t *testing.T) {\n\tfor _, test := range []struct {\n\t\tName       string\n\t\tIdentifier string\n\t\tHelperLine string\n\t\tMethods    []*model.Method\n\t}{\n\t\t{Name: \"mock\", Identifier: \"MockSomename\", HelperLine: \"m.ctrl.T.Helper()\"},\n\t\t{Name: \"recorder\", Identifier: \"MockSomenameMockRecorder\", HelperLine: \"mr.mock.ctrl.T.Helper()\"},\n\t\t{\n\t\t\tName:       \"mock identifier conflict\",\n\t\t\tIdentifier: \"MockSomename\",\n\t\t\tHelperLine: \"m_2.ctrl.T.Helper()\",\n\t\t\tMethods: []*model.Method{\n\t\t\t\t{\n\t\t\t\t\tName: \"MethodA\",\n\t\t\t\t\tIn: []*model.Parameter{\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tName: \"m\",\n\t\t\t\t\t\t\tType: &model.NamedType{Type: \"int\"},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tName:       \"recorder identifier conflict\",\n\t\t\tIdentifier: \"MockSomenameMockRecorder\",\n\t\t\tHelperLine: \"mr_2.mock.ctrl.T.Helper()\",\n\t\t\tMethods: []*model.Method{\n\t\t\t\t{\n\t\t\t\t\tName: \"MethodA\",\n\t\t\t\t\tIn: []*model.Parameter{\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tName: \"mr\",\n\t\t\t\t\t\t\tType: &model.NamedType{Type: \"int\"},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t} {\n\t\tt.Run(test.Name, func(t *testing.T) {\n\t\t\tg := generator{}\n\n\t\t\tif len(test.Methods) == 0 {\n\t\t\t\ttest.Methods = []*model.Method{\n\t\t\t\t\t{Name: \"MethodA\"},\n\t\t\t\t\t{Name: \"MethodB\"},\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tintf := &model.Interface{Name: \"Somename\"}\n\t\t\tfor _, m := range test.Methods {\n\t\t\t\tintf.AddMethod(m)\n\t\t\t}\n\n\t\t\tif err := g.GenerateMockInterface(intf, \"somepackage\"); err != nil {\n\t\t\t\tt.Fatal(err)\n\t\t\t}\n\n\t\t\tlines := strings.Split(g.buf.String(), \"\\n\")\n\n\t\t\t// T.Helper() should be the first line\n\t\t\tfor _, method := range test.Methods {\n\t\t\t\tif strings.TrimSpace(lines[findMethod(t, test.Identifier, method.Name, lines)+1]) != test.HelperLine {\n\t\t\t\t\tt.Fatalf(\"method %s.%s did not declare itself a Helper method\", test.Identifier, method.Name)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc findMethod(t *testing.T, identifier, methodName string, lines []string) int {\n\tt.Helper()\n\tr := regexp.MustCompile(fmt.Sprintf(`func\\s+\\(.+%s\\)\\s*%s`, identifier, methodName))\n\tfor i, line := range lines {\n\t\tif r.MatchString(line) {\n\t\t\treturn i\n\t\t}\n\t}\n\n\tt.Fatalf(\"unable to find 'func (m %s) %s'\", identifier, methodName)\n\tpanic(\"unreachable\")\n}\n\nfunc TestGetArgNames(t *testing.T) {\n\tfor _, testCase := range []struct {\n\t\tname     string\n\t\tmethod   *model.Method\n\t\texpected []string\n\t}{\n\t\t{\n\t\t\tname: \"NamedArg\",\n\t\t\tmethod: &model.Method{\n\t\t\t\tIn: []*model.Parameter{\n\t\t\t\t\t{\n\t\t\t\t\t\tName: \"firstArg\",\n\t\t\t\t\t\tType: &model.NamedType{Type: \"int\"},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tName: \"secondArg\",\n\t\t\t\t\t\tType: &model.NamedType{Type: \"string\"},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\texpected: []string{\"firstArg\", \"secondArg\"},\n\t\t},\n\t\t{\n\t\t\tname: \"NotNamedArg\",\n\t\t\tmethod: &model.Method{\n\t\t\t\tIn: []*model.Parameter{\n\t\t\t\t\t{\n\t\t\t\t\t\tName: \"\",\n\t\t\t\t\t\tType: &model.NamedType{Type: \"int\"},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tName: \"\",\n\t\t\t\t\t\tType: &model.NamedType{Type: \"string\"},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\texpected: []string{\"arg0\", \"arg1\"},\n\t\t},\n\t\t{\n\t\t\tname: \"MixedNameArg\",\n\t\t\tmethod: &model.Method{\n\t\t\t\tIn: []*model.Parameter{\n\t\t\t\t\t{\n\t\t\t\t\t\tName: \"firstArg\",\n\t\t\t\t\t\tType: &model.NamedType{Type: \"int\"},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tName: \"_\",\n\t\t\t\t\t\tType: &model.NamedType{Type: \"string\"},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\texpected: []string{\"firstArg\", \"arg1\"},\n\t\t},\n\t} {\n\t\tt.Run(testCase.name, func(t *testing.T) {\n\t\t\tg := generator{}\n\n\t\t\tresult := g.getArgNames(testCase.method)\n\t\t\tif !reflect.DeepEqual(result, testCase.expected) {\n\t\t\t\tt.Fatalf(\"expected %s, got %s\", result, testCase.expected)\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc Test_createPackageMap(t *testing.T) {\n\ttests := []struct {\n\t\tname            string\n\t\timportPath      string\n\t\twantPackageName string\n\t\twantOK          bool\n\t}{\n\t\t{\"golang package\", \"context\", \"context\", true},\n\t\t{\"third party\", \"golang.org/x/tools/present\", \"present\", true},\n\t}\n\tvar importPaths []string\n\tfor _, t := range tests {\n\t\timportPaths = append(importPaths, t.importPath)\n\t}\n\tpackages := createPackageMap(importPaths)\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tgotPackageName, gotOk := packages[tt.importPath]\n\t\t\tif gotPackageName != tt.wantPackageName {\n\t\t\t\tt.Errorf(\"createPackageMap() gotPackageName = %v, wantPackageName = %v\", gotPackageName, tt.wantPackageName)\n\t\t\t}\n\t\t\tif gotOk != tt.wantOK {\n\t\t\t\tt.Errorf(\"createPackageMap() gotOk = %v, wantOK = %v\", gotOk, tt.wantOK)\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestParsePackageImport_FallbackGoPath(t *testing.T) {\n\tgoPath, err := ioutil.TempDir(\"\", \"gopath\")\n\tif err != nil {\n\t\tt.Error(err)\n\t}\n\tdefer func() {\n\t\tif err = os.RemoveAll(goPath); err != nil {\n\t\t\tt.Error(err)\n\t\t}\n\t}()\n\tsrcDir := filepath.Join(goPath, \"src/example.com/foo\")\n\terr = os.MkdirAll(srcDir, 0755)\n\tif err != nil {\n\t\tt.Error(err)\n\t}\n\tkey := \"GOPATH\"\n\tvalue := goPath\n\tif err := os.Setenv(key, value); err != nil {\n\t\tt.Fatalf(\"unable to set environment variable %q to %q: %v\", key, value, err)\n\t}\n\tkey = \"GO111MODULE\"\n\tvalue = \"on\"\n\tif err := os.Setenv(key, value); err != nil {\n\t\tt.Fatalf(\"unable to set environment variable %q to %q: %v\", key, value, err)\n\t}\n\tpkgPath, err := parsePackageImport(srcDir)\n\texpected := \"example.com/foo\"\n\tif pkgPath != expected {\n\t\tt.Errorf(\"expect %s, got %s\", expected, pkgPath)\n\t}\n}\n\nfunc TestParsePackageImport_FallbackMultiGoPath(t *testing.T) {\n\tvar goPathList []string\n\n\t// first gopath\n\tgoPath, err := ioutil.TempDir(\"\", \"gopath1\")\n\tif err != nil {\n\t\tt.Error(err)\n\t}\n\tgoPathList = append(goPathList, goPath)\n\tdefer func() {\n\t\tif err = os.RemoveAll(goPath); err != nil {\n\t\t\tt.Error(err)\n\t\t}\n\t}()\n\tsrcDir := filepath.Join(goPath, \"src/example.com/foo\")\n\terr = os.MkdirAll(srcDir, 0755)\n\tif err != nil {\n\t\tt.Error(err)\n\t}\n\n\t// second gopath\n\tgoPath, err = ioutil.TempDir(\"\", \"gopath2\")\n\tif err != nil {\n\t\tt.Error(err)\n\t}\n\tgoPathList = append(goPathList, goPath)\n\tdefer func() {\n\t\tif err = os.RemoveAll(goPath); err != nil {\n\t\t\tt.Error(err)\n\t\t}\n\t}()\n\n\tgoPaths := strings.Join(goPathList, string(os.PathListSeparator))\n\tkey := \"GOPATH\"\n\tvalue := goPaths\n\tif err := os.Setenv(key, value); err != nil {\n\t\tt.Fatalf(\"unable to set environment variable %q to %q: %v\", key, value, err)\n\t}\n\tkey = \"GO111MODULE\"\n\tvalue = \"on\"\n\tif err := os.Setenv(key, value); err != nil {\n\t\tt.Fatalf(\"unable to set environment variable %q to %q: %v\", key, value, err)\n\t}\n\tpkgPath, err := parsePackageImport(srcDir)\n\texpected := \"example.com/foo\"\n\tif pkgPath != expected {\n\t\tt.Errorf(\"expect %s, got %s\", expected, pkgPath)\n\t}\n}\n"
  },
  {
    "path": "mockgen/model/model.go",
    "content": "// Copyright 2012 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Package model contains the data model necessary for generating mock implementations.\npackage model\n\nimport (\n\t\"encoding/gob\"\n\t\"fmt\"\n\t\"io\"\n\t\"reflect\"\n\t\"strings\"\n)\n\n// pkgPath is the importable path for package model\nconst pkgPath = \"github.com/golang/mock/mockgen/model\"\n\n// Package is a Go package. It may be a subset.\ntype Package struct {\n\tName       string\n\tPkgPath    string\n\tInterfaces []*Interface\n\tDotImports []string\n}\n\n// Print writes the package name and its exported interfaces.\nfunc (pkg *Package) Print(w io.Writer) {\n\t_, _ = fmt.Fprintf(w, \"package %s\\n\", pkg.Name)\n\tfor _, intf := range pkg.Interfaces {\n\t\tintf.Print(w)\n\t}\n}\n\n// Imports returns the imports needed by the Package as a set of import paths.\nfunc (pkg *Package) Imports() map[string]bool {\n\tim := make(map[string]bool)\n\tfor _, intf := range pkg.Interfaces {\n\t\tintf.addImports(im)\n\t\tfor _, tp := range intf.TypeParams {\n\t\t\ttp.Type.addImports(im)\n\t\t}\n\t}\n\treturn im\n}\n\n// Interface is a Go interface.\ntype Interface struct {\n\tName       string\n\tMethods    []*Method\n\tTypeParams []*Parameter\n}\n\n// Print writes the interface name and its methods.\nfunc (intf *Interface) Print(w io.Writer) {\n\t_, _ = fmt.Fprintf(w, \"interface %s\\n\", intf.Name)\n\tfor _, m := range intf.Methods {\n\t\tm.Print(w)\n\t}\n}\n\nfunc (intf *Interface) addImports(im map[string]bool) {\n\tfor _, m := range intf.Methods {\n\t\tm.addImports(im)\n\t}\n}\n\n// AddMethod adds a new method, de-duplicating by method name.\nfunc (intf *Interface) AddMethod(m *Method) {\n\tfor _, me := range intf.Methods {\n\t\tif me.Name == m.Name {\n\t\t\treturn\n\t\t}\n\t}\n\tintf.Methods = append(intf.Methods, m)\n}\n\n// Method is a single method of an interface.\ntype Method struct {\n\tName     string\n\tIn, Out  []*Parameter\n\tVariadic *Parameter // may be nil\n}\n\n// Print writes the method name and its signature.\nfunc (m *Method) Print(w io.Writer) {\n\t_, _ = fmt.Fprintf(w, \"  - method %s\\n\", m.Name)\n\tif len(m.In) > 0 {\n\t\t_, _ = fmt.Fprintf(w, \"    in:\\n\")\n\t\tfor _, p := range m.In {\n\t\t\tp.Print(w)\n\t\t}\n\t}\n\tif m.Variadic != nil {\n\t\t_, _ = fmt.Fprintf(w, \"    ...:\\n\")\n\t\tm.Variadic.Print(w)\n\t}\n\tif len(m.Out) > 0 {\n\t\t_, _ = fmt.Fprintf(w, \"    out:\\n\")\n\t\tfor _, p := range m.Out {\n\t\t\tp.Print(w)\n\t\t}\n\t}\n}\n\nfunc (m *Method) addImports(im map[string]bool) {\n\tfor _, p := range m.In {\n\t\tp.Type.addImports(im)\n\t}\n\tif m.Variadic != nil {\n\t\tm.Variadic.Type.addImports(im)\n\t}\n\tfor _, p := range m.Out {\n\t\tp.Type.addImports(im)\n\t}\n}\n\n// Parameter is an argument or return parameter of a method.\ntype Parameter struct {\n\tName string // may be empty\n\tType Type\n}\n\n// Print writes a method parameter.\nfunc (p *Parameter) Print(w io.Writer) {\n\tn := p.Name\n\tif n == \"\" {\n\t\tn = `\"\"`\n\t}\n\t_, _ = fmt.Fprintf(w, \"    - %v: %v\\n\", n, p.Type.String(nil, \"\"))\n}\n\n// Type is a Go type.\ntype Type interface {\n\tString(pm map[string]string, pkgOverride string) string\n\taddImports(im map[string]bool)\n}\n\nfunc init() {\n\tgob.Register(&ArrayType{})\n\tgob.Register(&ChanType{})\n\tgob.Register(&FuncType{})\n\tgob.Register(&MapType{})\n\tgob.Register(&NamedType{})\n\tgob.Register(&PointerType{})\n\n\t// Call gob.RegisterName to make sure it has the consistent name registered\n\t// for both gob decoder and encoder.\n\t//\n\t// For a non-pointer type, gob.Register will try to get package full path by\n\t// calling rt.PkgPath() for a name to register. If your project has vendor\n\t// directory, it is possible that PkgPath will get a path like this:\n\t//     ../../../vendor/github.com/golang/mock/mockgen/model\n\tgob.RegisterName(pkgPath+\".PredeclaredType\", PredeclaredType(\"\"))\n}\n\n// ArrayType is an array or slice type.\ntype ArrayType struct {\n\tLen  int // -1 for slices, >= 0 for arrays\n\tType Type\n}\n\nfunc (at *ArrayType) String(pm map[string]string, pkgOverride string) string {\n\ts := \"[]\"\n\tif at.Len > -1 {\n\t\ts = fmt.Sprintf(\"[%d]\", at.Len)\n\t}\n\treturn s + at.Type.String(pm, pkgOverride)\n}\n\nfunc (at *ArrayType) addImports(im map[string]bool) { at.Type.addImports(im) }\n\n// ChanType is a channel type.\ntype ChanType struct {\n\tDir  ChanDir // 0, 1 or 2\n\tType Type\n}\n\nfunc (ct *ChanType) String(pm map[string]string, pkgOverride string) string {\n\ts := ct.Type.String(pm, pkgOverride)\n\tif ct.Dir == RecvDir {\n\t\treturn \"<-chan \" + s\n\t}\n\tif ct.Dir == SendDir {\n\t\treturn \"chan<- \" + s\n\t}\n\treturn \"chan \" + s\n}\n\nfunc (ct *ChanType) addImports(im map[string]bool) { ct.Type.addImports(im) }\n\n// ChanDir is a channel direction.\ntype ChanDir int\n\n// Constants for channel directions.\nconst (\n\tRecvDir ChanDir = 1\n\tSendDir ChanDir = 2\n)\n\n// FuncType is a function type.\ntype FuncType struct {\n\tIn, Out  []*Parameter\n\tVariadic *Parameter // may be nil\n}\n\nfunc (ft *FuncType) String(pm map[string]string, pkgOverride string) string {\n\targs := make([]string, len(ft.In))\n\tfor i, p := range ft.In {\n\t\targs[i] = p.Type.String(pm, pkgOverride)\n\t}\n\tif ft.Variadic != nil {\n\t\targs = append(args, \"...\"+ft.Variadic.Type.String(pm, pkgOverride))\n\t}\n\trets := make([]string, len(ft.Out))\n\tfor i, p := range ft.Out {\n\t\trets[i] = p.Type.String(pm, pkgOverride)\n\t}\n\tretString := strings.Join(rets, \", \")\n\tif nOut := len(ft.Out); nOut == 1 {\n\t\tretString = \" \" + retString\n\t} else if nOut > 1 {\n\t\tretString = \" (\" + retString + \")\"\n\t}\n\treturn \"func(\" + strings.Join(args, \", \") + \")\" + retString\n}\n\nfunc (ft *FuncType) addImports(im map[string]bool) {\n\tfor _, p := range ft.In {\n\t\tp.Type.addImports(im)\n\t}\n\tif ft.Variadic != nil {\n\t\tft.Variadic.Type.addImports(im)\n\t}\n\tfor _, p := range ft.Out {\n\t\tp.Type.addImports(im)\n\t}\n}\n\n// MapType is a map type.\ntype MapType struct {\n\tKey, Value Type\n}\n\nfunc (mt *MapType) String(pm map[string]string, pkgOverride string) string {\n\treturn \"map[\" + mt.Key.String(pm, pkgOverride) + \"]\" + mt.Value.String(pm, pkgOverride)\n}\n\nfunc (mt *MapType) addImports(im map[string]bool) {\n\tmt.Key.addImports(im)\n\tmt.Value.addImports(im)\n}\n\n// NamedType is an exported type in a package.\ntype NamedType struct {\n\tPackage    string // may be empty\n\tType       string\n\tTypeParams *TypeParametersType\n}\n\nfunc (nt *NamedType) String(pm map[string]string, pkgOverride string) string {\n\tif pkgOverride == nt.Package {\n\t\treturn nt.Type + nt.TypeParams.String(pm, pkgOverride)\n\t}\n\tprefix := pm[nt.Package]\n\tif prefix != \"\" {\n\t\treturn prefix + \".\" + nt.Type + nt.TypeParams.String(pm, pkgOverride)\n\t}\n\n\treturn nt.Type + nt.TypeParams.String(pm, pkgOverride)\n}\n\nfunc (nt *NamedType) addImports(im map[string]bool) {\n\tif nt.Package != \"\" {\n\t\tim[nt.Package] = true\n\t}\n\tnt.TypeParams.addImports(im)\n}\n\n// PointerType is a pointer to another type.\ntype PointerType struct {\n\tType Type\n}\n\nfunc (pt *PointerType) String(pm map[string]string, pkgOverride string) string {\n\treturn \"*\" + pt.Type.String(pm, pkgOverride)\n}\nfunc (pt *PointerType) addImports(im map[string]bool) { pt.Type.addImports(im) }\n\n// PredeclaredType is a predeclared type such as \"int\".\ntype PredeclaredType string\n\nfunc (pt PredeclaredType) String(map[string]string, string) string { return string(pt) }\nfunc (pt PredeclaredType) addImports(map[string]bool)              {}\n\n// TypeParametersType contains type paramters for a NamedType.\ntype TypeParametersType struct {\n\tTypeParameters []Type\n}\n\nfunc (tp *TypeParametersType) String(pm map[string]string, pkgOverride string) string {\n\tif tp == nil || len(tp.TypeParameters) == 0 {\n\t\treturn \"\"\n\t}\n\tvar sb strings.Builder\n\tsb.WriteString(\"[\")\n\tfor i, v := range tp.TypeParameters {\n\t\tif i != 0 {\n\t\t\tsb.WriteString(\", \")\n\t\t}\n\t\tsb.WriteString(v.String(pm, pkgOverride))\n\t}\n\tsb.WriteString(\"]\")\n\treturn sb.String()\n}\n\nfunc (tp *TypeParametersType) addImports(im map[string]bool) {\n\tif tp == nil {\n\t\treturn\n\t}\n\tfor _, v := range tp.TypeParameters {\n\t\tv.addImports(im)\n\t}\n}\n\n// The following code is intended to be called by the program generated by ../reflect.go.\n\n// InterfaceFromInterfaceType returns a pointer to an interface for the\n// given reflection interface type.\nfunc InterfaceFromInterfaceType(it reflect.Type) (*Interface, error) {\n\tif it.Kind() != reflect.Interface {\n\t\treturn nil, fmt.Errorf(\"%v is not an interface\", it)\n\t}\n\tintf := &Interface{}\n\n\tfor i := 0; i < it.NumMethod(); i++ {\n\t\tmt := it.Method(i)\n\t\t// TODO: need to skip unexported methods? or just raise an error?\n\t\tm := &Method{\n\t\t\tName: mt.Name,\n\t\t}\n\n\t\tvar err error\n\t\tm.In, m.Variadic, m.Out, err = funcArgsFromType(mt.Type)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tintf.AddMethod(m)\n\t}\n\n\treturn intf, nil\n}\n\n// t's Kind must be a reflect.Func.\nfunc funcArgsFromType(t reflect.Type) (in []*Parameter, variadic *Parameter, out []*Parameter, err error) {\n\tnin := t.NumIn()\n\tif t.IsVariadic() {\n\t\tnin--\n\t}\n\tvar p *Parameter\n\tfor i := 0; i < nin; i++ {\n\t\tp, err = parameterFromType(t.In(i))\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t\tin = append(in, p)\n\t}\n\tif t.IsVariadic() {\n\t\tp, err = parameterFromType(t.In(nin).Elem())\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t\tvariadic = p\n\t}\n\tfor i := 0; i < t.NumOut(); i++ {\n\t\tp, err = parameterFromType(t.Out(i))\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t\tout = append(out, p)\n\t}\n\treturn\n}\n\nfunc parameterFromType(t reflect.Type) (*Parameter, error) {\n\ttt, err := typeFromType(t)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn &Parameter{Type: tt}, nil\n}\n\nvar errorType = reflect.TypeOf((*error)(nil)).Elem()\n\nvar byteType = reflect.TypeOf(byte(0))\n\nfunc typeFromType(t reflect.Type) (Type, error) {\n\t// Hack workaround for https://golang.org/issue/3853.\n\t// This explicit check should not be necessary.\n\tif t == byteType {\n\t\treturn PredeclaredType(\"byte\"), nil\n\t}\n\n\tif imp := t.PkgPath(); imp != \"\" {\n\t\treturn &NamedType{\n\t\t\tPackage: impPath(imp),\n\t\t\tType:    t.Name(),\n\t\t}, nil\n\t}\n\n\t// only unnamed or predeclared types after here\n\n\t// Lots of types have element types. Let's do the parsing and error checking for all of them.\n\tvar elemType Type\n\tswitch t.Kind() {\n\tcase reflect.Array, reflect.Chan, reflect.Map, reflect.Ptr, reflect.Slice:\n\t\tvar err error\n\t\telemType, err = typeFromType(t.Elem())\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tswitch t.Kind() {\n\tcase reflect.Array:\n\t\treturn &ArrayType{\n\t\t\tLen:  t.Len(),\n\t\t\tType: elemType,\n\t\t}, nil\n\tcase reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n\t\treflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,\n\t\treflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.String:\n\t\treturn PredeclaredType(t.Kind().String()), nil\n\tcase reflect.Chan:\n\t\tvar dir ChanDir\n\t\tswitch t.ChanDir() {\n\t\tcase reflect.RecvDir:\n\t\t\tdir = RecvDir\n\t\tcase reflect.SendDir:\n\t\t\tdir = SendDir\n\t\t}\n\t\treturn &ChanType{\n\t\t\tDir:  dir,\n\t\t\tType: elemType,\n\t\t}, nil\n\tcase reflect.Func:\n\t\tin, variadic, out, err := funcArgsFromType(t)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &FuncType{\n\t\t\tIn:       in,\n\t\t\tOut:      out,\n\t\t\tVariadic: variadic,\n\t\t}, nil\n\tcase reflect.Interface:\n\t\t// Two special interfaces.\n\t\tif t.NumMethod() == 0 {\n\t\t\treturn PredeclaredType(\"interface{}\"), nil\n\t\t}\n\t\tif t == errorType {\n\t\t\treturn PredeclaredType(\"error\"), nil\n\t\t}\n\tcase reflect.Map:\n\t\tkt, err := typeFromType(t.Key())\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &MapType{\n\t\t\tKey:   kt,\n\t\t\tValue: elemType,\n\t\t}, nil\n\tcase reflect.Ptr:\n\t\treturn &PointerType{\n\t\t\tType: elemType,\n\t\t}, nil\n\tcase reflect.Slice:\n\t\treturn &ArrayType{\n\t\t\tLen:  -1,\n\t\t\tType: elemType,\n\t\t}, nil\n\tcase reflect.Struct:\n\t\tif t.NumField() == 0 {\n\t\t\treturn PredeclaredType(\"struct{}\"), nil\n\t\t}\n\t}\n\n\t// TODO: Struct, UnsafePointer\n\treturn nil, fmt.Errorf(\"can't yet turn %v (%v) into a model.Type\", t, t.Kind())\n}\n\n// impPath sanitizes the package path returned by `PkgPath` method of a reflect Type so that\n// it is importable. PkgPath might return a path that includes \"vendor\". These paths do not\n// compile, so we need to remove everything up to and including \"/vendor/\".\n// See https://github.com/golang/go/issues/12019.\nfunc impPath(imp string) string {\n\tif strings.HasPrefix(imp, \"vendor/\") {\n\t\timp = \"/\" + imp\n\t}\n\tif i := strings.LastIndex(imp, \"/vendor/\"); i != -1 {\n\t\timp = imp[i+len(\"/vendor/\"):]\n\t}\n\treturn imp\n}\n\n// ErrorInterface represent built-in error interface.\nvar ErrorInterface = Interface{\n\tName: \"error\",\n\tMethods: []*Method{\n\t\t{\n\t\t\tName: \"Error\",\n\t\t\tOut: []*Parameter{\n\t\t\t\t{\n\t\t\t\t\tName: \"\",\n\t\t\t\t\tType: PredeclaredType(\"string\"),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n}\n"
  },
  {
    "path": "mockgen/model/model_test.go",
    "content": "package model\n\nimport (\n\t\"fmt\"\n\t\"testing\"\n)\n\nfunc TestImpPath(t *testing.T) {\n\tnonVendor := \"github.com/foo/bar\"\n\tif nonVendor != impPath(nonVendor) {\n\t\tt.Errorf(\"\")\n\n\t}\n\ttestCases := []struct {\n\t\tinput string\n\t\twant  string\n\t}{\n\t\t{\"foo/bar\", \"foo/bar\"},\n\t\t{\"vendor/foo/bar\", \"foo/bar\"},\n\t\t{\"vendor/foo/vendor/bar\", \"bar\"},\n\t\t{\"/vendor/foo/bar\", \"foo/bar\"},\n\t\t{\"qux/vendor/foo/bar\", \"foo/bar\"},\n\t\t{\"qux/vendor/foo/vendor/bar\", \"bar\"},\n\t\t{\"govendor/foo\", \"govendor/foo\"},\n\t\t{\"foo/govendor/bar\", \"foo/govendor/bar\"},\n\t\t{\"vendors/foo\", \"vendors/foo\"},\n\t\t{\"foo/vendors/bar\", \"foo/vendors/bar\"},\n\t}\n\tfor _, tc := range testCases {\n\t\tt.Run(fmt.Sprintf(\"input %s\", tc.input), func(t *testing.T) {\n\t\t\tif got := impPath(tc.input); got != tc.want {\n\t\t\t\tt.Errorf(\"got %s; want %s\", got, tc.want)\n\t\t\t}\n\t\t})\n\t}\n}\n"
  },
  {
    "path": "mockgen/parse.go",
    "content": "// Copyright 2012 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\n// This file contains the model construction by parsing source files.\n\nimport (\n\t\"errors\"\n\t\"flag\"\n\t\"fmt\"\n\t\"go/ast\"\n\t\"go/build\"\n\t\"go/importer\"\n\t\"go/parser\"\n\t\"go/token\"\n\t\"go/types\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"path\"\n\t\"path/filepath\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/golang/mock/mockgen/model\"\n)\n\nvar (\n\timports  = flag.String(\"imports\", \"\", \"(source mode) Comma-separated name=path pairs of explicit imports to use.\")\n\tauxFiles = flag.String(\"aux_files\", \"\", \"(source mode) Comma-separated pkg=path pairs of auxiliary Go source files.\")\n)\n\n// sourceMode generates mocks via source file.\nfunc sourceMode(source string) (*model.Package, error) {\n\tsrcDir, err := filepath.Abs(filepath.Dir(source))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed getting source directory: %v\", err)\n\t}\n\n\tpackageImport, err := parsePackageImport(srcDir)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tfs := token.NewFileSet()\n\tfile, err := parser.ParseFile(fs, source, nil, 0)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed parsing source file %v: %v\", source, err)\n\t}\n\n\tp := &fileParser{\n\t\tfileSet:            fs,\n\t\timports:            make(map[string]importedPackage),\n\t\timportedInterfaces: newInterfaceCache(),\n\t\tauxInterfaces:      newInterfaceCache(),\n\t\tsrcDir:             srcDir,\n\t}\n\n\t// Handle -imports.\n\tdotImports := make(map[string]bool)\n\tif *imports != \"\" {\n\t\tfor _, kv := range strings.Split(*imports, \",\") {\n\t\t\teq := strings.Index(kv, \"=\")\n\t\t\tk, v := kv[:eq], kv[eq+1:]\n\t\t\tif k == \".\" {\n\t\t\t\tdotImports[v] = true\n\t\t\t} else {\n\t\t\t\tp.imports[k] = importedPkg{path: v}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Handle -aux_files.\n\tif err := p.parseAuxFiles(*auxFiles); err != nil {\n\t\treturn nil, err\n\t}\n\tp.addAuxInterfacesFromFile(packageImport, file) // this file\n\n\tpkg, err := p.parseFile(packageImport, file)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tfor pkgPath := range dotImports {\n\t\tpkg.DotImports = append(pkg.DotImports, pkgPath)\n\t}\n\treturn pkg, nil\n}\n\ntype importedPackage interface {\n\tPath() string\n\tParser() *fileParser\n}\n\ntype importedPkg struct {\n\tpath   string\n\tparser *fileParser\n}\n\nfunc (i importedPkg) Path() string        { return i.path }\nfunc (i importedPkg) Parser() *fileParser { return i.parser }\n\n// duplicateImport is a bit of a misnomer. Currently the parser can't\n// handle cases of multi-file packages importing different packages\n// under the same name. Often these imports would not be problematic,\n// so this type lets us defer raising an error unless the package name\n// is actually used.\ntype duplicateImport struct {\n\tname       string\n\tduplicates []string\n}\n\nfunc (d duplicateImport) Error() string {\n\treturn fmt.Sprintf(\"%q is ambiguous because of duplicate imports: %v\", d.name, d.duplicates)\n}\n\nfunc (d duplicateImport) Path() string        { log.Fatal(d.Error()); return \"\" }\nfunc (d duplicateImport) Parser() *fileParser { log.Fatal(d.Error()); return nil }\n\ntype interfaceCache struct {\n\tm map[string]map[string]*namedInterface\n}\n\nfunc newInterfaceCache() *interfaceCache {\n\treturn &interfaceCache{\n\t\tm: make(map[string]map[string]*namedInterface),\n\t}\n}\n\nfunc (i *interfaceCache) Set(pkg, name string, it *namedInterface) {\n\tif _, ok := i.m[pkg]; !ok {\n\t\ti.m[pkg] = make(map[string]*namedInterface)\n\t}\n\ti.m[pkg][name] = it\n}\n\nfunc (i *interfaceCache) Get(pkg, name string) *namedInterface {\n\tif _, ok := i.m[pkg]; !ok {\n\t\treturn nil\n\t}\n\treturn i.m[pkg][name]\n}\n\nfunc (i *interfaceCache) GetASTIface(pkg, name string) *ast.InterfaceType {\n\tif _, ok := i.m[pkg]; !ok {\n\t\treturn nil\n\t}\n\tit, ok := i.m[pkg][name]\n\tif !ok {\n\t\treturn nil\n\t}\n\treturn it.it\n}\n\ntype fileParser struct {\n\tfileSet            *token.FileSet\n\timports            map[string]importedPackage // package name => imported package\n\timportedInterfaces *interfaceCache\n\tauxFiles           []*ast.File\n\tauxInterfaces      *interfaceCache\n\tsrcDir             string\n}\n\nfunc (p *fileParser) errorf(pos token.Pos, format string, args ...interface{}) error {\n\tps := p.fileSet.Position(pos)\n\tformat = \"%s:%d:%d: \" + format\n\targs = append([]interface{}{ps.Filename, ps.Line, ps.Column}, args...)\n\treturn fmt.Errorf(format, args...)\n}\n\nfunc (p *fileParser) parseAuxFiles(auxFiles string) error {\n\tauxFiles = strings.TrimSpace(auxFiles)\n\tif auxFiles == \"\" {\n\t\treturn nil\n\t}\n\tfor _, kv := range strings.Split(auxFiles, \",\") {\n\t\tparts := strings.SplitN(kv, \"=\", 2)\n\t\tif len(parts) != 2 {\n\t\t\treturn fmt.Errorf(\"bad aux file spec: %v\", kv)\n\t\t}\n\t\tpkg, fpath := parts[0], parts[1]\n\n\t\tfile, err := parser.ParseFile(p.fileSet, fpath, nil, 0)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tp.auxFiles = append(p.auxFiles, file)\n\t\tp.addAuxInterfacesFromFile(pkg, file)\n\t}\n\treturn nil\n}\n\nfunc (p *fileParser) addAuxInterfacesFromFile(pkg string, file *ast.File) {\n\tfor ni := range iterInterfaces(file) {\n\t\tp.auxInterfaces.Set(pkg, ni.name.Name, ni)\n\t}\n}\n\n// parseFile loads all file imports and auxiliary files import into the\n// fileParser, parses all file interfaces and returns package model.\nfunc (p *fileParser) parseFile(importPath string, file *ast.File) (*model.Package, error) {\n\tallImports, dotImports := importsOfFile(file)\n\t// Don't stomp imports provided by -imports. Those should take precedence.\n\tfor pkg, pkgI := range allImports {\n\t\tif _, ok := p.imports[pkg]; !ok {\n\t\t\tp.imports[pkg] = pkgI\n\t\t}\n\t}\n\t// Add imports from auxiliary files, which might be needed for embedded interfaces.\n\t// Don't stomp any other imports.\n\tfor _, f := range p.auxFiles {\n\t\tauxImports, _ := importsOfFile(f)\n\t\tfor pkg, pkgI := range auxImports {\n\t\t\tif _, ok := p.imports[pkg]; !ok {\n\t\t\t\tp.imports[pkg] = pkgI\n\t\t\t}\n\t\t}\n\t}\n\n\tvar is []*model.Interface\n\tfor ni := range iterInterfaces(file) {\n\t\ti, err := p.parseInterface(ni.name.String(), importPath, ni)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tis = append(is, i)\n\t}\n\treturn &model.Package{\n\t\tName:       file.Name.String(),\n\t\tPkgPath:    importPath,\n\t\tInterfaces: is,\n\t\tDotImports: dotImports,\n\t}, nil\n}\n\n// parsePackage loads package specified by path, parses it and returns\n// a new fileParser with the parsed imports and interfaces.\nfunc (p *fileParser) parsePackage(path string) (*fileParser, error) {\n\tnewP := &fileParser{\n\t\tfileSet:            token.NewFileSet(),\n\t\timports:            make(map[string]importedPackage),\n\t\timportedInterfaces: newInterfaceCache(),\n\t\tauxInterfaces:      newInterfaceCache(),\n\t\tsrcDir:             p.srcDir,\n\t}\n\n\tvar pkgs map[string]*ast.Package\n\tif imp, err := build.Import(path, newP.srcDir, build.FindOnly); err != nil {\n\t\treturn nil, err\n\t} else if pkgs, err = parser.ParseDir(newP.fileSet, imp.Dir, nil, 0); err != nil {\n\t\treturn nil, err\n\t}\n\n\tfor _, pkg := range pkgs {\n\t\tfile := ast.MergePackageFiles(pkg, ast.FilterFuncDuplicates|ast.FilterUnassociatedComments|ast.FilterImportDuplicates)\n\t\tfor ni := range iterInterfaces(file) {\n\t\t\tnewP.importedInterfaces.Set(path, ni.name.Name, ni)\n\t\t}\n\t\timports, _ := importsOfFile(file)\n\t\tfor pkgName, pkgI := range imports {\n\t\t\tnewP.imports[pkgName] = pkgI\n\t\t}\n\t}\n\treturn newP, nil\n}\n\nfunc (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*model.Interface, error) {\n\tiface := &model.Interface{Name: name}\n\ttps := make(map[string]bool)\n\n\ttp, err := p.parseFieldList(pkg, it.typeParams, tps)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to parse interface type parameters: %v\", name)\n\t}\n\tiface.TypeParams = tp\n\tfor _, v := range tp {\n\t\ttps[v.Name] = true\n\t}\n\n\tfor _, field := range it.it.Methods.List {\n\t\tswitch v := field.Type.(type) {\n\t\tcase *ast.FuncType:\n\t\t\tif nn := len(field.Names); nn != 1 {\n\t\t\t\treturn nil, fmt.Errorf(\"expected one name for interface %v, got %d\", iface.Name, nn)\n\t\t\t}\n\t\t\tm := &model.Method{\n\t\t\t\tName: field.Names[0].String(),\n\t\t\t}\n\t\t\tvar err error\n\t\t\tm.In, m.Variadic, m.Out, err = p.parseFunc(pkg, v, tps)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tiface.AddMethod(m)\n\t\tcase *ast.Ident:\n\t\t\t// Embedded interface in this package.\n\t\t\tembeddedIfaceType := p.auxInterfaces.Get(pkg, v.String())\n\t\t\tif embeddedIfaceType == nil {\n\t\t\t\tembeddedIfaceType = p.importedInterfaces.Get(pkg, v.String())\n\t\t\t}\n\n\t\t\tvar embeddedIface *model.Interface\n\t\t\tif embeddedIfaceType != nil {\n\t\t\t\tvar err error\n\t\t\t\tembeddedIface, err = p.parseInterface(v.String(), pkg, embeddedIfaceType)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// This is built-in error interface.\n\t\t\t\tif v.String() == model.ErrorInterface.Name {\n\t\t\t\t\tembeddedIface = &model.ErrorInterface\n\t\t\t\t} else {\n\t\t\t\t\tip, err := p.parsePackage(pkg)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, p.errorf(v.Pos(), \"could not parse package %s: %v\", pkg, err)\n\t\t\t\t\t}\n\n\t\t\t\t\tif embeddedIfaceType = ip.importedInterfaces.Get(pkg, v.String()); embeddedIfaceType == nil {\n\t\t\t\t\t\treturn nil, p.errorf(v.Pos(), \"unknown embedded interface %s.%s\", pkg, v.String())\n\t\t\t\t\t}\n\n\t\t\t\t\tembeddedIface, err = ip.parseInterface(v.String(), pkg, embeddedIfaceType)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Copy the methods.\n\t\t\tfor _, m := range embeddedIface.Methods {\n\t\t\t\tiface.AddMethod(m)\n\t\t\t}\n\t\tcase *ast.SelectorExpr:\n\t\t\t// Embedded interface in another package.\n\t\t\tfilePkg, sel := v.X.(*ast.Ident).String(), v.Sel.String()\n\t\t\tembeddedPkg, ok := p.imports[filePkg]\n\t\t\tif !ok {\n\t\t\t\treturn nil, p.errorf(v.X.Pos(), \"unknown package %s\", filePkg)\n\t\t\t}\n\n\t\t\tvar embeddedIface *model.Interface\n\t\t\tvar err error\n\t\t\tembeddedIfaceType := p.auxInterfaces.Get(filePkg, sel)\n\t\t\tif embeddedIfaceType != nil {\n\t\t\t\tembeddedIface, err = p.parseInterface(sel, filePkg, embeddedIfaceType)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tpath := embeddedPkg.Path()\n\t\t\t\tparser := embeddedPkg.Parser()\n\t\t\t\tif parser == nil {\n\t\t\t\t\tip, err := p.parsePackage(path)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, p.errorf(v.Pos(), \"could not parse package %s: %v\", path, err)\n\t\t\t\t\t}\n\t\t\t\t\tparser = ip\n\t\t\t\t\tp.imports[filePkg] = importedPkg{\n\t\t\t\t\t\tpath:   embeddedPkg.Path(),\n\t\t\t\t\t\tparser: parser,\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif embeddedIfaceType = parser.importedInterfaces.Get(path, sel); embeddedIfaceType == nil {\n\t\t\t\t\treturn nil, p.errorf(v.Pos(), \"unknown embedded interface %s.%s\", path, sel)\n\t\t\t\t}\n\t\t\t\tembeddedIface, err = parser.parseInterface(sel, path, embeddedIfaceType)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Copy the methods.\n\t\t\t// TODO: apply shadowing rules.\n\t\t\tfor _, m := range embeddedIface.Methods {\n\t\t\t\tiface.AddMethod(m)\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"don't know how to mock method of type %T\", field.Type)\n\t\t}\n\t}\n\treturn iface, nil\n}\n\nfunc (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]bool) (inParam []*model.Parameter, variadic *model.Parameter, outParam []*model.Parameter, err error) {\n\tif f.Params != nil {\n\t\tregParams := f.Params.List\n\t\tif isVariadic(f) {\n\t\t\tn := len(regParams)\n\t\t\tvarParams := regParams[n-1:]\n\t\t\tregParams = regParams[:n-1]\n\t\t\tvp, err := p.parseFieldList(pkg, varParams, tps)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, nil, p.errorf(varParams[0].Pos(), \"failed parsing variadic argument: %v\", err)\n\t\t\t}\n\t\t\tvariadic = vp[0]\n\t\t}\n\t\tinParam, err = p.parseFieldList(pkg, regParams, tps)\n\t\tif err != nil {\n\t\t\treturn nil, nil, nil, p.errorf(f.Pos(), \"failed parsing arguments: %v\", err)\n\t\t}\n\t}\n\tif f.Results != nil {\n\t\toutParam, err = p.parseFieldList(pkg, f.Results.List, tps)\n\t\tif err != nil {\n\t\t\treturn nil, nil, nil, p.errorf(f.Pos(), \"failed parsing returns: %v\", err)\n\t\t}\n\t}\n\treturn\n}\n\nfunc (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[string]bool) ([]*model.Parameter, error) {\n\tnf := 0\n\tfor _, f := range fields {\n\t\tnn := len(f.Names)\n\t\tif nn == 0 {\n\t\t\tnn = 1 // anonymous parameter\n\t\t}\n\t\tnf += nn\n\t}\n\tif nf == 0 {\n\t\treturn nil, nil\n\t}\n\tps := make([]*model.Parameter, nf)\n\ti := 0 // destination index\n\tfor _, f := range fields {\n\t\tt, err := p.parseType(pkg, f.Type, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif len(f.Names) == 0 {\n\t\t\t// anonymous arg\n\t\t\tps[i] = &model.Parameter{Type: t}\n\t\t\ti++\n\t\t\tcontinue\n\t\t}\n\t\tfor _, name := range f.Names {\n\t\t\tps[i] = &model.Parameter{Name: name.Name, Type: t}\n\t\t\ti++\n\t\t}\n\t}\n\treturn ps, nil\n}\n\nfunc (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) {\n\tswitch v := typ.(type) {\n\tcase *ast.ArrayType:\n\t\tln := -1\n\t\tif v.Len != nil {\n\t\t\tvalue, err := p.parseArrayLength(v.Len)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tln, err = strconv.Atoi(value)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, p.errorf(v.Len.Pos(), \"bad array size: %v\", err)\n\t\t\t}\n\t\t}\n\t\tt, err := p.parseType(pkg, v.Elt, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &model.ArrayType{Len: ln, Type: t}, nil\n\tcase *ast.ChanType:\n\t\tt, err := p.parseType(pkg, v.Value, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tvar dir model.ChanDir\n\t\tif v.Dir == ast.SEND {\n\t\t\tdir = model.SendDir\n\t\t}\n\t\tif v.Dir == ast.RECV {\n\t\t\tdir = model.RecvDir\n\t\t}\n\t\treturn &model.ChanType{Dir: dir, Type: t}, nil\n\tcase *ast.Ellipsis:\n\t\t// assume we're parsing a variadic argument\n\t\treturn p.parseType(pkg, v.Elt, tps)\n\tcase *ast.FuncType:\n\t\tin, variadic, out, err := p.parseFunc(pkg, v, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &model.FuncType{In: in, Out: out, Variadic: variadic}, nil\n\tcase *ast.Ident:\n\t\tif v.IsExported() && !tps[v.Name] {\n\t\t\t// `pkg` may be an aliased imported pkg\n\t\t\t// if so, patch the import w/ the fully qualified import\n\t\t\tmaybeImportedPkg, ok := p.imports[pkg]\n\t\t\tif ok {\n\t\t\t\tpkg = maybeImportedPkg.Path()\n\t\t\t}\n\t\t\t// assume type in this package\n\t\t\treturn &model.NamedType{Package: pkg, Type: v.Name}, nil\n\t\t}\n\n\t\t// assume predeclared type\n\t\treturn model.PredeclaredType(v.Name), nil\n\tcase *ast.InterfaceType:\n\t\tif v.Methods != nil && len(v.Methods.List) > 0 {\n\t\t\treturn nil, p.errorf(v.Pos(), \"can't handle non-empty unnamed interface types\")\n\t\t}\n\t\treturn model.PredeclaredType(\"interface{}\"), nil\n\tcase *ast.MapType:\n\t\tkey, err := p.parseType(pkg, v.Key, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tvalue, err := p.parseType(pkg, v.Value, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &model.MapType{Key: key, Value: value}, nil\n\tcase *ast.SelectorExpr:\n\t\tpkgName := v.X.(*ast.Ident).String()\n\t\tpkg, ok := p.imports[pkgName]\n\t\tif !ok {\n\t\t\treturn nil, p.errorf(v.Pos(), \"unknown package %q\", pkgName)\n\t\t}\n\t\treturn &model.NamedType{Package: pkg.Path(), Type: v.Sel.String()}, nil\n\tcase *ast.StarExpr:\n\t\tt, err := p.parseType(pkg, v.X, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &model.PointerType{Type: t}, nil\n\tcase *ast.StructType:\n\t\tif v.Fields != nil && len(v.Fields.List) > 0 {\n\t\t\treturn nil, p.errorf(v.Pos(), \"can't handle non-empty unnamed struct types\")\n\t\t}\n\t\treturn model.PredeclaredType(\"struct{}\"), nil\n\tcase *ast.ParenExpr:\n\t\treturn p.parseType(pkg, v.X, tps)\n\tdefault:\n\t\tmt, err := p.parseGenericType(pkg, typ, tps)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif mt == nil {\n\t\t\tbreak\n\t\t}\n\t\treturn mt, nil\n\t}\n\n\treturn nil, fmt.Errorf(\"don't know how to parse type %T\", typ)\n}\n\nfunc (p *fileParser) parseArrayLength(expr ast.Expr) (string, error) {\n\tswitch val := expr.(type) {\n\tcase (*ast.BasicLit):\n\t\treturn val.Value, nil\n\tcase (*ast.Ident):\n\t\t// when the length is a const defined locally\n\t\treturn val.Obj.Decl.(*ast.ValueSpec).Values[0].(*ast.BasicLit).Value, nil\n\tcase (*ast.SelectorExpr):\n\t\t// when the length is a const defined in an external package\n\t\tusedPkg, err := importer.Default().Import(fmt.Sprintf(\"%s\", val.X))\n\t\tif err != nil {\n\t\t\treturn \"\", p.errorf(expr.Pos(), \"unknown package in array length: %v\", err)\n\t\t}\n\t\tev, err := types.Eval(token.NewFileSet(), usedPkg, token.NoPos, val.Sel.Name)\n\t\tif err != nil {\n\t\t\treturn \"\", p.errorf(expr.Pos(), \"unknown constant in array length: %v\", err)\n\t\t}\n\t\treturn ev.Value.String(), nil\n\tcase (*ast.ParenExpr):\n\t\treturn p.parseArrayLength(val.X)\n\tcase (*ast.BinaryExpr):\n\t\tx, err := p.parseArrayLength(val.X)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\ty, err := p.parseArrayLength(val.Y)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tbiExpr := fmt.Sprintf(\"%s%v%s\", x, val.Op, y)\n\t\ttv, err := types.Eval(token.NewFileSet(), nil, token.NoPos, biExpr)\n\t\tif err != nil {\n\t\t\treturn \"\", p.errorf(expr.Pos(), \"invalid expression in array length: %v\", err)\n\t\t}\n\t\treturn tv.Value.String(), nil\n\tdefault:\n\t\treturn \"\", p.errorf(expr.Pos(), \"invalid expression in array length: %v\", val)\n\t}\n}\n\n// importsOfFile returns a map of package name to import path\n// of the imports in file.\nfunc importsOfFile(file *ast.File) (normalImports map[string]importedPackage, dotImports []string) {\n\tvar importPaths []string\n\tfor _, is := range file.Imports {\n\t\tif is.Name != nil {\n\t\t\tcontinue\n\t\t}\n\t\timportPath := is.Path.Value[1 : len(is.Path.Value)-1] // remove quotes\n\t\timportPaths = append(importPaths, importPath)\n\t}\n\tpackagesName := createPackageMap(importPaths)\n\tnormalImports = make(map[string]importedPackage)\n\tdotImports = make([]string, 0)\n\tfor _, is := range file.Imports {\n\t\tvar pkgName string\n\t\timportPath := is.Path.Value[1 : len(is.Path.Value)-1] // remove quotes\n\n\t\tif is.Name != nil {\n\t\t\t// Named imports are always certain.\n\t\t\tif is.Name.Name == \"_\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tpkgName = is.Name.Name\n\t\t} else {\n\t\t\tpkg, ok := packagesName[importPath]\n\t\t\tif !ok {\n\t\t\t\t// Fallback to import path suffix. Note that this is uncertain.\n\t\t\t\t_, last := path.Split(importPath)\n\t\t\t\t// If the last path component has dots, the first dot-delimited\n\t\t\t\t// field is used as the name.\n\t\t\t\tpkgName = strings.SplitN(last, \".\", 2)[0]\n\t\t\t} else {\n\t\t\t\tpkgName = pkg\n\t\t\t}\n\t\t}\n\n\t\tif pkgName == \".\" {\n\t\t\tdotImports = append(dotImports, importPath)\n\t\t} else {\n\t\t\tif pkg, ok := normalImports[pkgName]; ok {\n\t\t\t\tswitch p := pkg.(type) {\n\t\t\t\tcase duplicateImport:\n\t\t\t\t\tnormalImports[pkgName] = duplicateImport{\n\t\t\t\t\t\tname:       p.name,\n\t\t\t\t\t\tduplicates: append([]string{importPath}, p.duplicates...),\n\t\t\t\t\t}\n\t\t\t\tcase importedPkg:\n\t\t\t\t\tnormalImports[pkgName] = duplicateImport{\n\t\t\t\t\t\tname:       pkgName,\n\t\t\t\t\t\tduplicates: []string{p.path, importPath},\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnormalImports[pkgName] = importedPkg{path: importPath}\n\t\t\t}\n\t\t}\n\t}\n\treturn\n}\n\ntype namedInterface struct {\n\tname       *ast.Ident\n\tit         *ast.InterfaceType\n\ttypeParams []*ast.Field\n}\n\n// Create an iterator over all interfaces in file.\nfunc iterInterfaces(file *ast.File) <-chan *namedInterface {\n\tch := make(chan *namedInterface)\n\tgo func() {\n\t\tfor _, decl := range file.Decls {\n\t\t\tgd, ok := decl.(*ast.GenDecl)\n\t\t\tif !ok || gd.Tok != token.TYPE {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor _, spec := range gd.Specs {\n\t\t\t\tts, ok := spec.(*ast.TypeSpec)\n\t\t\t\tif !ok {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tit, ok := ts.Type.(*ast.InterfaceType)\n\t\t\t\tif !ok {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tch <- &namedInterface{ts.Name, it, getTypeSpecTypeParams(ts)}\n\t\t\t}\n\t\t}\n\t\tclose(ch)\n\t}()\n\treturn ch\n}\n\n// isVariadic returns whether the function is variadic.\nfunc isVariadic(f *ast.FuncType) bool {\n\tnargs := len(f.Params.List)\n\tif nargs == 0 {\n\t\treturn false\n\t}\n\t_, ok := f.Params.List[nargs-1].Type.(*ast.Ellipsis)\n\treturn ok\n}\n\n// packageNameOfDir get package import path via dir\nfunc packageNameOfDir(srcDir string) (string, error) {\n\tfiles, err := ioutil.ReadDir(srcDir)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tvar goFilePath string\n\tfor _, file := range files {\n\t\tif !file.IsDir() && strings.HasSuffix(file.Name(), \".go\") {\n\t\t\tgoFilePath = file.Name()\n\t\t\tbreak\n\t\t}\n\t}\n\tif goFilePath == \"\" {\n\t\treturn \"\", fmt.Errorf(\"go source file not found %s\", srcDir)\n\t}\n\n\tpackageImport, err := parsePackageImport(srcDir)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn packageImport, nil\n}\n\nvar errOutsideGoPath = errors.New(\"source directory is outside GOPATH\")\n"
  },
  {
    "path": "mockgen/parse_test.go",
    "content": "package main\n\nimport (\n\t\"go/parser\"\n\t\"go/token\"\n\t\"testing\"\n)\n\nfunc TestFileParser_ParseFile(t *testing.T) {\n\tfs := token.NewFileSet()\n\tfile, err := parser.ParseFile(fs, \"internal/tests/custom_package_name/greeter/greeter.go\", nil, 0)\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n\n\tp := fileParser{\n\t\tfileSet:            fs,\n\t\timports:            make(map[string]importedPackage),\n\t\timportedInterfaces: newInterfaceCache(),\n\t}\n\n\tpkg, err := p.parseFile(\"\", file)\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n\n\tcheckGreeterImports(t, p.imports)\n\n\texpectedName := \"greeter\"\n\tif pkg.Name != expectedName {\n\t\tt.Fatalf(\"Expected name to be %v but got %v\", expectedName, pkg.Name)\n\t}\n\n\texpectedInterfaceName := \"InputMaker\"\n\tif pkg.Interfaces[0].Name != expectedInterfaceName {\n\t\tt.Fatalf(\"Expected interface name to be %v but got %v\", expectedInterfaceName, pkg.Interfaces[0].Name)\n\t}\n}\n\nfunc TestFileParser_ParsePackage(t *testing.T) {\n\tfs := token.NewFileSet()\n\t_, err := parser.ParseFile(fs, \"internal/tests/custom_package_name/greeter/greeter.go\", nil, 0)\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n\n\tp := fileParser{\n\t\tfileSet:            fs,\n\t\timports:            make(map[string]importedPackage),\n\t\timportedInterfaces: newInterfaceCache(),\n\t}\n\n\tnewP, err := p.parsePackage(\"github.com/golang/mock/mockgen/internal/tests/custom_package_name/greeter\")\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n\n\tcheckGreeterImports(t, newP.imports)\n}\n\nfunc TestImportsOfFile(t *testing.T) {\n\tfs := token.NewFileSet()\n\tfile, err := parser.ParseFile(fs, \"internal/tests/custom_package_name/greeter/greeter.go\", nil, 0)\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n\n\timports, _ := importsOfFile(file)\n\tcheckGreeterImports(t, imports)\n}\n\nfunc checkGreeterImports(t *testing.T, imports map[string]importedPackage) {\n\t// check that imports have stdlib package \"fmt\"\n\tif fmtPackage, ok := imports[\"fmt\"]; !ok {\n\t\tt.Errorf(\"Expected imports to have key \\\"fmt\\\"\")\n\t} else {\n\t\texpectedFmtPackage := \"fmt\"\n\t\tif fmtPackage.Path() != expectedFmtPackage {\n\t\t\tt.Errorf(\"Expected fmt key to have value %s but got %s\", expectedFmtPackage, fmtPackage.Path())\n\t\t}\n\t}\n\n\t// check that imports have package named \"validator\"\n\tif validatorPackage, ok := imports[\"validator\"]; !ok {\n\t\tt.Errorf(\"Expected imports to have key \\\"fmt\\\"\")\n\t} else {\n\t\texpectedValidatorPackage := \"github.com/golang/mock/mockgen/internal/tests/custom_package_name/validator\"\n\t\tif validatorPackage.Path() != expectedValidatorPackage {\n\t\t\tt.Errorf(\"Expected validator key to have value %s but got %s\", expectedValidatorPackage, validatorPackage.Path())\n\t\t}\n\t}\n\n\t// check that imports have package named \"client\"\n\tif clientPackage, ok := imports[\"client\"]; !ok {\n\t\tt.Errorf(\"Expected imports to have key \\\"client\\\"\")\n\t} else {\n\t\texpectedClientPackage := \"github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1\"\n\t\tif clientPackage.Path() != expectedClientPackage {\n\t\t\tt.Errorf(\"Expected client key to have value %s but got %s\", expectedClientPackage, clientPackage.Path())\n\t\t}\n\t}\n\n\t// check that imports don't have package named \"v1\"\n\tif _, ok := imports[\"v1\"]; ok {\n\t\tt.Errorf(\"Expected import not to have key \\\"v1\\\"\")\n\t}\n}\n\nfunc Benchmark_parseFile(b *testing.B) {\n\tsource := \"internal/tests/performance/big_interface/big_interface.go\"\n\tfor n := 0; n < b.N; n++ {\n\t\tsourceMode(source)\n\t}\n}\n\nfunc TestParseArrayWithConstLength(t *testing.T) {\n\tfs := token.NewFileSet()\n\tsrcDir := \"internal/tests/const_array_length/input.go\"\n\n\tfile, err := parser.ParseFile(fs, srcDir, nil, 0)\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n\n\tp := fileParser{\n\t\tfileSet:            fs,\n\t\timports:            make(map[string]importedPackage),\n\t\timportedInterfaces: newInterfaceCache(),\n\t\tauxInterfaces:      newInterfaceCache(),\n\t\tsrcDir:             srcDir,\n\t}\n\n\tpkg, err := p.parseFile(\"\", file)\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n\n\texpects := []string{\"[2]int\", \"[2]int\", \"[127]int\", \"[3]int\", \"[3]int\", \"[7]int\"}\n\tfor i, e := range expects {\n\t\tgot := pkg.Interfaces[0].Methods[i].Out[0].Type.String(nil, \"\")\n\t\tif got != e {\n\t\t\tt.Fatalf(\"got %v; expected %v\", got, e)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "mockgen/reflect.go",
    "content": "// Copyright 2012 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\n// This file contains the model construction by reflection.\n\nimport (\n\t\"bytes\"\n\t\"encoding/gob\"\n\t\"flag\"\n\t\"fmt\"\n\t\"go/build\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"os\"\n\t\"os/exec\"\n\t\"path/filepath\"\n\t\"runtime\"\n\t\"strings\"\n\t\"text/template\"\n\n\t\"github.com/golang/mock/mockgen/model\"\n)\n\nvar (\n\tprogOnly   = flag.Bool(\"prog_only\", false, \"(reflect mode) Only generate the reflection program; write it to stdout and exit.\")\n\texecOnly   = flag.String(\"exec_only\", \"\", \"(reflect mode) If set, execute this reflection program.\")\n\tbuildFlags = flag.String(\"build_flags\", \"\", \"(reflect mode) Additional flags for go build.\")\n)\n\n// reflectMode generates mocks via reflection on an interface.\nfunc reflectMode(importPath string, symbols []string) (*model.Package, error) {\n\tif *execOnly != \"\" {\n\t\treturn run(*execOnly)\n\t}\n\n\tprogram, err := writeProgram(importPath, symbols)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif *progOnly {\n\t\tif _, err := os.Stdout.Write(program); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tos.Exit(0)\n\t}\n\n\twd, _ := os.Getwd()\n\n\t// Try to run the reflection program  in the current working directory.\n\tif p, err := runInDir(program, wd); err == nil {\n\t\treturn p, nil\n\t}\n\n\t// Try to run the program in the same directory as the input package.\n\tif p, err := build.Import(importPath, wd, build.FindOnly); err == nil {\n\t\tdir := p.Dir\n\t\tif p, err := runInDir(program, dir); err == nil {\n\t\t\treturn p, nil\n\t\t}\n\t}\n\n\t// Try to run it in a standard temp directory.\n\treturn runInDir(program, \"\")\n}\n\nfunc writeProgram(importPath string, symbols []string) ([]byte, error) {\n\tvar program bytes.Buffer\n\tdata := reflectData{\n\t\tImportPath: importPath,\n\t\tSymbols:    symbols,\n\t}\n\tif err := reflectProgram.Execute(&program, &data); err != nil {\n\t\treturn nil, err\n\t}\n\treturn program.Bytes(), nil\n}\n\n// run the given program and parse the output as a model.Package.\nfunc run(program string) (*model.Package, error) {\n\tf, err := ioutil.TempFile(\"\", \"\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tfilename := f.Name()\n\tdefer os.Remove(filename)\n\tif err := f.Close(); err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Run the program.\n\tcmd := exec.Command(program, \"-output\", filename)\n\tcmd.Stdout = os.Stdout\n\tcmd.Stderr = os.Stderr\n\tif err := cmd.Run(); err != nil {\n\t\treturn nil, err\n\t}\n\n\tf, err = os.Open(filename)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Process output.\n\tvar pkg model.Package\n\tif err := gob.NewDecoder(f).Decode(&pkg); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif err := f.Close(); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &pkg, nil\n}\n\n// runInDir writes the given program into the given dir, runs it there, and\n// parses the output as a model.Package.\nfunc runInDir(program []byte, dir string) (*model.Package, error) {\n\t// We use TempDir instead of TempFile so we can control the filename.\n\ttmpDir, err := ioutil.TempDir(dir, \"gomock_reflect_\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer func() {\n\t\tif err := os.RemoveAll(tmpDir); err != nil {\n\t\t\tlog.Printf(\"failed to remove temp directory: %s\", err)\n\t\t}\n\t}()\n\tconst progSource = \"prog.go\"\n\tvar progBinary = \"prog.bin\"\n\tif runtime.GOOS == \"windows\" {\n\t\t// Windows won't execute a program unless it has a \".exe\" suffix.\n\t\tprogBinary += \".exe\"\n\t}\n\n\tif err := ioutil.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil {\n\t\treturn nil, err\n\t}\n\n\tcmdArgs := []string{}\n\tcmdArgs = append(cmdArgs, \"build\")\n\tif *buildFlags != \"\" {\n\t\tcmdArgs = append(cmdArgs, strings.Split(*buildFlags, \" \")...)\n\t}\n\tcmdArgs = append(cmdArgs, \"-o\", progBinary, progSource)\n\n\t// Build the program.\n\tbuf := bytes.NewBuffer(nil)\n\tcmd := exec.Command(\"go\", cmdArgs...)\n\tcmd.Dir = tmpDir\n\tcmd.Stdout = os.Stdout\n\tcmd.Stderr = io.MultiWriter(os.Stderr, buf)\n\tif err := cmd.Run(); err != nil {\n\t\tsErr := buf.String()\n\t\tif strings.Contains(sErr, `cannot find package \".\"`) &&\n\t\t\tstrings.Contains(sErr, \"github.com/golang/mock/mockgen/model\") {\n\t\t\tfmt.Fprint(os.Stderr, \"Please reference the steps in the README to fix this error:\\n\\thttps://github.com/golang/mock#reflect-vendoring-error.\\n\")\n\t\t\treturn nil, err\n\t\t}\n\t\treturn nil, err\n\t}\n\n\treturn run(filepath.Join(tmpDir, progBinary))\n}\n\ntype reflectData struct {\n\tImportPath string\n\tSymbols    []string\n}\n\n// This program reflects on an interface value, and prints the\n// gob encoding of a model.Package to standard output.\n// JSON doesn't work because of the model.Type interface.\nvar reflectProgram = template.Must(template.New(\"program\").Parse(`\npackage main\n\nimport (\n\t\"encoding/gob\"\n\t\"flag\"\n\t\"fmt\"\n\t\"os\"\n\t\"path\"\n\t\"reflect\"\n\n\t\"github.com/golang/mock/mockgen/model\"\n\n\tpkg_ {{printf \"%q\" .ImportPath}}\n)\n\nvar output = flag.String(\"output\", \"\", \"The output file name, or empty to use stdout.\")\n\nfunc main() {\n\tflag.Parse()\n\n\tits := []struct{\n\t\tsym string\n\t\ttyp reflect.Type\n\t}{\n\t\t{{range .Symbols}}\n\t\t{ {{printf \"%q\" .}}, reflect.TypeOf((*pkg_.{{.}})(nil)).Elem()},\n\t\t{{end}}\n\t}\n\tpkg := &model.Package{\n\t\t// NOTE: This behaves contrary to documented behaviour if the\n\t\t// package name is not the final component of the import path.\n\t\t// The reflect package doesn't expose the package name, though.\n\t\tName: path.Base({{printf \"%q\" .ImportPath}}),\n\t}\n\n\tfor _, it := range its {\n\t\tintf, err := model.InterfaceFromInterfaceType(it.typ)\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(os.Stderr, \"Reflection: %v\\n\", err)\n\t\t\tos.Exit(1)\n\t\t}\n\t\tintf.Name = it.sym\n\t\tpkg.Interfaces = append(pkg.Interfaces, intf)\n\t}\n\n\toutfile := os.Stdout\n\tif len(*output) != 0 {\n\t\tvar err error\n\t\toutfile, err = os.Create(*output)\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(os.Stderr, \"failed to open output file %q\", *output)\n\t\t}\n\t\tdefer func() {\n\t\t\tif err := outfile.Close(); err != nil {\n\t\t\t\tfmt.Fprintf(os.Stderr, \"failed to close output file %q\", *output)\n\t\t\t\tos.Exit(1)\n\t\t\t}\n\t\t}()\n\t}\n\n\tif err := gob.NewEncoder(outfile).Encode(pkg); err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"gob encode: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n}\n`))\n"
  },
  {
    "path": "mockgen/version.go",
    "content": "// Copyright 2022 Google LLC\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"runtime/debug\"\n)\n\nfunc printModuleVersion() {\n\tif bi, exists := debug.ReadBuildInfo(); exists {\n\t\tfmt.Println(bi.Main.Version)\n\t} else {\n\t\tlog.Printf(\"No version information found. Make sure to use \" +\n\t\t\t\"GO111MODULE=on when running 'go get' in order to use specific \" +\n\t\t\t\"version of the binary.\")\n\t}\n}\n"
  },
  {
    "path": "sample/README.md",
    "content": "# Samples\n\nThis directory contains an example of a package containing a non-trivial\ninterface that can be mocked with GoMock. The interesting files are:\n\n* `user.go`: Source code for the sample package, containing interfaces to be\n    mocked. This file depends on the packages named imp[1-4] for various things.\n\n* `user_test.go`: A test for the sample package, in which mocks of the\n    interfaces from `user.go` are used. This demonstrates how to create mock\n    objects, set up expectations, and so on.\n\n* `mock_user_test.go`: The generated mock code. See ../gomock/matchers.go\n    for the `go:generate` command used to generate it.\n\nTo run the test,\n\n```bash\ngo test github.com/golang/mock/sample\n```\n"
  },
  {
    "path": "sample/concurrent/concurrent.go",
    "content": "// Package concurrent demonstrates how to use gomock with goroutines.\npackage concurrent\n\n//go:generate mockgen -destination mock/concurrent_mock.go github.com/golang/mock/sample/concurrent Math\n\ntype Math interface {\n\tSum(a, b int) int\n}\n"
  },
  {
    "path": "sample/concurrent/concurrent_test.go",
    "content": "package concurrent\n\nimport (\n\t\"testing\"\n\n\t\"context\"\n\n\t\"github.com/golang/mock/gomock\"\n\n\tmock \"github.com/golang/mock/sample/concurrent/mock\"\n)\n\nfunc call(ctx context.Context, m Math) (int, error) {\n\tresult := make(chan int)\n\tgo func() {\n\t\tresult <- m.Sum(1, 2)\n\t\tclose(result)\n\t}()\n\tselect {\n\tcase r := <-result:\n\t\treturn r, nil\n\tcase <-ctx.Done():\n\t\treturn 0, ctx.Err()\n\t}\n}\n\n// TestConcurrentFails is expected to fail (and is disabled). It\n// demonstrates how to use gomock.WithContext to interrupt the test\n// from a different goroutine.\nfunc TestConcurrentFails(t *testing.T) {\n\tt.Skip(\"Test is expected to fail, remove skip to trying running yourself.\")\n\tctrl, ctx := gomock.WithContext(context.Background(), t)\n\tdefer ctrl.Finish()\n\tm := mock.NewMockMath(ctrl)\n\tif _, err := call(ctx, m); err != nil {\n\t\tt.Error(\"call failed:\", err)\n\t}\n}\n\nfunc TestConcurrentWorks(t *testing.T) {\n\tctrl, ctx := gomock.WithContext(context.Background(), t)\n\tdefer ctrl.Finish()\n\tm := mock.NewMockMath(ctrl)\n\tm.EXPECT().Sum(1, 2).Return(3)\n\tif _, err := call(ctx, m); err != nil {\n\t\tt.Error(\"call failed:\", err)\n\t}\n}\n"
  },
  {
    "path": "sample/concurrent/mock/concurrent_mock.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: github.com/golang/mock/sample/concurrent (interfaces: Math)\n\n// Package mock_concurrent is a generated GoMock package.\npackage mock_concurrent\n\nimport (\n\treflect \"reflect\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n)\n\n// MockMath is a mock of Math interface.\ntype MockMath struct {\n\tctrl     *gomock.Controller\n\trecorder *MockMathMockRecorder\n}\n\n// MockMathMockRecorder is the mock recorder for MockMath.\ntype MockMathMockRecorder struct {\n\tmock *MockMath\n}\n\n// NewMockMath creates a new mock instance.\nfunc NewMockMath(ctrl *gomock.Controller) *MockMath {\n\tmock := &MockMath{ctrl: ctrl}\n\tmock.recorder = &MockMathMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockMath) EXPECT() *MockMathMockRecorder {\n\treturn m.recorder\n}\n\n// Sum mocks base method.\nfunc (m *MockMath) Sum(arg0, arg1 int) int {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Sum\", arg0, arg1)\n\tret0, _ := ret[0].(int)\n\treturn ret0\n}\n\n// Sum indicates an expected call of Sum.\nfunc (mr *MockMathMockRecorder) Sum(arg0, arg1 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Sum\", reflect.TypeOf((*MockMath)(nil).Sum), arg0, arg1)\n}\n"
  },
  {
    "path": "sample/imp1/imp1.go",
    "content": "package imp1\n\nimport \"bufio\"\n\ntype Imp1 struct{}\n\ntype ImpT int\n\ntype ForeignEmbedded interface {\n\t// The return value here also makes sure that\n\t// the generated mock picks up the \"bufio\" import.\n\tForeignEmbeddedMethod() *bufio.Reader\n\n\t// This method uses a type in this package,\n\t// which should be qualified when this interface is embedded.\n\tImplicitPackage(s string, t ImpT, st []ImpT, pt *ImpT, ct chan ImpT)\n}\n"
  },
  {
    "path": "sample/imp2/imp2.go",
    "content": "package imp2\n\ntype Imp2 struct{}\n"
  },
  {
    "path": "sample/imp3/imp3.go",
    "content": "package imp3\n\ntype Imp3 struct{}\n"
  },
  {
    "path": "sample/imp4/imp4.go",
    "content": "package imp_four\n\ntype Imp4 struct{}\n"
  },
  {
    "path": "sample/mock_user_test.go",
    "content": "// Code generated by MockGen. DO NOT EDIT.\n// Source: github.com/golang/mock/sample (interfaces: Index,Embed,Embedded)\n\n// Package user_test is a generated GoMock package.\npackage user_test\n\nimport (\n\tbufio \"bufio\"\n\tbytes \"bytes\"\n\thash \"hash\"\n\ttemplate \"html/template\"\n\tio \"io\"\n\thttp \"net/http\"\n\treflect \"reflect\"\n\ttemplate0 \"text/template\"\n\n\tgomock \"github.com/golang/mock/gomock\"\n\timp1 \"github.com/golang/mock/sample/imp1\"\n\timp2 \"github.com/golang/mock/sample/imp2\"\n\timp3 \"github.com/golang/mock/sample/imp3\"\n\timp_four \"github.com/golang/mock/sample/imp4\"\n)\n\n// MockIndex is a mock of Index interface.\ntype MockIndex struct {\n\tctrl     *gomock.Controller\n\trecorder *MockIndexMockRecorder\n}\n\n// MockIndexMockRecorder is the mock recorder for MockIndex.\ntype MockIndexMockRecorder struct {\n\tmock *MockIndex\n}\n\n// NewMockIndex creates a new mock instance.\nfunc NewMockIndex(ctrl *gomock.Controller) *MockIndex {\n\tmock := &MockIndex{ctrl: ctrl}\n\tmock.recorder = &MockIndexMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockIndex) EXPECT() *MockIndexMockRecorder {\n\treturn m.recorder\n}\n\n// Anon mocks base method.\nfunc (m *MockIndex) Anon(arg0 string) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Anon\", arg0)\n}\n\n// Anon indicates an expected call of Anon.\nfunc (mr *MockIndexMockRecorder) Anon(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Anon\", reflect.TypeOf((*MockIndex)(nil).Anon), arg0)\n}\n\n// Chan mocks base method.\nfunc (m *MockIndex) Chan(arg0 chan int, arg1 chan<- hash.Hash) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Chan\", arg0, arg1)\n}\n\n// Chan indicates an expected call of Chan.\nfunc (mr *MockIndexMockRecorder) Chan(arg0, arg1 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Chan\", reflect.TypeOf((*MockIndex)(nil).Chan), arg0, arg1)\n}\n\n// ConcreteRet mocks base method.\nfunc (m *MockIndex) ConcreteRet() chan<- bool {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"ConcreteRet\")\n\tret0, _ := ret[0].(chan<- bool)\n\treturn ret0\n}\n\n// ConcreteRet indicates an expected call of ConcreteRet.\nfunc (mr *MockIndexMockRecorder) ConcreteRet() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"ConcreteRet\", reflect.TypeOf((*MockIndex)(nil).ConcreteRet))\n}\n\n// Ellip mocks base method.\nfunc (m *MockIndex) Ellip(arg0 string, arg1 ...interface{}) {\n\tm.ctrl.T.Helper()\n\tvarargs := []interface{}{arg0}\n\tfor _, a := range arg1 {\n\t\tvarargs = append(varargs, a)\n\t}\n\tm.ctrl.Call(m, \"Ellip\", varargs...)\n}\n\n// Ellip indicates an expected call of Ellip.\nfunc (mr *MockIndexMockRecorder) Ellip(arg0 interface{}, arg1 ...interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\tvarargs := append([]interface{}{arg0}, arg1...)\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Ellip\", reflect.TypeOf((*MockIndex)(nil).Ellip), varargs...)\n}\n\n// EllipOnly mocks base method.\nfunc (m *MockIndex) EllipOnly(arg0 ...string) {\n\tm.ctrl.T.Helper()\n\tvarargs := []interface{}{}\n\tfor _, a := range arg0 {\n\t\tvarargs = append(varargs, a)\n\t}\n\tm.ctrl.Call(m, \"EllipOnly\", varargs...)\n}\n\n// EllipOnly indicates an expected call of EllipOnly.\nfunc (mr *MockIndexMockRecorder) EllipOnly(arg0 ...interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"EllipOnly\", reflect.TypeOf((*MockIndex)(nil).EllipOnly), arg0...)\n}\n\n// ForeignFour mocks base method.\nfunc (m *MockIndex) ForeignFour(arg0 imp_four.Imp4) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"ForeignFour\", arg0)\n}\n\n// ForeignFour indicates an expected call of ForeignFour.\nfunc (mr *MockIndexMockRecorder) ForeignFour(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"ForeignFour\", reflect.TypeOf((*MockIndex)(nil).ForeignFour), arg0)\n}\n\n// ForeignOne mocks base method.\nfunc (m *MockIndex) ForeignOne(arg0 imp1.Imp1) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"ForeignOne\", arg0)\n}\n\n// ForeignOne indicates an expected call of ForeignOne.\nfunc (mr *MockIndexMockRecorder) ForeignOne(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"ForeignOne\", reflect.TypeOf((*MockIndex)(nil).ForeignOne), arg0)\n}\n\n// ForeignThree mocks base method.\nfunc (m *MockIndex) ForeignThree(arg0 imp3.Imp3) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"ForeignThree\", arg0)\n}\n\n// ForeignThree indicates an expected call of ForeignThree.\nfunc (mr *MockIndexMockRecorder) ForeignThree(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"ForeignThree\", reflect.TypeOf((*MockIndex)(nil).ForeignThree), arg0)\n}\n\n// ForeignTwo mocks base method.\nfunc (m *MockIndex) ForeignTwo(arg0 imp2.Imp2) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"ForeignTwo\", arg0)\n}\n\n// ForeignTwo indicates an expected call of ForeignTwo.\nfunc (mr *MockIndexMockRecorder) ForeignTwo(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"ForeignTwo\", reflect.TypeOf((*MockIndex)(nil).ForeignTwo), arg0)\n}\n\n// Func mocks base method.\nfunc (m *MockIndex) Func(arg0 func(http.Request) (int, bool)) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Func\", arg0)\n}\n\n// Func indicates an expected call of Func.\nfunc (mr *MockIndexMockRecorder) Func(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Func\", reflect.TypeOf((*MockIndex)(nil).Func), arg0)\n}\n\n// Get mocks base method.\nfunc (m *MockIndex) Get(arg0 string) interface{} {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Get\", arg0)\n\tret0, _ := ret[0].(interface{})\n\treturn ret0\n}\n\n// Get indicates an expected call of Get.\nfunc (mr *MockIndexMockRecorder) Get(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Get\", reflect.TypeOf((*MockIndex)(nil).Get), arg0)\n}\n\n// GetTwo mocks base method.\nfunc (m *MockIndex) GetTwo(arg0, arg1 string) (interface{}, interface{}) {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"GetTwo\", arg0, arg1)\n\tret0, _ := ret[0].(interface{})\n\tret1, _ := ret[1].(interface{})\n\treturn ret0, ret1\n}\n\n// GetTwo indicates an expected call of GetTwo.\nfunc (mr *MockIndexMockRecorder) GetTwo(arg0, arg1 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"GetTwo\", reflect.TypeOf((*MockIndex)(nil).GetTwo), arg0, arg1)\n}\n\n// Map mocks base method.\nfunc (m *MockIndex) Map(arg0 map[int]hash.Hash) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Map\", arg0)\n}\n\n// Map indicates an expected call of Map.\nfunc (mr *MockIndexMockRecorder) Map(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Map\", reflect.TypeOf((*MockIndex)(nil).Map), arg0)\n}\n\n// NillableRet mocks base method.\nfunc (m *MockIndex) NillableRet() error {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"NillableRet\")\n\tret0, _ := ret[0].(error)\n\treturn ret0\n}\n\n// NillableRet indicates an expected call of NillableRet.\nfunc (mr *MockIndexMockRecorder) NillableRet() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"NillableRet\", reflect.TypeOf((*MockIndex)(nil).NillableRet))\n}\n\n// Other mocks base method.\nfunc (m *MockIndex) Other() hash.Hash {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Other\")\n\tret0, _ := ret[0].(hash.Hash)\n\treturn ret0\n}\n\n// Other indicates an expected call of Other.\nfunc (mr *MockIndexMockRecorder) Other() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Other\", reflect.TypeOf((*MockIndex)(nil).Other))\n}\n\n// Ptr mocks base method.\nfunc (m *MockIndex) Ptr(arg0 *int) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Ptr\", arg0)\n}\n\n// Ptr indicates an expected call of Ptr.\nfunc (mr *MockIndexMockRecorder) Ptr(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Ptr\", reflect.TypeOf((*MockIndex)(nil).Ptr), arg0)\n}\n\n// Put mocks base method.\nfunc (m *MockIndex) Put(arg0 string, arg1 interface{}) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Put\", arg0, arg1)\n}\n\n// Put indicates an expected call of Put.\nfunc (mr *MockIndexMockRecorder) Put(arg0, arg1 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Put\", reflect.TypeOf((*MockIndex)(nil).Put), arg0, arg1)\n}\n\n// Slice mocks base method.\nfunc (m *MockIndex) Slice(arg0 []int, arg1 []byte) [3]int {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"Slice\", arg0, arg1)\n\tret0, _ := ret[0].([3]int)\n\treturn ret0\n}\n\n// Slice indicates an expected call of Slice.\nfunc (mr *MockIndexMockRecorder) Slice(arg0, arg1 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Slice\", reflect.TypeOf((*MockIndex)(nil).Slice), arg0, arg1)\n}\n\n// Struct mocks base method.\nfunc (m *MockIndex) Struct(arg0 struct{}) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Struct\", arg0)\n}\n\n// Struct indicates an expected call of Struct.\nfunc (mr *MockIndexMockRecorder) Struct(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Struct\", reflect.TypeOf((*MockIndex)(nil).Struct), arg0)\n}\n\n// StructChan mocks base method.\nfunc (m *MockIndex) StructChan(arg0 chan struct{}) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"StructChan\", arg0)\n}\n\n// StructChan indicates an expected call of StructChan.\nfunc (mr *MockIndexMockRecorder) StructChan(arg0 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"StructChan\", reflect.TypeOf((*MockIndex)(nil).StructChan), arg0)\n}\n\n// Summary mocks base method.\nfunc (m *MockIndex) Summary(arg0 *bytes.Buffer, arg1 io.Writer) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Summary\", arg0, arg1)\n}\n\n// Summary indicates an expected call of Summary.\nfunc (mr *MockIndexMockRecorder) Summary(arg0, arg1 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Summary\", reflect.TypeOf((*MockIndex)(nil).Summary), arg0, arg1)\n}\n\n// Templates mocks base method.\nfunc (m *MockIndex) Templates(arg0 template.CSS, arg1 template0.FuncMap) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"Templates\", arg0, arg1)\n}\n\n// Templates indicates an expected call of Templates.\nfunc (mr *MockIndexMockRecorder) Templates(arg0, arg1 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"Templates\", reflect.TypeOf((*MockIndex)(nil).Templates), arg0, arg1)\n}\n\n// MockEmbed is a mock of Embed interface.\ntype MockEmbed struct {\n\tctrl     *gomock.Controller\n\trecorder *MockEmbedMockRecorder\n}\n\n// MockEmbedMockRecorder is the mock recorder for MockEmbed.\ntype MockEmbedMockRecorder struct {\n\tmock *MockEmbed\n}\n\n// NewMockEmbed creates a new mock instance.\nfunc NewMockEmbed(ctrl *gomock.Controller) *MockEmbed {\n\tmock := &MockEmbed{ctrl: ctrl}\n\tmock.recorder = &MockEmbedMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockEmbed) EXPECT() *MockEmbedMockRecorder {\n\treturn m.recorder\n}\n\n// EmbeddedMethod mocks base method.\nfunc (m *MockEmbed) EmbeddedMethod() {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"EmbeddedMethod\")\n}\n\n// EmbeddedMethod indicates an expected call of EmbeddedMethod.\nfunc (mr *MockEmbedMockRecorder) EmbeddedMethod() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"EmbeddedMethod\", reflect.TypeOf((*MockEmbed)(nil).EmbeddedMethod))\n}\n\n// ForeignEmbeddedMethod mocks base method.\nfunc (m *MockEmbed) ForeignEmbeddedMethod() *bufio.Reader {\n\tm.ctrl.T.Helper()\n\tret := m.ctrl.Call(m, \"ForeignEmbeddedMethod\")\n\tret0, _ := ret[0].(*bufio.Reader)\n\treturn ret0\n}\n\n// ForeignEmbeddedMethod indicates an expected call of ForeignEmbeddedMethod.\nfunc (mr *MockEmbedMockRecorder) ForeignEmbeddedMethod() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"ForeignEmbeddedMethod\", reflect.TypeOf((*MockEmbed)(nil).ForeignEmbeddedMethod))\n}\n\n// ImplicitPackage mocks base method.\nfunc (m *MockEmbed) ImplicitPackage(arg0 string, arg1 imp1.ImpT, arg2 []imp1.ImpT, arg3 *imp1.ImpT, arg4 chan imp1.ImpT) {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"ImplicitPackage\", arg0, arg1, arg2, arg3, arg4)\n}\n\n// ImplicitPackage indicates an expected call of ImplicitPackage.\nfunc (mr *MockEmbedMockRecorder) ImplicitPackage(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"ImplicitPackage\", reflect.TypeOf((*MockEmbed)(nil).ImplicitPackage), arg0, arg1, arg2, arg3, arg4)\n}\n\n// RegularMethod mocks base method.\nfunc (m *MockEmbed) RegularMethod() {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"RegularMethod\")\n}\n\n// RegularMethod indicates an expected call of RegularMethod.\nfunc (mr *MockEmbedMockRecorder) RegularMethod() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"RegularMethod\", reflect.TypeOf((*MockEmbed)(nil).RegularMethod))\n}\n\n// MockEmbedded is a mock of Embedded interface.\ntype MockEmbedded struct {\n\tctrl     *gomock.Controller\n\trecorder *MockEmbeddedMockRecorder\n}\n\n// MockEmbeddedMockRecorder is the mock recorder for MockEmbedded.\ntype MockEmbeddedMockRecorder struct {\n\tmock *MockEmbedded\n}\n\n// NewMockEmbedded creates a new mock instance.\nfunc NewMockEmbedded(ctrl *gomock.Controller) *MockEmbedded {\n\tmock := &MockEmbedded{ctrl: ctrl}\n\tmock.recorder = &MockEmbeddedMockRecorder{mock}\n\treturn mock\n}\n\n// EXPECT returns an object that allows the caller to indicate expected use.\nfunc (m *MockEmbedded) EXPECT() *MockEmbeddedMockRecorder {\n\treturn m.recorder\n}\n\n// EmbeddedMethod mocks base method.\nfunc (m *MockEmbedded) EmbeddedMethod() {\n\tm.ctrl.T.Helper()\n\tm.ctrl.Call(m, \"EmbeddedMethod\")\n}\n\n// EmbeddedMethod indicates an expected call of EmbeddedMethod.\nfunc (mr *MockEmbeddedMockRecorder) EmbeddedMethod() *gomock.Call {\n\tmr.mock.ctrl.T.Helper()\n\treturn mr.mock.ctrl.RecordCallWithMethodType(mr.mock, \"EmbeddedMethod\", reflect.TypeOf((*MockEmbedded)(nil).EmbeddedMethod))\n}\n"
  },
  {
    "path": "sample/user.go",
    "content": "// Package user is an example package with an interface.\npackage user\n\n//go:generate mockgen -destination mock_user_test.go -package user_test github.com/golang/mock/sample Index,Embed,Embedded\n\n// Random bunch of imports to test mockgen.\nimport (\n\t\"io\"\n\n\tbtz \"bytes\"\n\t\"hash\"\n\t\"log\"\n\t\"net\"\n\t\"net/http\"\n\n\t// Two imports with the same base name.\n\tt1 \"html/template\"\n\n\tt2 \"text/template\"\n\n\t\"github.com/golang/mock/sample/imp1\"\n\n\t// Dependencies outside the standard library.\n\n\trenamed2 \"github.com/golang/mock/sample/imp2\"\n\n\t. \"github.com/golang/mock/sample/imp3\"\n\n\timp_four \"github.com/golang/mock/sample/imp4\"\n)\n\n// calls itself \"imp_four\"\n\n// A bizarre interface to test corner cases in mockgen.\n// This would normally be in its own file or package,\n// separate from the user of it (e.g. io.Reader).\ntype Index interface {\n\tGet(key string) interface{}\n\tGetTwo(key1, key2 string) (v1, v2 interface{})\n\tPut(key string, value interface{})\n\n\t// Check that imports are handled correctly.\n\tSummary(buf *btz.Buffer, w io.Writer)\n\tOther() hash.Hash\n\tTemplates(a t1.CSS, b t2.FuncMap)\n\n\t// A method with an anonymous argument.\n\tAnon(string)\n\n\t// Methods using foreign types outside the standard library.\n\tForeignOne(imp1.Imp1)\n\tForeignTwo(renamed2.Imp2)\n\tForeignThree(Imp3)\n\tForeignFour(imp_four.Imp4)\n\n\t// A method that returns a nillable type.\n\tNillableRet() error\n\t// A method that returns a non-interface type.\n\tConcreteRet() chan<- bool\n\n\t// Methods with an ellipsis argument.\n\tEllip(fmt string, args ...interface{})\n\tEllipOnly(...string)\n\n\t// A method with a pointer argument that we will set.\n\tPtr(arg *int)\n\n\t// A method with a slice argument and an array return.\n\tSlice(a []int, b []byte) [3]int\n\n\t// A method with channel arguments.\n\tChan(a chan int, b chan<- hash.Hash)\n\n\t// A method with a function argument.\n\tFunc(f func(http.Request) (int, bool))\n\n\t// A method with a map argument.\n\tMap(a map[int]hash.Hash)\n\n\t// Methods with an unnamed empty struct argument.\n\tStruct(a struct{})          // not so likely\n\tStructChan(a chan struct{}) // a bit more common\n}\n\n// An interface with an embedded interface.\ntype Embed interface {\n\tRegularMethod()\n\tEmbedded\n\timp1.ForeignEmbedded\n}\n\ntype Embedded interface {\n\tEmbeddedMethod()\n}\n\n// some random use of another package that isn't needed by the interface.\nvar _ net.Addr\n\n// A function that we will test that uses the above interface.\n// It takes a list of keys and values, and puts them in the index.\nfunc Remember(index Index, keys []string, values []interface{}) {\n\tfor i, k := range keys {\n\t\tindex.Put(k, values[i])\n\t}\n\terr := index.NillableRet()\n\tif err != nil {\n\t\tlog.Fatalf(\"Woah! %v\", err)\n\t}\n\tif len(keys) > 0 && keys[0] == \"a\" {\n\t\tindex.Ellip(\"%d\", 0, 1, 1, 2, 3)\n\t\tindex.Ellip(\"%d\", 1, 3, 6, 10, 15)\n\t\tindex.EllipOnly(\"arg\")\n\t}\n}\n\nfunc GrabPointer(index Index) int {\n\tvar a int\n\tindex.Ptr(&a)\n\treturn a\n}\n"
  },
  {
    "path": "sample/user_test.go",
    "content": "// A test that uses a mock.\npackage user_test\n\nimport (\n\t\"testing\"\n\n\t\"github.com/golang/mock/gomock\"\n\tuser \"github.com/golang/mock/sample\"\n\t\"github.com/golang/mock/sample/imp1\"\n)\n\nfunc TestRemember(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\tmockIndex := NewMockIndex(ctrl)\n\tmockIndex.EXPECT().Put(\"a\", 1)            // literals work\n\tmockIndex.EXPECT().Put(\"b\", gomock.Eq(2)) // matchers work too\n\n\t// NillableRet returns error. Not declaring it should result in a nil return.\n\tmockIndex.EXPECT().NillableRet()\n\t// Calls that returns something assignable to the return type.\n\tboolc := make(chan bool)\n\t// In this case, \"chan bool\" is assignable to \"chan<- bool\".\n\tmockIndex.EXPECT().ConcreteRet().Return(boolc)\n\t// In this case, nil is assignable to \"chan<- bool\".\n\tmockIndex.EXPECT().ConcreteRet().Return(nil)\n\n\t// Should be able to place expectations on variadic methods.\n\tmockIndex.EXPECT().Ellip(\"%d\", 0, 1, 1, 2, 3) // direct args\n\ttri := []interface{}{1, 3, 6, 10, 15}\n\tmockIndex.EXPECT().Ellip(\"%d\", tri...) // args from slice\n\tmockIndex.EXPECT().EllipOnly(gomock.Eq(\"arg\"))\n\n\tuser.Remember(mockIndex, []string{\"a\", \"b\"}, []interface{}{1, 2})\n\t// Check the ConcreteRet calls.\n\tif c := mockIndex.ConcreteRet(); c != boolc {\n\t\tt.Errorf(\"ConcreteRet: got %v, want %v\", c, boolc)\n\t}\n\tif c := mockIndex.ConcreteRet(); c != nil {\n\t\tt.Errorf(\"ConcreteRet: got %v, want nil\", c)\n\t}\n\n\t// Try one with an action.\n\tcalledString := \"\"\n\tmockIndex.EXPECT().Put(gomock.Any(), gomock.Any()).Do(func(key string, _ interface{}) {\n\t\tcalledString = key\n\t})\n\tmockIndex.EXPECT().NillableRet()\n\tuser.Remember(mockIndex, []string{\"blah\"}, []interface{}{7})\n\tif calledString != \"blah\" {\n\t\tt.Fatalf(`Uh oh. %q != \"blah\"`, calledString)\n\t}\n\n\t// Use Do with a nil arg.\n\tmockIndex.EXPECT().Put(\"nil-key\", gomock.Any()).Do(func(key string, value interface{}) {\n\t\tif value != nil {\n\t\t\tt.Errorf(\"Put did not pass through nil; got %v\", value)\n\t\t}\n\t})\n\tmockIndex.EXPECT().NillableRet()\n\tuser.Remember(mockIndex, []string{\"nil-key\"}, []interface{}{nil})\n}\n\nfunc TestVariadicFunction(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\tmockIndex := NewMockIndex(ctrl)\n\tmockIndex.EXPECT().Ellip(\"%d\", 5, 6, 7, 8).Do(func(format string, nums ...int) {\n\t\tsum := 0\n\t\tfor _, value := range nums {\n\t\t\tsum += value\n\t\t}\n\t\tif sum != 26 {\n\t\t\tt.Errorf(\"Expected 26, got %d\", sum)\n\t\t}\n\t})\n\tmockIndex.EXPECT().Ellip(\"%d\", gomock.Any()).Do(func(format string, nums ...int) {\n\t\tsum := 0\n\t\tfor _, value := range nums {\n\t\t\tsum += value\n\t\t}\n\t\tif sum != 10 {\n\t\t\tt.Errorf(\"Expected 10, got %d\", sum)\n\t\t}\n\t})\n\tmockIndex.EXPECT().Ellip(\"%d\", gomock.Any()).Do(func(format string, nums ...int) {\n\t\tsum := 0\n\t\tfor _, value := range nums {\n\t\t\tsum += value\n\t\t}\n\t\tif sum != 0 {\n\t\t\tt.Errorf(\"Expected 0, got %d\", sum)\n\t\t}\n\t})\n\tmockIndex.EXPECT().Ellip(\"%d\", gomock.Any()).Do(func(format string, nums ...int) {\n\t\tsum := 0\n\t\tfor _, value := range nums {\n\t\t\tsum += value\n\t\t}\n\t\tif sum != 0 {\n\t\t\tt.Errorf(\"Expected 0, got %d\", sum)\n\t\t}\n\t})\n\tmockIndex.EXPECT().Ellip(\"%d\").Do(func(format string, nums ...int) {\n\t\tsum := 0\n\t\tfor _, value := range nums {\n\t\t\tsum += value\n\t\t}\n\t\tif sum != 0 {\n\t\t\tt.Errorf(\"Expected 0, got %d\", sum)\n\t\t}\n\t})\n\n\tmockIndex.Ellip(\"%d\", 1, 2, 3, 4) // Match second matcher.\n\tmockIndex.Ellip(\"%d\", 5, 6, 7, 8) // Match first matcher.\n\tmockIndex.Ellip(\"%d\", 0)\n\tmockIndex.Ellip(\"%d\")\n\tmockIndex.Ellip(\"%d\")\n}\n\nfunc TestGrabPointer(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\tmockIndex := NewMockIndex(ctrl)\n\tmockIndex.EXPECT().Ptr(gomock.Any()).SetArg(0, 7) // set first argument to 7\n\n\ti := user.GrabPointer(mockIndex)\n\tif i != 7 {\n\t\tt.Errorf(\"Expected 7, got %d\", i)\n\t}\n}\n\nfunc TestEmbeddedInterface(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\tmockEmbed := NewMockEmbed(ctrl)\n\tmockEmbed.EXPECT().RegularMethod()\n\tmockEmbed.EXPECT().EmbeddedMethod()\n\tmockEmbed.EXPECT().ForeignEmbeddedMethod()\n\n\tmockEmbed.RegularMethod()\n\tmockEmbed.EmbeddedMethod()\n\tvar emb imp1.ForeignEmbedded = mockEmbed // also does interface check\n\temb.ForeignEmbeddedMethod()\n}\n\nfunc TestExpectTrueNil(t *testing.T) {\n\t// Make sure that passing \"nil\" to EXPECT (thus as a nil interface value),\n\t// will correctly match a nil concrete type.\n\tctrl := gomock.NewController(t)\n\tdefer ctrl.Finish()\n\n\tmockIndex := NewMockIndex(ctrl)\n\tmockIndex.EXPECT().Ptr(nil) // this nil is a nil interface{}\n\tmockIndex.Ptr(nil)          // this nil is a nil *int\n}\n\nfunc TestDoAndReturnSignature(t *testing.T) {\n\tt.Run(\"wrong number of return args\", func(t *testing.T) {\n\t\tctrl := gomock.NewController(t)\n\t\tdefer ctrl.Finish()\n\n\t\tmockIndex := NewMockIndex(ctrl)\n\n\t\tmockIndex.EXPECT().Slice(gomock.Any(), gomock.Any()).DoAndReturn(\n\t\t\tfunc(_ []int, _ []byte) {},\n\t\t)\n\n\t\tdefer func() {\n\t\t\tif r := recover(); r == nil {\n\t\t\t\tt.Error(\"expected panic\")\n\t\t\t}\n\t\t}()\n\n\t\tmockIndex.Slice([]int{0}, []byte(\"meow\"))\n\t})\n\n\tt.Run(\"wrong type of return arg\", func(t *testing.T) {\n\t\tctrl := gomock.NewController(t)\n\t\tdefer ctrl.Finish()\n\n\t\tmockIndex := NewMockIndex(ctrl)\n\n\t\tmockIndex.EXPECT().Slice(gomock.Any(), gomock.Any()).DoAndReturn(\n\t\t\tfunc(_ []int, _ []byte) bool {\n\t\t\t\treturn true\n\t\t\t})\n\n\t\tmockIndex.Slice([]int{0}, []byte(\"meow\"))\n\t})\n}\n"
  }
]