pax_global_header00006660000000000000000000000064150576325360014526gustar00rootroot0000000000000052 comment=1787e7d29dd879b458fdf4df04fd7825f206ef3d counterfeiter-6.12.0/000077500000000000000000000000001505763253600144725ustar00rootroot00000000000000counterfeiter-6.12.0/.devcontainer/000077500000000000000000000000001505763253600172315ustar00rootroot00000000000000counterfeiter-6.12.0/.devcontainer/Dockerfile000066400000000000000000000017141505763253600212260ustar00rootroot00000000000000# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.145.1/containers/go/.devcontainer/base.Dockerfile # [Choice] Go version: 1, 1.15, 1.14 ARG VARIANT="1" FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT} # [Option] Install Node.js ARG INSTALL_NODE="false" ARG NODE_VERSION="lts/*" RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi # [Optional] Uncomment this section to install additional OS packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends # [Optional] Uncomment the next line to use go get to install anything else you need # RUN go get -x # [Optional] Uncomment this line to install global node packages. # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1counterfeiter-6.12.0/.devcontainer/devcontainer.json000066400000000000000000000021131505763253600226020ustar00rootroot00000000000000{ "name": "Go", "build": { "dockerfile": "Dockerfile", "args": { // Update the VARIANT arg to pick a version of Go: 1, 1.15, 1.14 "VARIANT": "1", // Options "INSTALL_NODE": "false", "NODE_VERSION": "lts/*" } }, "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], // Set *default* container specific settings.json values on container create. "settings": { "ref": "vscode://schemas/settings/machine", "go.toolsManagement.checkForUpdates": "proxy", "go.useLanguageServer": true, "go.gopath": "/go", "go.goroot": "/usr/local/go", "go.toolsGopath": "/go/bin" }, // Add the IDs of extensions you want installed when the container is created. "extensions": [ "golang.Go" ] // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. // "postCreateCommand": "go version", // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. // "remoteUser": "vscode" } counterfeiter-6.12.0/.gitattributes000066400000000000000000000000161505763253600173620ustar00rootroot00000000000000* text eol=lf counterfeiter-6.12.0/.github/000077500000000000000000000000001505763253600160325ustar00rootroot00000000000000counterfeiter-6.12.0/.github/dependabot.yml000066400000000000000000000002671505763253600206670ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: gomod directory: "/" schedule: interval: daily time: "13:00" open-pull-requests-limit: 100 reviewers: - "joefitzgerald" counterfeiter-6.12.0/.github/workflows/000077500000000000000000000000001505763253600200675ustar00rootroot00000000000000counterfeiter-6.12.0/.github/workflows/codeql-analysis.yml000066400000000000000000000046631505763253600237130ustar00rootroot00000000000000# For most projects, this workflow file will not need changing; you simply need # to commit it to your repository. # # You may wish to alter this file to override the set of languages analyzed, # or to provide custom queries or build logic. # # ******** NOTE ******** # We have attempted to detect the languages in your repository. Please check # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # name: 'CodeQL' on: push: branches: [main] pull_request: # The branches below must be a subset of the branches above branches: [main] schedule: - cron: '45 1 * * 2' jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: ['go'] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] # Learn more: # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed steps: - name: Checkout repository uses: actions/checkout@v2 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@v1 # â„šī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project # uses a compiled language #- run: | # make bootstrap # make release - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 counterfeiter-6.12.0/.github/workflows/go.yml000066400000000000000000000023641505763253600212240ustar00rootroot00000000000000name: Build and Test on: push: pull_request: workflow_dispatch: inputs: debug_enabled: type: boolean description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' required: false default: false jobs: build: name: Build and Test runs-on: ${{ matrix.os }} strategy: matrix: go: [stable, oldstable] os: [ubuntu-latest, windows-latest] steps: - name: Set git to use LF run: | git config --global core.autocrlf false git config --global core.eol lf - uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v4 with: go-version: ${{ matrix.go }} # Enable tmate debugging of manually-triggered workflows if the input option was provided - name: Setup tmate session uses: mxschmitt/action-tmate@v3 if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} - name: Build and Test (Linux and macOS) run: ./scripts/ci.sh if: ${{ matrix.os != 'windows-latest' }} - name: Build and Test (Windows) run: .\scripts\ci.ps1 if: ${{ matrix.os == 'windows-latest' }} counterfeiter-6.12.0/.gitignore000066400000000000000000000005471505763253600164700ustar00rootroot00000000000000# Compiled Object files, Static and Dynamic libs (Shared Objects) *.o *.a *.so # Folders _obj _test # Architecture specific extensions/prefixes *.[568vq] [568vq].out *.cgo1.go *.cgo2.c _cgo_defun.c _cgo_gotypes.go _cgo_export.* _testmain.go *.exe *.test *.iml .idea .envrc /counterfeiter integration/testdata/output *.profile *.bench /.vscode .DS_Store counterfeiter-6.12.0/.golangci.yaml000066400000000000000000000000401505763253600172110ustar00rootroot00000000000000run: skip-dirs: - fixturescounterfeiter-6.12.0/LICENSE000066400000000000000000000020661505763253600155030ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 maxbrunsfeld Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.counterfeiter-6.12.0/README.md000066400000000000000000000167711505763253600157650ustar00rootroot00000000000000# `counterfeiter` [![GitHub Actions](https://github.com/maxbrunsfeld/counterfeiter/actions/workflows/go.yml/badge.svg)](https://github.com/maxbrunsfeld/counterfeiter/actions/workflows/go.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/maxbrunsfeld/counterfeiter/v6)](https://goreportcard.com/report/github.com/maxbrunsfeld/counterfeiter/v6) [![GoDoc](https://godoc.org/github.com/maxbrunsfeld/counterfeiter/v6?status.svg)](https://godoc.org/github.com/maxbrunsfeld/counterfeiter/v6) When writing unit-tests for an object, it is often useful to have fake implementations of the object's collaborators. In go, such fake implementations cannot be generated automatically at runtime, and writing them by hand can be quite arduous. `counterfeiter` allows you to simply generate test doubles for a given interface. ### Supported Versions Of `go` `counterfeiter` follows the [support policy of `go` itself](https://golang.org/doc/devel/release.html#policy): > Each major Go release is supported until there are two newer major releases. For example, Go 1.5 was supported until the Go 1.7 release, and Go 1.6 was supported until the Go 1.8 release. We fix critical problems, including [critical security problems](https://golang.org/security), in supported releases as needed by issuing minor revisions (for example, Go 1.6.1, Go 1.6.2, and so on). If you are having problems with `counterfeiter` and are not using a supported version of go, please update to use a supported version of go before opening an issue. ### Using `counterfeiter` âš ī¸ Please use [`go modules`](https://blog.golang.org/using-go-modules) when working with counterfeiter. Typically, `counterfeiter` is used in `go generate` directives. It can be frustrating when you change your interface declaration and suddenly all of your generated code is suddenly out-of-date. The best practice here is to use the [`go generate` command](https://blog.golang.org/generate) to make it easier to keep your test doubles up to date. âš ī¸ If you are working with go 1.23 or earlier, please refer to an [older version of this README](https://github.com/maxbrunsfeld/counterfeiter/blob/e39cbe6aaa94a0b6718cf3d413cd5319c3a1f6fa/README.md#using-counterfeiter), as the instructions below assume go 1.24 (which added `go tool` support) and later. #### Step 1 - Add `counterfeiter` as a tool dependency Establish a tool dependency on counterfeiter by running the following command: ```shell go get -tool github.com/maxbrunsfeld/counterfeiter/v6 ``` #### Step 2a - Add `go:generate` Directives You can add directives right next to your interface definitions (or not), in any `.go` file in your module. ```shell $ cat myinterface.go ``` ```go package foo //go:generate go tool counterfeiter . MySpecialInterface type MySpecialInterface interface { DoThings(string, uint64) (int, error) } ``` ```shell $ go generate ./... Writing `FakeMySpecialInterface` to `foofakes/fake_my_special_interface.go`... Done ``` #### Step 2b - Add `counterfeiter:generate` Directives If you plan to have many directives in a single package, consider using this option, as it will speed things up considerably. You can add directives right next to your interface definitions (or not), in any `.go` file in your module. ```shell $ cat myinterface.go ``` ```go package foo // You only need **one** of these per package! //go:generate go tool counterfeiter -generate // You will add lots of directives like these in the same package... //counterfeiter:generate . MySpecialInterface type MySpecialInterface interface { DoThings(string, uint64) (int, error) } // Like this... //counterfeiter:generate . MyOtherInterface type MyOtherInterface interface { DoOtherThings(string, uint64) (int, error) } ``` ```shell $ go generate ./... Writing `FakeMySpecialInterface` to `foofakes/fake_my_special_interface.go`... Done Writing `FakeMyOtherInterface` to `foofakes/fake_my_other_interface.go`... Done ``` #### Step 3 - Run `go generate` You can run `go generate` in the directory with your directive, or in the root of your module (to ensure you generate for all packages in your module): ```shell $ go generate ./... ``` #### Invoking `counterfeiter` from the shell You can use the following command to invoke `counterfeiter` from within a go module: ```shell $ go tool counterfeiter USAGE counterfeiter [-generate>] [-o ] [-p] [--fake-name ] [-header ] [] [-] ``` #### Installing `counterfeiter` to `$GOPATH/bin` This is unnecessary if you're using the approach described above, but does allow you to invoke `counterfeiter` in your shell _outside_ of a module: ```shell $ go install github.com/maxbrunsfeld/counterfeiter/v6 $ ~/go/bin/counterfeiter USAGE counterfeiter [-generate>] [-o ] [-p] [--fake-name ] [-header ] [] [-] ``` ### Generating Test Doubles Given a path to a package and an interface name, you can generate a test double. ```shell $ cat path/to/foo/file.go ``` ```go package foo type MySpecialInterface interface { DoThings(string, uint64) (int, error) } ``` ```shell $ go tool counterfeiter path/to/foo MySpecialInterface Wrote `FakeMySpecialInterface` to `path/to/foo/foofakes/fake_my_special_interface.go` ``` ### Using Test Doubles In Your Tests Instantiate fakes: ```go import "my-repo/path/to/foo/foofakes" var fake = &foofakes.FakeMySpecialInterface{} ``` Fakes record the arguments they were called with: ```go fake.DoThings("stuff", 5) Expect(fake.DoThingsCallCount()).To(Equal(1)) str, num := fake.DoThingsArgsForCall(0) Expect(str).To(Equal("stuff")) Expect(num).To(Equal(uint64(5))) ``` You can stub their return values: ```go fake.DoThingsReturns(3, errors.New("the-error")) num, err := fake.DoThings("stuff", 5) Expect(num).To(Equal(3)) Expect(err).To(Equal(errors.New("the-error"))) ``` For more examples of using the `counterfeiter` API, look at [some of the provided examples](https://github.com/maxbrunsfeld/counterfeiter/blob/master/generated_fakes_test.go). ### Generating Test Doubles For Third Party Interfaces For third party interfaces, you can specify the interface using the alternative syntax `.`, for example: ```shell $ go tool counterfeiter github.com/go-redis/redis.Pipeliner ``` ### Running The Tests For `counterfeiter` If you want to run the tests for `counterfeiter` (perhaps, because you want to contribute a PR), all you have to do is run `scripts/ci.sh`. ### Contributions So you want to contribute to `counterfeiter`! That's great, here's exactly what you should do: - open a new github issue, describing your problem, or use case - help us understand how you want to fix or extend `counterfeiter` - write one or more unit tests for the behavior you want - write the simplest code you can for the feature you're working on - try to find any opportunities to refactor - avoid writing code that isn't covered by unit tests `counterfeiter` has a few high level goals for contributors to keep in mind - keep unit-level test coverage as high as possible - keep `main.go` as simple as possible - avoid making the command line options any more complicated - avoid making the internals of `counterfeiter` any more complicated If you have any questions about how to contribute, rest assured that @tjarratt and other maintainers will work with you to ensure we make `counterfeiter` better, together. This project has largely been maintained by the community, and we greatly appreciate any PR (whether big or small). ### License `counterfeiter` is MIT-licensed. counterfeiter-6.12.0/arguments/000077500000000000000000000000001505763253600164775ustar00rootroot00000000000000counterfeiter-6.12.0/arguments/files.go000066400000000000000000000001671505763253600201340ustar00rootroot00000000000000package arguments import "os" type Evaler func(string) (string, error) type Stater func(string) (os.FileInfo, error) counterfeiter-6.12.0/arguments/parser.go000066400000000000000000000152551505763253600203320ustar00rootroot00000000000000package arguments import ( "encoding/json" "errors" "flag" "fmt" "path" "path/filepath" "regexp" "strings" "unicode" ) func New(args []string, workingDir string, evaler Evaler, stater Stater) (*ParsedArguments, error) { if len(args) == 0 { return nil, errors.New("argument parsing requires at least one argument") } fs := flag.NewFlagSet("counterfeiter", flag.ContinueOnError) fakeNameFlag := fs.String( "fake-name", "", "The name of the fake struct", ) outputPathFlag := fs.String( "o", "", "The file or directory to which the generated fake will be written", ) packageFlag := fs.Bool( "p", false, "Whether or not to generate a package shim", ) generateFlag := fs.Bool( "generate", false, "Identify all //counterfeiter:generate directives in the current working directory and generate fakes for them", ) headerFlag := fs.String( "header", "", "A path to a file that should be used as a header for the generated fake", ) quietFlag := fs.Bool( "q", false, "Suppress status statements", ) helpFlag := fs.Bool( "help", false, "Display this help", ) err := fs.Parse(args[1:]) if err != nil { return nil, err } if *helpFlag { return nil, errors.New(usage) } if len(fs.Args()) == 0 && !*generateFlag { return nil, errors.New(usage) } packageMode := *packageFlag result := &ParsedArguments{ PrintToStdOut: any(args, "-"), GenerateInterfaceAndShimFromPackageDirectory: packageMode, GenerateMode: *generateFlag, HeaderFile: *headerFlag, Quiet: *quietFlag, } if *generateFlag { return result, nil } err = result.parseSourcePackageDir(packageMode, workingDir, evaler, stater, fs.Args()) if err != nil { return nil, err } result.parseInterfaceName(packageMode, fs.Args()) result.parseFakeName(packageMode, *fakeNameFlag, fs.Args()) result.parseOutputPath(packageMode, workingDir, *outputPathFlag, fs.Args()) result.parseDestinationPackageName(packageMode, fs.Args()) result.parsePackagePath(packageMode, fs.Args()) return result, nil } func (a *ParsedArguments) PrettyPrint() { b, _ := json.MarshalIndent(a, "", " ") fmt.Println(string(b)) } func (a *ParsedArguments) parseInterfaceName(packageMode bool, args []string) { if packageMode { a.InterfaceName = "" return } if len(args) == 1 { fullyQualifiedInterface := strings.Split(args[0], ".") a.InterfaceName = fullyQualifiedInterface[len(fullyQualifiedInterface)-1] } else { a.InterfaceName = args[1] } } func (a *ParsedArguments) parseSourcePackageDir(packageMode bool, workingDir string, evaler Evaler, stater Stater, args []string) error { if packageMode { a.SourcePackageDir = args[0] return nil } if len(args) <= 1 { return nil } s, err := getSourceDir(args[0], workingDir, evaler, stater) if err != nil { return err } a.SourcePackageDir = s return nil } func (a *ParsedArguments) parseFakeName(packageMode bool, fakeName string, args []string) { if packageMode { a.parsePackagePath(packageMode, args) a.FakeImplName = strings.ToUpper(path.Base(a.PackagePath))[:1] + path.Base(a.PackagePath)[1:] return } if fakeName == "" { fakeName = "Fake" + fixupUnexportedNames(a.InterfaceName) } a.FakeImplName = fakeName } func (a *ParsedArguments) parseOutputPath(packageMode bool, workingDir string, outputPath string, args []string) { outputPathIsFilename := false if strings.HasSuffix(outputPath, ".go") { outputPathIsFilename = true } snakeCaseName := strings.ToLower(camelRegexp.ReplaceAllString(a.FakeImplName, "${1}_${2}")) if outputPath != "" { if !filepath.IsAbs(outputPath) { outputPath = filepath.Join(workingDir, outputPath) } a.OutputPath = outputPath if !outputPathIsFilename { a.OutputPath = filepath.Join(a.OutputPath, snakeCaseName+".go") } return } if packageMode { a.parseDestinationPackageName(packageMode, args) a.OutputPath = path.Join(workingDir, a.DestinationPackageName, snakeCaseName+".go") return } d := workingDir if len(args) > 1 { d = a.SourcePackageDir } a.OutputPath = filepath.Join(d, packageNameForPath(d), snakeCaseName+".go") } func (a *ParsedArguments) parseDestinationPackageName(packageMode bool, args []string) { if packageMode { a.parsePackagePath(packageMode, args) a.DestinationPackageName = path.Base(a.PackagePath) + "shim" return } a.DestinationPackageName = restrictToValidPackageName(filepath.Base(filepath.Dir(a.OutputPath))) } func (a *ParsedArguments) parsePackagePath(packageMode bool, args []string) { if packageMode { a.PackagePath = args[0] return } if len(args) == 1 { fullyQualifiedInterface := strings.Split(args[0], ".") a.PackagePath = strings.Join(fullyQualifiedInterface[:len(fullyQualifiedInterface)-1], ".") } else { a.InterfaceName = args[1] } if a.PackagePath == "" { a.PackagePath = a.SourcePackageDir } } type ParsedArguments struct { GenerateInterfaceAndShimFromPackageDirectory bool SourcePackageDir string // abs path to the dir containing the interface to fake PackagePath string // package path to the package containing the interface to fake OutputPath string // path to write the fake file to DestinationPackageName string // often the base-dir for OutputPath but must be a valid package name InterfaceName string // the interface to counterfeit FakeImplName string // the name of the struct implementing the given interface PrintToStdOut bool GenerateMode bool Quiet bool HeaderFile string } func fixupUnexportedNames(interfaceName string) string { asRunes := []rune(interfaceName) if len(asRunes) == 0 || !unicode.IsLower(asRunes[0]) { return interfaceName } asRunes[0] = unicode.ToUpper(asRunes[0]) return string(asRunes) } var camelRegexp = regexp.MustCompile("([a-z])([A-Z])") func packageNameForPath(pathToPackage string) string { _, packageName := filepath.Split(pathToPackage) return packageName + "fakes" } func getSourceDir(path string, workingDir string, evaler Evaler, stater Stater) (string, error) { if !filepath.IsAbs(path) { path = filepath.Join(workingDir, path) } evaluatedPath, err := evaler(path) if err != nil { return "", fmt.Errorf("No such file/directory/package [%s]: %v", path, err) } stat, err := stater(evaluatedPath) if err != nil { return "", fmt.Errorf("No such file/directory/package [%s]: %v", path, err) } if !stat.IsDir() { return filepath.Dir(path), nil } return path, nil } func any(slice []string, needle string) bool { for _, str := range slice { if str == needle { return true } } return false } func restrictToValidPackageName(input string) string { return strings.Map(func(r rune) rune { if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_' { return r } else { return -1 } }, input) } counterfeiter-6.12.0/arguments/parser_test.go000066400000000000000000000250241505763253600213640ustar00rootroot00000000000000//go:build !windows package arguments_test import ( "errors" "fmt" "io" "log" "os" "path" "path/filepath" "time" "testing" "github.com/maxbrunsfeld/counterfeiter/v6/arguments" . "github.com/onsi/gomega" "github.com/sclevine/spec" "github.com/sclevine/spec/report" ) func TestParsingArguments(t *testing.T) { spec.Run(t, "ParsingArguments", testParsingArguments, spec.Report(report.Terminal{})) } func testParsingArguments(t *testing.T, when spec.G, it spec.S) { var ( err error parsedArgs *arguments.ParsedArguments args []string workingDir string evaler arguments.Evaler stater arguments.Stater ) justBefore := func() { parsedArgs, err = arguments.New(args, workingDir, evaler, stater) } it.Before(func() { RegisterTestingT(t) log.SetOutput(io.Discard) workingDir = "/home/test-user/workspace" evaler = func(input string) (string, error) { return input, nil } stater = func(filename string) (os.FileInfo, error) { return fakeFileInfo(filename, true), nil } }) when("when the -p flag is provided", func() { it.Before(func() { args = []string{"counterfeiter", "-p", "os"} justBefore() }) it("doesn't parse extraneous arguments", func() { Expect(err).To(Succeed()) Expect(parsedArgs.GenerateInterfaceAndShimFromPackageDirectory).To(BeTrue()) Expect(parsedArgs.InterfaceName).To(Equal("")) Expect(parsedArgs.FakeImplName).To(Equal("Os")) }) when("given a stdlib package", func() { it("sets arguments as expected", func() { Expect(parsedArgs.SourcePackageDir).To(Equal("os")) Expect(parsedArgs.OutputPath).To(Equal(path.Join(workingDir, "osshim", "os.go"))) Expect(parsedArgs.DestinationPackageName).To(Equal("osshim")) }) }) }) when("when a single argument is provided", func() { it.Before(func() { args = []string{"counterfeiter", "someonesinterfaces.AnInterface"} justBefore() }) it("sets PrintToStdOut to false", func() { Expect(parsedArgs.PrintToStdOut).To(BeFalse()) }) it("provides a name for the fake implementing the interface", func() { Expect(parsedArgs.FakeImplName).To(Equal("FakeAnInterface")) }) it("provides a path for the interface source", func() { Expect(parsedArgs.PackagePath).To(Equal("someonesinterfaces")) }) it("treats the last segment as the interface to counterfeit", func() { Expect(parsedArgs.InterfaceName).To(Equal("AnInterface")) }) it("snake cases the filename for the output directory", func() { Expect(parsedArgs.OutputPath).To(Equal( filepath.Join( workingDir, "workspacefakes", "fake_an_interface.go", ), )) }) }) when("when a single argument is provided with the output directory", func() { it.Before(func() { args = []string{"counterfeiter", "-o", "/tmp/foo", "io.Writer"} justBefore() }) it("indicates to not print to stdout", func() { Expect(parsedArgs.PrintToStdOut).To(BeFalse()) }) it("provides a name for the fake implementing the interface", func() { Expect(parsedArgs.FakeImplName).To(Equal("FakeWriter")) }) it("provides a path for the interface source", func() { Expect(parsedArgs.PackagePath).To(Equal("io")) }) it("treats the last segment as the interface to counterfeit", func() { Expect(parsedArgs.InterfaceName).To(Equal("Writer")) }) it("copies the provided output path into the result", func() { Expect(parsedArgs.OutputPath).To(Equal("/tmp/foo/fake_writer.go")) }) }) when("when a single argument is provided with the output file", func() { it.Before(func() { args = []string{"counterfeiter", "-o", "/tmp/foo/fake_foo.go", "io.Writer"} justBefore() }) it("indicates to not print to stdout", func() { Expect(parsedArgs.PrintToStdOut).To(BeFalse()) }) it("provides a name for the fake implementing the interface", func() { Expect(parsedArgs.FakeImplName).To(Equal("FakeWriter")) }) it("provides a path for the interface source", func() { Expect(parsedArgs.PackagePath).To(Equal("io")) }) it("treats the last segment as the interface to counterfeit", func() { Expect(parsedArgs.InterfaceName).To(Equal("Writer")) }) it("copies the provided output path into the result", func() { Expect(parsedArgs.OutputPath).To(Equal("/tmp/foo/fake_foo.go")) }) }) when("when two arguments are provided", func() { it.Before(func() { args = []string{"counterfeiter", "my/my5package", "MySpecialInterface"} justBefore() }) it("indicates to not print to stdout", func() { Expect(parsedArgs.PrintToStdOut).To(BeFalse()) }) it("provides a name for the fake implementing the interface", func() { Expect(parsedArgs.FakeImplName).To(Equal("FakeMySpecialInterface")) }) it("treats the second argument as the interface to counterfeit", func() { Expect(parsedArgs.InterfaceName).To(Equal("MySpecialInterface")) }) it("snake cases the filename for the output directory", func() { Expect(parsedArgs.OutputPath).To(Equal( filepath.Join( parsedArgs.SourcePackageDir, "my5packagefakes", "fake_my_special_interface.go", ), )) }) it("specifies the destination package name", func() { Expect(parsedArgs.DestinationPackageName).To(Equal("my5packagefakes")) }) when("when the interface is unexported", func() { it.Before(func() { args = []string{"counterfeiter", "my/mypackage", "mySpecialInterface"} justBefore() }) it("fixes up the fake name to be TitleCase", func() { Expect(parsedArgs.FakeImplName).To(Equal("FakeMySpecialInterface")) }) it("snake cases the filename for the output directory", func() { Expect(parsedArgs.OutputPath).To(Equal( filepath.Join( parsedArgs.SourcePackageDir, "mypackagefakes", "fake_my_special_interface.go", ), )) }) }) when("the source directory", func() { it("should be an absolute path", func() { Expect(filepath.IsAbs(parsedArgs.SourcePackageDir)).To(BeTrue()) }) when("when the first arg is a path to a file", func() { it.Before(func() { stater = func(filename string) (os.FileInfo, error) { return fakeFileInfo(filename, false), nil } justBefore() }) it("should be the directory containing the file", func() { Expect(parsedArgs.SourcePackageDir).ToNot(ContainSubstring("something.go")) }) }) when("when evaluating symlinks fails", func() { it.Before(func() { evaler = func(input string) (string, error) { return "", errors.New("aww shucks") } justBefore() }) it("should return an error with a useful message", func() { Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal(fmt.Sprintf("No such file/directory/package [%s]: aww shucks", path.Join(workingDir, "my/my5package")))) }) }) when("when the file stat cannot be read", func() { it.Before(func() { stater = func(_ string) (os.FileInfo, error) { return fakeFileInfo("", false), errors.New("submarine-shoutout") } justBefore() }) it("should return an error with a useful message", func() { Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal(fmt.Sprintf("No such file/directory/package [%s]: submarine-shoutout", path.Join(workingDir, "my/my5package")))) }) }) }) }) when("when the output dir contains characters inappropriate for a package name", func() { it.Before(func() { args = []string{"counterfeiter", "@my-special-package[]{}", "MySpecialInterface"} justBefore() }) it("should choose a valid package name", func() { Expect(parsedArgs.DestinationPackageName).To(Equal("myspecialpackagefakes")) }) }) when("when three arguments are provided", func() { when("and the third one is '-'", func() { it.Before(func() { args = []string{"counterfeiter", "my/mypackage", "MySpecialInterface", "-"} justBefore() }) it("treats the second argument as the interface to counterfeit", func() { Expect(parsedArgs.InterfaceName).To(Equal("MySpecialInterface")) }) it("provides a name for the fake implementing the interface", func() { Expect(parsedArgs.FakeImplName).To(Equal("FakeMySpecialInterface")) }) it("indicates that the fake should be printed to stdout", func() { Expect(parsedArgs.PrintToStdOut).To(BeTrue()) }) it("snake cases the filename for the output directory", func() { Expect(parsedArgs.OutputPath).To(Equal( filepath.Join( parsedArgs.SourcePackageDir, "mypackagefakes", "fake_my_special_interface.go", ), )) }) when("the source directory", func() { it("should be an absolute path", func() { Expect(filepath.IsAbs(parsedArgs.SourcePackageDir)).To(BeTrue()) }) when("when the first arg is a path to a file", func() { it.Before(func() { stater = func(filename string) (os.FileInfo, error) { return fakeFileInfo(filename, false), nil } }) it("should be the directory containing the file", func() { Expect(parsedArgs.SourcePackageDir).ToNot(ContainSubstring("something.go")) }) }) }) }) when("and the third one is some random input", func() { it.Before(func() { args = []string{"counterfeiter", "my/mypackage", "MySpecialInterface", "WHOOPS"} justBefore() }) it("indicates to not print to stdout", func() { Expect(parsedArgs.PrintToStdOut).To(BeFalse()) }) }) }) when("when the output dir contains underscores in package name", func() { it.Before(func() { args = []string{"counterfeiter", "fake_command_runner", "MySpecialInterface"} justBefore() }) it("should ensure underscores are in the package name", func() { Expect(parsedArgs.DestinationPackageName).To(Equal("fake_command_runnerfakes")) }) }) when("when '-header' is used", func() { it.Before(func() { args = []string{"counterfeiter", "-header", "some/header/file", "some.interface"} justBefore() }) it("sets the HeaderFile attriburte on the parsedArgs struct", func() { Expect(parsedArgs.HeaderFile).To(Equal("some/header/file")) Expect(err).NotTo(HaveOccurred()) }) }) } func fakeFileInfo(filename string, isDir bool) os.FileInfo { return testFileInfo{name: filename, isDir: isDir} } type testFileInfo struct { name string isDir bool } func (testFileInfo testFileInfo) Name() string { return testFileInfo.name } func (testFileInfo testFileInfo) IsDir() bool { return testFileInfo.isDir } func (testFileInfo testFileInfo) Size() int64 { return 0 } func (testFileInfo testFileInfo) Mode() os.FileMode { return 0 } func (testFileInfo testFileInfo) ModTime() time.Time { return time.Now() } func (testFileInfo testFileInfo) Sys() interface{} { return nil } counterfeiter-6.12.0/arguments/parser_windows_test.go000066400000000000000000000065251505763253600231430ustar00rootroot00000000000000//go:build windows package arguments_test import ( "io" "log" "os" "path/filepath" "time" "testing" "github.com/maxbrunsfeld/counterfeiter/v6/arguments" . "github.com/onsi/gomega" "github.com/sclevine/spec" "github.com/sclevine/spec/report" ) func TestParsingArguments(t *testing.T) { spec.Run(t, "ParsingArguments (Windows)", testParsingArguments, spec.Report(report.Terminal{})) } func testParsingArguments(t *testing.T, when spec.G, it spec.S) { var ( err error parsedArgs *arguments.ParsedArguments args []string workingDir string evaler arguments.Evaler stater arguments.Stater ) justBefore := func() { parsedArgs, err = arguments.New(args, workingDir, evaler, stater) } it.Before(func() { RegisterTestingT(t) log.SetOutput(io.Discard) workingDir = "C:\\Users\\test-user\\workspace" evaler = func(input string) (string, error) { return input, nil } stater = func(filename string) (os.FileInfo, error) { return fakeFileInfo(filename, true), nil } }) when("when a single argument is provided with the output directory", func() { it.Before(func() { args = []string{"counterfeiter", "-o", "C:\\tmp\\foo", "io.Writer"} justBefore() }) it("copies the provided output path into the result", func() { Expect(parsedArgs.OutputPath).To(Equal("C:\\tmp\\foo\\fake_writer.go")) Expect(err).NotTo(HaveOccurred()) }) }) when("when two arguments are provided", func() { it.Before(func() { args = []string{"counterfeiter", "my\\specialpackage", "MySpecialInterface"} justBefore() }) it("snake cases the filename for the output directory", func() { Expect(parsedArgs.OutputPath).To(Equal( filepath.Join( parsedArgs.SourcePackageDir, "specialpackagefakes", "fake_my_special_interface.go", ), )) Expect(err).NotTo(HaveOccurred()) }) when("the source directory", func() { it("should be an absolute path", func() { Expect(filepath.IsAbs(parsedArgs.SourcePackageDir)).To(BeTrue()) Expect(err).NotTo(HaveOccurred()) }) }) }) when("when three arguments are provided", func() { when("and the third one is '-'", func() { it.Before(func() { args = []string{"counterfeiter", "my/mypackage", "MySpecialInterface", "-"} justBefore() }) it("snake cases the filename for the output directory", func() { Expect(parsedArgs.OutputPath).To(Equal( filepath.Join( parsedArgs.SourcePackageDir, "mypackagefakes", "fake_my_special_interface.go", ), )) Expect(err).NotTo(HaveOccurred()) }) when("the source directory", func() { it("should be an absolute path", func() { Expect(filepath.IsAbs(parsedArgs.SourcePackageDir)).To(BeTrue()) Expect(err).NotTo(HaveOccurred()) }) }) }) }) } func fakeFileInfo(filename string, isDir bool) os.FileInfo { return testFileInfo{name: filename, isDir: isDir} } type testFileInfo struct { name string isDir bool } func (testFileInfo testFileInfo) Name() string { return testFileInfo.name } func (testFileInfo testFileInfo) IsDir() bool { return testFileInfo.isDir } func (testFileInfo testFileInfo) Size() int64 { return 0 } func (testFileInfo testFileInfo) Mode() os.FileMode { return 0 } func (testFileInfo testFileInfo) ModTime() time.Time { return time.Now() } func (testFileInfo testFileInfo) Sys() interface{} { return nil } counterfeiter-6.12.0/arguments/usage.go000066400000000000000000000100041505763253600201250ustar00rootroot00000000000000package arguments const usage = ` USAGE counterfeiter [-generate>] [-o ] [-p] [--fake-name ] [-header ] [] [-] ARGUMENTS source-path Path to the file or directory containing the interface to fake. In package mode (-p), source-path should instead specify the path of the input package; alternatively you can use the package name (e.g. "os") and the path will be inferred from your GOROOT. interface If source-path is specified: Name of the interface to fake. If no source-path is specified: Fully qualified interface path of the interface to fake. If -p is specified, this will be the name of the interface to generate. example: # writes "FakeStdInterface" to ./packagefakes/fake_std_interface.go counterfeiter package/subpackage.StdInterface '-' argument Write code to standard out instead of to a file OPTIONS -generate Identify all //counterfeiter:generate directives in .go file in the current working directory and generate fakes for them. You can pass arguments as usual. NOTE: This is not the same as //go:generate directives (used with the 'go generate' command), but it can be combined with go generate by adding the following to a .go file: # runs counterfeiter in generate mode //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate example: Add the following to a .go file: //counterfeiter:generate . MyInterface //counterfeiter:generate . MyOtherInterface //counterfeiter:generate . MyThirdInterface # run counterfeiter counterfeiter -generate # writes "FakeMyInterface" to ./mypackagefakes/fake_my_interface.go # writes "FakeMyOtherInterface" to ./mypackagefakes/fake_my_other_interface.go # writes "FakeMyThirdInterface" to ./mypackagefakes/fake_my_third_interface.go -o Path to the file or directory for the generated fakes. This also determines the package name that will be used. By default, the generated fakes will be generated in the package "xyzfakes" which is nested in package "xyz", where "xyz" is the name of referenced package. example: # writes "FakeMyInterface" to ./mySpecialFakesDir/specialFake.go counterfeiter -o ./mySpecialFakesDir/specialFake.go ./mypackage MyInterface # writes "FakeMyInterface" to ./mySpecialFakesDir/fake_my_interface.go counterfeiter -o ./mySpecialFakesDir ./mypackage MyInterface -p Package mode: When invoked in package mode, counterfeiter will generate an interface and shim implementation from a package in your module. Counterfeiter finds the public methods in the package and adds those method signatures to the generated interface . example: # generates os.go (interface) and osshim.go (shim) in ${PWD}/osshim counterfeiter -p os # now generate fake in ${PWD}/osshim/os_fake (fake_os.go) go generate osshim/... -header Path to the file which should be used as a header for all generated fakes. By default, no special header is used. This is useful to e.g. add a licence header to every fake. If the generate mode is used and both the "go:generate" and the "counterfeiter:generate" specify a header file, the header file from the "counterfeiter:generate" line takes precedence. example: # having the following code in a package ... //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -header ./generic.go.txt -generate //counterfeiter:generate -header ./specific.go.txt . MyInterface //counterfeiter:generate . MyOtherInterface //counterfeiter:generate . MyThirdInterface # ... generating the fakes ... go generate . # writes "FakeMyInterface" with ./specific.go.txt as a header # writes "FakeMyOtherInterface" & "FakeMyThirdInterface" with ./generic.go.txt as a header --fake-name Name of the fake struct to generate. By default, 'Fake' will be prepended to the name of the original interface. (ignored in -p mode) example: # writes "CoolThing" to ./mypackagefakes/cool_thing.go counterfeiter --fake-name CoolThing ./mypackage MyInterface ` counterfeiter-6.12.0/benchmark_test.go000066400000000000000000000033541505763253600200170ustar00rootroot00000000000000package main import ( "io" "log" "path/filepath" "testing" "github.com/maxbrunsfeld/counterfeiter/v6/arguments" "github.com/maxbrunsfeld/counterfeiter/v6/generator" ) func BenchmarkDoGenerate(b *testing.B) { b.StopTimer() workingDir, err := filepath.Abs(filepath.Join(".", "fixtures")) if err != nil { b.Fatal(err) } log.SetOutput(io.Discard) args := &arguments.ParsedArguments{ GenerateInterfaceAndShimFromPackageDirectory: false, SourcePackageDir: workingDir, PackagePath: workingDir, OutputPath: filepath.Join(workingDir, "fixturesfakes", "fake_something.go"), DestinationPackageName: "fixturesfakes", InterfaceName: "Something", FakeImplName: "FakeSomething", PrintToStdOut: false, } caches := map[string]struct { cache generator.Cacher headerReader generator.FileReader }{ "without caches": { cache: &generator.FakeCache{}, headerReader: &generator.SimpleFileReader{}, }, "with caches": { cache: &generator.Cache{}, headerReader: &generator.CachedFileReader{}, }, } headers := map[string]string{ "without headerfile": "", "with headerfile": "headers/default.header.go.txt", } for name, caches := range caches { caches := caches b.Run(name, func(b *testing.B) { for name, headerFile := range headers { headerFile := headerFile b.Run(name, func(b *testing.B) { args.HeaderFile = headerFile b.StartTimer() for i := 0; i < b.N; i++ { if _, err := doGenerate(workingDir, args, caches.cache, caches.headerReader); err != nil { b.Errorf("Expected doGenerate not to return an error, got %v", err) } } }) // b.Run for headerFiles } }) // b.Run for caches } } counterfeiter-6.12.0/command/000077500000000000000000000000001505763253600161105ustar00rootroot00000000000000counterfeiter-6.12.0/command/runner.go000066400000000000000000000046271505763253600177610ustar00rootroot00000000000000package command import ( "fmt" "go/build" "os" "path/filepath" "sort" "strconv" "strings" ) func Detect(cwd string, args []string, generateMode bool) ([]Invocation, error) { if generateMode { return generateModeInvocations(cwd) } file := os.Getenv("GOFILE") var lineno int if goline, err := strconv.Atoi(os.Getenv("GOLINE")); err == nil { lineno = goline } i, err := NewInvocation(file, lineno, args) if err != nil { return nil, err } return []Invocation{i}, nil } type Invocation struct { Args []string Line int File string } func NewInvocation(file string, line int, args []string) (Invocation, error) { if len(args) < 1 { return Invocation{}, fmt.Errorf("%s:%v an invocation of counterfeiter must have arguments", file, line) } i := Invocation{ File: file, Line: line, Args: args, } return i, nil } func generateModeInvocations(cwd string) ([]Invocation, error) { var result []Invocation // Find all the go files pkg, err := build.ImportDir(cwd, build.IgnoreVendor) if err != nil { return nil, err } gofiles := make([]string, 0, len(pkg.GoFiles)+len(pkg.CgoFiles)+len(pkg.TestGoFiles)+len(pkg.XTestGoFiles)) gofiles = append(gofiles, pkg.GoFiles...) gofiles = append(gofiles, pkg.CgoFiles...) gofiles = append(gofiles, pkg.TestGoFiles...) gofiles = append(gofiles, pkg.XTestGoFiles...) sort.Strings(gofiles) for _, file := range gofiles { invocations, err := invocationsInFile(cwd, file) if err != nil { return nil, err } result = append(result, invocations...) } return result, nil } func invocationsInFile(dir string, file string) ([]Invocation, error) { str, err := os.ReadFile(filepath.Join(dir, file)) if err != nil { return nil, err } lines := strings.Split(string(str), "\n") var result []Invocation line := 0 for i := range lines { line++ args, ok := matchForString(lines[i]) if !ok { continue } inv, err := NewInvocation(file, line, args) if err != nil { return nil, err } result = append(result, inv) } return result, nil } const generateDirectivePrefix = "//counterfeiter:generate " func matchForString(s string) ([]string, bool) { if !strings.HasPrefix(s, generateDirectivePrefix) { return nil, false } return stringToArgs(s[len(generateDirectivePrefix):]), true } func stringToArgs(s string) []string { a := strings.Fields(s) result := []string{ "counterfeiter", } result = append(result, a...) return result } counterfeiter-6.12.0/command/runner_internals_test.go000066400000000000000000000025661505763253600230770ustar00rootroot00000000000000package command import ( "log" "testing" . "github.com/onsi/gomega" "github.com/sclevine/spec" "github.com/sclevine/spec/report" ) func TestRunner(t *testing.T) { spec.Run(t, "Regexp", testRegexp, spec.Report(report.Terminal{})) } type Case struct { input string matches bool args []string } func testRegexp(t *testing.T, when spec.G, it spec.S) { var cases []Case it.Before(func() { RegisterTestingT(t) log.SetFlags(log.Llongfile) cases = []Case{ { input: "//go:generate counterfeiter . Intf", matches: false, }, { input: "//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . Intf", matches: false, }, { input: "//counterfeiter:generate . Intf", matches: true, args: []string{"counterfeiter", ".", "Intf"}, }, { input: "//go:generate stringer -type=Enum", matches: false, }, } }) it("splits args correctly", func() { Expect(stringToArgs(". Intf")).To(ConsistOf([]string{"counterfeiter", ".", "Intf"})) Expect(stringToArgs(" . Intf ")).To(ConsistOf([]string{"counterfeiter", ".", "Intf"})) }) it("matches lines appropriately", func() { for _, c := range cases { result, ok := matchForString(c.input) if c.matches { Expect(ok).To(BeTrue(), c.input) Expect(result).To(ConsistOf(c.args), c.input) } else { Expect(ok).To(BeFalse()) } } }) } counterfeiter-6.12.0/command/runner_test.go000066400000000000000000000051351505763253600210130ustar00rootroot00000000000000package command_test import ( "log" "os" "path/filepath" "testing" "github.com/maxbrunsfeld/counterfeiter/v6/command" . "github.com/onsi/gomega" "github.com/sclevine/spec" "github.com/sclevine/spec/report" ) func TestRunner(t *testing.T) { spec.Run(t, "Runner", testRunner, spec.Report(report.Terminal{})) } func testRunner(t *testing.T, when spec.G, it spec.S) { reset := func() { os.Unsetenv("DOLLAR") os.Unsetenv("GOFILE") os.Unsetenv("GOLINE") os.Unsetenv("GOPACKAGE") } it.Before(func() { RegisterTestingT(t) reset() log.SetFlags(log.Llongfile) }) it.After(func() { reset() }) when("counterfeiter has been invoked directly", func() { it.Before(func() { }) it("creates an invocation", func() { i, err := command.Detect(filepath.Join(".", "..", "fixtures"), []string{"counterfeiter", ".", "AliasedInterface"}, false) Expect(err).NotTo(HaveOccurred()) Expect(i).NotTo(BeNil()) Expect(i).To(HaveLen(1)) Expect(i[0].Args).To(HaveLen(3)) Expect(i[0].Args[1]).To(Equal(".")) Expect(i[0].Args[2]).To(Equal("AliasedInterface")) }) }) when("counterfeiter is invoked in generate mode", func() { it.Before(func() { os.Unsetenv("DOLLAR") os.Unsetenv("GOFILE") os.Unsetenv("GOLINE") os.Unsetenv("GOPACKAGE") }) it("creates invocations", func() { i, err := command.Detect(filepath.Join(".", "..", "fixtures"), []string{"counterfeiter", ".", "AliasedInterface"}, true) Expect(err).NotTo(HaveOccurred()) Expect(i).NotTo(BeNil()) Expect(len(i)).To(Equal(19)) Expect(i[0].File).To(Equal("aliased_interfaces.go")) Expect(i[0].Line).To(Equal(6)) Expect(i[0].Args).To(HaveLen(3)) Expect(i[0].Args[0]).To(Equal("counterfeiter")) Expect(i[0].Args[1]).To(Equal(".")) Expect(i[0].Args[2]).To(Equal("AliasedInterface")) }) }) when("counterfeiter has been invoked by go generate", func() { it.Before(func() { os.Setenv("DOLLAR", "$") os.Setenv("GOFILE", "aliased_interfaces.go") os.Setenv("GOLINE", "5") os.Setenv("GOPACKAGE", "fixtures") }) it("creates invocations but does not include generate mode as an invocation", func() { i, err := command.Detect(filepath.Join(".", "..", "fixtures"), []string{"counterfeiter", ".", "AliasedInterface"}, false) Expect(err).NotTo(HaveOccurred()) Expect(i).NotTo(BeNil()) Expect(len(i)).To(Equal(1)) Expect(i[0].File).To(Equal("aliased_interfaces.go")) Expect(i[0].Line).To(Equal(5)) Expect(i[0].Args).To(HaveLen(3)) Expect(i[0].Args[0]).To(Equal("counterfeiter")) Expect(i[0].Args[1]).To(Equal(".")) Expect(i[0].Args[2]).To(Equal("AliasedInterface")) }) }) } counterfeiter-6.12.0/fixtures/000077500000000000000000000000001505763253600163435ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/aliased_interfaces.go000066400000000000000000000005511505763253600225000ustar00rootroot00000000000000package fixtures import alias "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/another_package" //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate . AliasedInterface // AliasedInterface is an interface that embeds an interface in an aliased package. type AliasedInterface interface { alias.AnotherInterface } counterfeiter-6.12.0/fixtures/aliased_package/000077500000000000000000000000001505763253600214205ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/aliased_package/aliased_packagefakes/000077500000000000000000000000001505763253600255075ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/aliased_package/aliased_packagefakes/fake_in_aliased_package.go000066400000000000000000000053731505763253600325770ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package aliased_packagefakes import ( "sync" the_aliased_package "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/aliased_package" ) type FakeInAliasedPackage struct { StuffStub func(int) string stuffMutex sync.RWMutex stuffArgsForCall []struct { arg1 int } stuffReturns struct { result1 string } stuffReturnsOnCall map[int]struct { result1 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeInAliasedPackage) Stuff(arg1 int) string { fake.stuffMutex.Lock() ret, specificReturn := fake.stuffReturnsOnCall[len(fake.stuffArgsForCall)] fake.stuffArgsForCall = append(fake.stuffArgsForCall, struct { arg1 int }{arg1}) stub := fake.StuffStub fakeReturns := fake.stuffReturns fake.recordInvocation("Stuff", []interface{}{arg1}) fake.stuffMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeInAliasedPackage) StuffCallCount() int { fake.stuffMutex.RLock() defer fake.stuffMutex.RUnlock() return len(fake.stuffArgsForCall) } func (fake *FakeInAliasedPackage) StuffCalls(stub func(int) string) { fake.stuffMutex.Lock() defer fake.stuffMutex.Unlock() fake.StuffStub = stub } func (fake *FakeInAliasedPackage) StuffArgsForCall(i int) int { fake.stuffMutex.RLock() defer fake.stuffMutex.RUnlock() argsForCall := fake.stuffArgsForCall[i] return argsForCall.arg1 } func (fake *FakeInAliasedPackage) StuffReturns(result1 string) { fake.stuffMutex.Lock() defer fake.stuffMutex.Unlock() fake.StuffStub = nil fake.stuffReturns = struct { result1 string }{result1} } func (fake *FakeInAliasedPackage) StuffReturnsOnCall(i int, result1 string) { fake.stuffMutex.Lock() defer fake.stuffMutex.Unlock() fake.StuffStub = nil if fake.stuffReturnsOnCall == nil { fake.stuffReturnsOnCall = make(map[int]struct { result1 string }) } fake.stuffReturnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakeInAliasedPackage) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeInAliasedPackage) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ the_aliased_package.InAliasedPackage = new(FakeInAliasedPackage) counterfeiter-6.12.0/fixtures/aliased_package/in_aliased_package.go000066400000000000000000000003631505763253600255140ustar00rootroot00000000000000package the_aliased_package // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/aliased_package" //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . InAliasedPackage type InAliasedPackage interface { Stuff(int) string } counterfeiter-6.12.0/fixtures/another_package/000077500000000000000000000000001505763253600214565ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/another_package/another_packagefakes/000077500000000000000000000000001505763253600256035ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/another_package/another_packagefakes/fake_another_interface.go000066400000000000000000000066051505763253600326070ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package another_packagefakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/another_package" ) type FakeAnotherInterface struct { AnotherMethodStub func([]another_package.SomeType, map[another_package.SomeType]another_package.SomeType, *another_package.SomeType, another_package.SomeType, chan another_package.SomeType) anotherMethodMutex sync.RWMutex anotherMethodArgsForCall []struct { arg1 []another_package.SomeType arg2 map[another_package.SomeType]another_package.SomeType arg3 *another_package.SomeType arg4 another_package.SomeType arg5 chan another_package.SomeType } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeAnotherInterface) AnotherMethod(arg1 []another_package.SomeType, arg2 map[another_package.SomeType]another_package.SomeType, arg3 *another_package.SomeType, arg4 another_package.SomeType, arg5 chan another_package.SomeType) { var arg1Copy []another_package.SomeType if arg1 != nil { arg1Copy = make([]another_package.SomeType, len(arg1)) copy(arg1Copy, arg1) } fake.anotherMethodMutex.Lock() fake.anotherMethodArgsForCall = append(fake.anotherMethodArgsForCall, struct { arg1 []another_package.SomeType arg2 map[another_package.SomeType]another_package.SomeType arg3 *another_package.SomeType arg4 another_package.SomeType arg5 chan another_package.SomeType }{arg1Copy, arg2, arg3, arg4, arg5}) stub := fake.AnotherMethodStub fake.recordInvocation("AnotherMethod", []interface{}{arg1Copy, arg2, arg3, arg4, arg5}) fake.anotherMethodMutex.Unlock() if stub != nil { fake.AnotherMethodStub(arg1, arg2, arg3, arg4, arg5) } } func (fake *FakeAnotherInterface) AnotherMethodCallCount() int { fake.anotherMethodMutex.RLock() defer fake.anotherMethodMutex.RUnlock() return len(fake.anotherMethodArgsForCall) } func (fake *FakeAnotherInterface) AnotherMethodCalls(stub func([]another_package.SomeType, map[another_package.SomeType]another_package.SomeType, *another_package.SomeType, another_package.SomeType, chan another_package.SomeType)) { fake.anotherMethodMutex.Lock() defer fake.anotherMethodMutex.Unlock() fake.AnotherMethodStub = stub } func (fake *FakeAnotherInterface) AnotherMethodArgsForCall(i int) ([]another_package.SomeType, map[another_package.SomeType]another_package.SomeType, *another_package.SomeType, another_package.SomeType, chan another_package.SomeType) { fake.anotherMethodMutex.RLock() defer fake.anotherMethodMutex.RUnlock() argsForCall := fake.anotherMethodArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4, argsForCall.arg5 } func (fake *FakeAnotherInterface) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeAnotherInterface) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ another_package.AnotherInterface = new(FakeAnotherInterface) counterfeiter-6.12.0/fixtures/another_package/types.go000066400000000000000000000005051505763253600231510ustar00rootroot00000000000000package another_package // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/another_package" type SomeType int //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . AnotherInterface type AnotherInterface interface { AnotherMethod([]SomeType, map[SomeType]SomeType, *SomeType, SomeType, chan SomeType) } counterfeiter-6.12.0/fixtures/blank.go000066400000000000000000000001171505763253600177600ustar00rootroot00000000000000package fixtures // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" counterfeiter-6.12.0/fixtures/compound_return.go000066400000000000000000000001661505763253600221200ustar00rootroot00000000000000package fixtures //counterfeiter:generate . SomethingElse type SomethingElse interface { ReturnStuff() (a, b int) } counterfeiter-6.12.0/fixtures/custom_output.go000066400000000000000000000001761505763253600216300ustar00rootroot00000000000000package fixtures //counterfeiter:generate -o ./customfakesdir . CustomOutput type CustomOutput interface { CustomFolder() } counterfeiter-6.12.0/fixtures/customfakesdir/000077500000000000000000000000001505763253600213665ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/customfakesdir/fake_custom_output.go000066400000000000000000000033561505763253600256440ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package customfakesdir import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeCustomOutput struct { CustomFolderStub func() customFolderMutex sync.RWMutex customFolderArgsForCall []struct { } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeCustomOutput) CustomFolder() { fake.customFolderMutex.Lock() fake.customFolderArgsForCall = append(fake.customFolderArgsForCall, struct { }{}) stub := fake.CustomFolderStub fake.recordInvocation("CustomFolder", []interface{}{}) fake.customFolderMutex.Unlock() if stub != nil { fake.CustomFolderStub() } } func (fake *FakeCustomOutput) CustomFolderCallCount() int { fake.customFolderMutex.RLock() defer fake.customFolderMutex.RUnlock() return len(fake.customFolderArgsForCall) } func (fake *FakeCustomOutput) CustomFolderCalls(stub func()) { fake.customFolderMutex.Lock() defer fake.customFolderMutex.Unlock() fake.CustomFolderStub = stub } func (fake *FakeCustomOutput) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeCustomOutput) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.CustomOutput = new(FakeCustomOutput) counterfeiter-6.12.0/fixtures/dot_imports.go000066400000000000000000000002451505763253600212360ustar00rootroot00000000000000package fixtures import ( "io" "net/http" . "os" ) //counterfeiter:generate . DotImports type DotImports interface { DoThings(io.Writer, *File) *http.Client } counterfeiter-6.12.0/fixtures/dup_packages/000077500000000000000000000000001505763253600207715ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/dup_packages/a/000077500000000000000000000000001505763253600212115ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/dup_packages/a/a.go000066400000000000000000000004121505763253600217550ustar00rootroot00000000000000package a // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/a" import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/a/foo" //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . A type A interface { V1() foo.I } counterfeiter-6.12.0/fixtures/dup_packages/a/foo/000077500000000000000000000000001505763253600217745ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/dup_packages/a/foo/a.go000066400000000000000000000003211505763253600225370ustar00rootroot00000000000000package foo // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/a/foo" type S struct{} //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . I type I interface { FromA() S } counterfeiter-6.12.0/fixtures/dup_packages/alias.go000066400000000000000000000007401505763253600224120ustar00rootroot00000000000000package dup_packages // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages" import ( "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/a" afoo "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/a/foo" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/b/foo" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate . AliasV1 type AliasV1 interface { a.A afoo.I foo.I } counterfeiter-6.12.0/fixtures/dup_packages/b/000077500000000000000000000000001505763253600212125ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/dup_packages/b/foo/000077500000000000000000000000001505763253600217755ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/dup_packages/b/foo/b.go000066400000000000000000000003211505763253600225410ustar00rootroot00000000000000package foo // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/b/foo" type S struct{} //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . I type I interface { FromB() S } counterfeiter-6.12.0/fixtures/dup_packages/dupA.go000066400000000000000000000003631505763253600222130ustar00rootroot00000000000000package dup_packages // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages" import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/a/foo" //counterfeiter:generate . DupA type DupA interface { A() foo.S } counterfeiter-6.12.0/fixtures/dup_packages/dupAB.go000066400000000000000000000002471505763253600223160ustar00rootroot00000000000000package dup_packages // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages" //counterfeiter:generate . DupAB type DupAB interface { DupA DupB } counterfeiter-6.12.0/fixtures/dup_packages/dupB.go000066400000000000000000000003631505763253600222140ustar00rootroot00000000000000package dup_packages // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages" import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/b/foo" //counterfeiter:generate . DupB type DupB interface { B() foo.S } counterfeiter-6.12.0/fixtures/dup_packages/dup_packagenames.go000066400000000000000000000005341505763253600246110ustar00rootroot00000000000000package dup_packages // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages" import ( "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/a/foo" bfoo "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/b/foo" ) //counterfeiter:generate . AB type AB interface { A() foo.S foo.I B() bfoo.S bfoo.I } counterfeiter-6.12.0/fixtures/dup_packages/foo/000077500000000000000000000000001505763253600215545ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/dup_packages/foo/multi_import.go000066400000000000000000000006121505763253600246260ustar00rootroot00000000000000package foo // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/foo" import ( "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/a/foo" bfoo "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/b/foo" ) type S struct{} //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . MultiAB type MultiAB interface { Mine() S foo.I bfoo.I } counterfeiter-6.12.0/fixtures/dup_packages/go.mod000066400000000000000000000001171505763253600220760ustar00rootroot00000000000000module github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages go 1.22 counterfeiter-6.12.0/fixtures/embeds_interfaces.go000066400000000000000000000005151505763253600223350ustar00rootroot00000000000000package fixtures import ( "net/http" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/another_package" ) //counterfeiter:generate . EmbedsInterfaces type EmbedsInterfaces interface { http.Handler another_package.AnotherInterface InterfaceToEmbed DoThings() } type InterfaceToEmbed interface { EmbeddedMethod() string } counterfeiter-6.12.0/fixtures/externalpkg/000077500000000000000000000000001505763253600206675ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/externalpkg/aliased_interface.go000066400000000000000000000002741505763253600246430ustar00rootroot00000000000000package externalpkg //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate github.com/maxbrunsfeld/counterfeiter/v6/fixtures/internalpkg.Context counterfeiter-6.12.0/fixtures/externalpkg/externalpkgfakes/000077500000000000000000000000001505763253600242255ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/externalpkg/externalpkgfakes/fake_context.go000066400000000000000000000033041505763253600272260ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package externalpkgfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/internalpkg" ) type FakeContext struct { DoSomethingStub func() doSomethingMutex sync.RWMutex doSomethingArgsForCall []struct { } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeContext) DoSomething() { fake.doSomethingMutex.Lock() fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { }{}) stub := fake.DoSomethingStub fake.recordInvocation("DoSomething", []interface{}{}) fake.doSomethingMutex.Unlock() if stub != nil { fake.DoSomethingStub() } } func (fake *FakeContext) DoSomethingCallCount() int { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() return len(fake.doSomethingArgsForCall) } func (fake *FakeContext) DoSomethingCalls(stub func()) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = stub } func (fake *FakeContext) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeContext) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ internalpkg.Context = new(FakeContext) counterfeiter-6.12.0/fixtures/fixturesfakes/000077500000000000000000000000001505763253600212265ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/fixturesfakes/fake_aliased_interface.go000066400000000000000000000066541505763253600262000ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/another_package" ) type FakeAliasedInterface struct { AnotherMethodStub func([]another_package.SomeType, map[another_package.SomeType]another_package.SomeType, *another_package.SomeType, another_package.SomeType, chan another_package.SomeType) anotherMethodMutex sync.RWMutex anotherMethodArgsForCall []struct { arg1 []another_package.SomeType arg2 map[another_package.SomeType]another_package.SomeType arg3 *another_package.SomeType arg4 another_package.SomeType arg5 chan another_package.SomeType } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeAliasedInterface) AnotherMethod(arg1 []another_package.SomeType, arg2 map[another_package.SomeType]another_package.SomeType, arg3 *another_package.SomeType, arg4 another_package.SomeType, arg5 chan another_package.SomeType) { var arg1Copy []another_package.SomeType if arg1 != nil { arg1Copy = make([]another_package.SomeType, len(arg1)) copy(arg1Copy, arg1) } fake.anotherMethodMutex.Lock() fake.anotherMethodArgsForCall = append(fake.anotherMethodArgsForCall, struct { arg1 []another_package.SomeType arg2 map[another_package.SomeType]another_package.SomeType arg3 *another_package.SomeType arg4 another_package.SomeType arg5 chan another_package.SomeType }{arg1Copy, arg2, arg3, arg4, arg5}) stub := fake.AnotherMethodStub fake.recordInvocation("AnotherMethod", []interface{}{arg1Copy, arg2, arg3, arg4, arg5}) fake.anotherMethodMutex.Unlock() if stub != nil { fake.AnotherMethodStub(arg1, arg2, arg3, arg4, arg5) } } func (fake *FakeAliasedInterface) AnotherMethodCallCount() int { fake.anotherMethodMutex.RLock() defer fake.anotherMethodMutex.RUnlock() return len(fake.anotherMethodArgsForCall) } func (fake *FakeAliasedInterface) AnotherMethodCalls(stub func([]another_package.SomeType, map[another_package.SomeType]another_package.SomeType, *another_package.SomeType, another_package.SomeType, chan another_package.SomeType)) { fake.anotherMethodMutex.Lock() defer fake.anotherMethodMutex.Unlock() fake.AnotherMethodStub = stub } func (fake *FakeAliasedInterface) AnotherMethodArgsForCall(i int) ([]another_package.SomeType, map[another_package.SomeType]another_package.SomeType, *another_package.SomeType, another_package.SomeType, chan another_package.SomeType) { fake.anotherMethodMutex.RLock() defer fake.anotherMethodMutex.RUnlock() argsForCall := fake.anotherMethodArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4, argsForCall.arg5 } func (fake *FakeAliasedInterface) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeAliasedInterface) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.AliasedInterface = new(FakeAliasedInterface) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_dot_imports.go000066400000000000000000000057431505763253600251170ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "io" "net/http" "os" "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeDotImports struct { DoThingsStub func(io.Writer, *os.File) *http.Client doThingsMutex sync.RWMutex doThingsArgsForCall []struct { arg1 io.Writer arg2 *os.File } doThingsReturns struct { result1 *http.Client } doThingsReturnsOnCall map[int]struct { result1 *http.Client } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeDotImports) DoThings(arg1 io.Writer, arg2 *os.File) *http.Client { fake.doThingsMutex.Lock() ret, specificReturn := fake.doThingsReturnsOnCall[len(fake.doThingsArgsForCall)] fake.doThingsArgsForCall = append(fake.doThingsArgsForCall, struct { arg1 io.Writer arg2 *os.File }{arg1, arg2}) stub := fake.DoThingsStub fakeReturns := fake.doThingsReturns fake.recordInvocation("DoThings", []interface{}{arg1, arg2}) fake.doThingsMutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeDotImports) DoThingsCallCount() int { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() return len(fake.doThingsArgsForCall) } func (fake *FakeDotImports) DoThingsCalls(stub func(io.Writer, *os.File) *http.Client) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = stub } func (fake *FakeDotImports) DoThingsArgsForCall(i int) (io.Writer, *os.File) { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() argsForCall := fake.doThingsArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeDotImports) DoThingsReturns(result1 *http.Client) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil fake.doThingsReturns = struct { result1 *http.Client }{result1} } func (fake *FakeDotImports) DoThingsReturnsOnCall(i int, result1 *http.Client) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil if fake.doThingsReturnsOnCall == nil { fake.doThingsReturnsOnCall = make(map[int]struct { result1 *http.Client }) } fake.doThingsReturnsOnCall[i] = struct { result1 *http.Client }{result1} } func (fake *FakeDotImports) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeDotImports) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.DotImports = new(FakeDotImports) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_embeds_interfaces.go000066400000000000000000000161731505763253600262150ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "net/http" "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/another_package" ) type FakeEmbedsInterfaces struct { AnotherMethodStub func([]another_package.SomeType, map[another_package.SomeType]another_package.SomeType, *another_package.SomeType, another_package.SomeType, chan another_package.SomeType) anotherMethodMutex sync.RWMutex anotherMethodArgsForCall []struct { arg1 []another_package.SomeType arg2 map[another_package.SomeType]another_package.SomeType arg3 *another_package.SomeType arg4 another_package.SomeType arg5 chan another_package.SomeType } DoThingsStub func() doThingsMutex sync.RWMutex doThingsArgsForCall []struct { } EmbeddedMethodStub func() string embeddedMethodMutex sync.RWMutex embeddedMethodArgsForCall []struct { } embeddedMethodReturns struct { result1 string } embeddedMethodReturnsOnCall map[int]struct { result1 string } ServeHTTPStub func(http.ResponseWriter, *http.Request) serveHTTPMutex sync.RWMutex serveHTTPArgsForCall []struct { arg1 http.ResponseWriter arg2 *http.Request } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeEmbedsInterfaces) AnotherMethod(arg1 []another_package.SomeType, arg2 map[another_package.SomeType]another_package.SomeType, arg3 *another_package.SomeType, arg4 another_package.SomeType, arg5 chan another_package.SomeType) { var arg1Copy []another_package.SomeType if arg1 != nil { arg1Copy = make([]another_package.SomeType, len(arg1)) copy(arg1Copy, arg1) } fake.anotherMethodMutex.Lock() fake.anotherMethodArgsForCall = append(fake.anotherMethodArgsForCall, struct { arg1 []another_package.SomeType arg2 map[another_package.SomeType]another_package.SomeType arg3 *another_package.SomeType arg4 another_package.SomeType arg5 chan another_package.SomeType }{arg1Copy, arg2, arg3, arg4, arg5}) stub := fake.AnotherMethodStub fake.recordInvocation("AnotherMethod", []interface{}{arg1Copy, arg2, arg3, arg4, arg5}) fake.anotherMethodMutex.Unlock() if stub != nil { fake.AnotherMethodStub(arg1, arg2, arg3, arg4, arg5) } } func (fake *FakeEmbedsInterfaces) AnotherMethodCallCount() int { fake.anotherMethodMutex.RLock() defer fake.anotherMethodMutex.RUnlock() return len(fake.anotherMethodArgsForCall) } func (fake *FakeEmbedsInterfaces) AnotherMethodCalls(stub func([]another_package.SomeType, map[another_package.SomeType]another_package.SomeType, *another_package.SomeType, another_package.SomeType, chan another_package.SomeType)) { fake.anotherMethodMutex.Lock() defer fake.anotherMethodMutex.Unlock() fake.AnotherMethodStub = stub } func (fake *FakeEmbedsInterfaces) AnotherMethodArgsForCall(i int) ([]another_package.SomeType, map[another_package.SomeType]another_package.SomeType, *another_package.SomeType, another_package.SomeType, chan another_package.SomeType) { fake.anotherMethodMutex.RLock() defer fake.anotherMethodMutex.RUnlock() argsForCall := fake.anotherMethodArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4, argsForCall.arg5 } func (fake *FakeEmbedsInterfaces) DoThings() { fake.doThingsMutex.Lock() fake.doThingsArgsForCall = append(fake.doThingsArgsForCall, struct { }{}) stub := fake.DoThingsStub fake.recordInvocation("DoThings", []interface{}{}) fake.doThingsMutex.Unlock() if stub != nil { fake.DoThingsStub() } } func (fake *FakeEmbedsInterfaces) DoThingsCallCount() int { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() return len(fake.doThingsArgsForCall) } func (fake *FakeEmbedsInterfaces) DoThingsCalls(stub func()) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = stub } func (fake *FakeEmbedsInterfaces) EmbeddedMethod() string { fake.embeddedMethodMutex.Lock() ret, specificReturn := fake.embeddedMethodReturnsOnCall[len(fake.embeddedMethodArgsForCall)] fake.embeddedMethodArgsForCall = append(fake.embeddedMethodArgsForCall, struct { }{}) stub := fake.EmbeddedMethodStub fakeReturns := fake.embeddedMethodReturns fake.recordInvocation("EmbeddedMethod", []interface{}{}) fake.embeddedMethodMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeEmbedsInterfaces) EmbeddedMethodCallCount() int { fake.embeddedMethodMutex.RLock() defer fake.embeddedMethodMutex.RUnlock() return len(fake.embeddedMethodArgsForCall) } func (fake *FakeEmbedsInterfaces) EmbeddedMethodCalls(stub func() string) { fake.embeddedMethodMutex.Lock() defer fake.embeddedMethodMutex.Unlock() fake.EmbeddedMethodStub = stub } func (fake *FakeEmbedsInterfaces) EmbeddedMethodReturns(result1 string) { fake.embeddedMethodMutex.Lock() defer fake.embeddedMethodMutex.Unlock() fake.EmbeddedMethodStub = nil fake.embeddedMethodReturns = struct { result1 string }{result1} } func (fake *FakeEmbedsInterfaces) EmbeddedMethodReturnsOnCall(i int, result1 string) { fake.embeddedMethodMutex.Lock() defer fake.embeddedMethodMutex.Unlock() fake.EmbeddedMethodStub = nil if fake.embeddedMethodReturnsOnCall == nil { fake.embeddedMethodReturnsOnCall = make(map[int]struct { result1 string }) } fake.embeddedMethodReturnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakeEmbedsInterfaces) ServeHTTP(arg1 http.ResponseWriter, arg2 *http.Request) { fake.serveHTTPMutex.Lock() fake.serveHTTPArgsForCall = append(fake.serveHTTPArgsForCall, struct { arg1 http.ResponseWriter arg2 *http.Request }{arg1, arg2}) stub := fake.ServeHTTPStub fake.recordInvocation("ServeHTTP", []interface{}{arg1, arg2}) fake.serveHTTPMutex.Unlock() if stub != nil { fake.ServeHTTPStub(arg1, arg2) } } func (fake *FakeEmbedsInterfaces) ServeHTTPCallCount() int { fake.serveHTTPMutex.RLock() defer fake.serveHTTPMutex.RUnlock() return len(fake.serveHTTPArgsForCall) } func (fake *FakeEmbedsInterfaces) ServeHTTPCalls(stub func(http.ResponseWriter, *http.Request)) { fake.serveHTTPMutex.Lock() defer fake.serveHTTPMutex.Unlock() fake.ServeHTTPStub = stub } func (fake *FakeEmbedsInterfaces) ServeHTTPArgsForCall(i int) (http.ResponseWriter, *http.Request) { fake.serveHTTPMutex.RLock() defer fake.serveHTTPMutex.RUnlock() argsForCall := fake.serveHTTPArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeEmbedsInterfaces) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeEmbedsInterfaces) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.EmbedsInterfaces = new(FakeEmbedsInterfaces) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_first_interface.go000066400000000000000000000032611505763253600257140ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeFirstInterface struct { DoThingsStub func() doThingsMutex sync.RWMutex doThingsArgsForCall []struct { } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeFirstInterface) DoThings() { fake.doThingsMutex.Lock() fake.doThingsArgsForCall = append(fake.doThingsArgsForCall, struct { }{}) stub := fake.DoThingsStub fake.recordInvocation("DoThings", []interface{}{}) fake.doThingsMutex.Unlock() if stub != nil { fake.DoThingsStub() } } func (fake *FakeFirstInterface) DoThingsCallCount() int { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() return len(fake.doThingsArgsForCall) } func (fake *FakeFirstInterface) DoThingsCalls(stub func()) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = stub } func (fake *FakeFirstInterface) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeFirstInterface) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.FirstInterface = new(FakeFirstInterface) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_has_imports.go000066400000000000000000000057431505763253600251040ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "io" "net/http" "os" "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeHasImports struct { DoThingsStub func(io.Writer, *os.File) *http.Client doThingsMutex sync.RWMutex doThingsArgsForCall []struct { arg1 io.Writer arg2 *os.File } doThingsReturns struct { result1 *http.Client } doThingsReturnsOnCall map[int]struct { result1 *http.Client } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeHasImports) DoThings(arg1 io.Writer, arg2 *os.File) *http.Client { fake.doThingsMutex.Lock() ret, specificReturn := fake.doThingsReturnsOnCall[len(fake.doThingsArgsForCall)] fake.doThingsArgsForCall = append(fake.doThingsArgsForCall, struct { arg1 io.Writer arg2 *os.File }{arg1, arg2}) stub := fake.DoThingsStub fakeReturns := fake.doThingsReturns fake.recordInvocation("DoThings", []interface{}{arg1, arg2}) fake.doThingsMutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeHasImports) DoThingsCallCount() int { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() return len(fake.doThingsArgsForCall) } func (fake *FakeHasImports) DoThingsCalls(stub func(io.Writer, *os.File) *http.Client) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = stub } func (fake *FakeHasImports) DoThingsArgsForCall(i int) (io.Writer, *os.File) { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() argsForCall := fake.doThingsArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeHasImports) DoThingsReturns(result1 *http.Client) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil fake.doThingsReturns = struct { result1 *http.Client }{result1} } func (fake *FakeHasImports) DoThingsReturnsOnCall(i int, result1 *http.Client) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil if fake.doThingsReturnsOnCall == nil { fake.doThingsReturnsOnCall = make(map[int]struct { result1 *http.Client }) } fake.doThingsReturnsOnCall[i] = struct { result1 *http.Client }{result1} } func (fake *FakeHasImports) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeHasImports) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.HasImports = new(FakeHasImports) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_has_other_types.go000066400000000000000000000057471505763253600257600ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeHasOtherTypes struct { GetThingStub func(fixtures.SomeString) fixtures.SomeFunc getThingMutex sync.RWMutex getThingArgsForCall []struct { arg1 fixtures.SomeString } getThingReturns struct { result1 fixtures.SomeFunc } getThingReturnsOnCall map[int]struct { result1 fixtures.SomeFunc } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeHasOtherTypes) GetThing(arg1 fixtures.SomeString) fixtures.SomeFunc { fake.getThingMutex.Lock() ret, specificReturn := fake.getThingReturnsOnCall[len(fake.getThingArgsForCall)] fake.getThingArgsForCall = append(fake.getThingArgsForCall, struct { arg1 fixtures.SomeString }{arg1}) stub := fake.GetThingStub fakeReturns := fake.getThingReturns fake.recordInvocation("GetThing", []interface{}{arg1}) fake.getThingMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeHasOtherTypes) GetThingCallCount() int { fake.getThingMutex.RLock() defer fake.getThingMutex.RUnlock() return len(fake.getThingArgsForCall) } func (fake *FakeHasOtherTypes) GetThingCalls(stub func(fixtures.SomeString) fixtures.SomeFunc) { fake.getThingMutex.Lock() defer fake.getThingMutex.Unlock() fake.GetThingStub = stub } func (fake *FakeHasOtherTypes) GetThingArgsForCall(i int) fixtures.SomeString { fake.getThingMutex.RLock() defer fake.getThingMutex.RUnlock() argsForCall := fake.getThingArgsForCall[i] return argsForCall.arg1 } func (fake *FakeHasOtherTypes) GetThingReturns(result1 fixtures.SomeFunc) { fake.getThingMutex.Lock() defer fake.getThingMutex.Unlock() fake.GetThingStub = nil fake.getThingReturns = struct { result1 fixtures.SomeFunc }{result1} } func (fake *FakeHasOtherTypes) GetThingReturnsOnCall(i int, result1 fixtures.SomeFunc) { fake.getThingMutex.Lock() defer fake.getThingMutex.Unlock() fake.GetThingStub = nil if fake.getThingReturnsOnCall == nil { fake.getThingReturnsOnCall = make(map[int]struct { result1 fixtures.SomeFunc }) } fake.getThingReturnsOnCall[i] = struct { result1 fixtures.SomeFunc }{result1} } func (fake *FakeHasOtherTypes) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeHasOtherTypes) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.HasOtherTypes = new(FakeHasOtherTypes) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_has_var_args.go000066400000000000000000000117021505763253600252030ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeHasVarArgs struct { DoMoreThingsStub func(int, int, ...string) int doMoreThingsMutex sync.RWMutex doMoreThingsArgsForCall []struct { arg1 int arg2 int arg3 []string } doMoreThingsReturns struct { result1 int } doMoreThingsReturnsOnCall map[int]struct { result1 int } DoThingsStub func(int, ...string) int doThingsMutex sync.RWMutex doThingsArgsForCall []struct { arg1 int arg2 []string } doThingsReturns struct { result1 int } doThingsReturnsOnCall map[int]struct { result1 int } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeHasVarArgs) DoMoreThings(arg1 int, arg2 int, arg3 ...string) int { fake.doMoreThingsMutex.Lock() ret, specificReturn := fake.doMoreThingsReturnsOnCall[len(fake.doMoreThingsArgsForCall)] fake.doMoreThingsArgsForCall = append(fake.doMoreThingsArgsForCall, struct { arg1 int arg2 int arg3 []string }{arg1, arg2, arg3}) stub := fake.DoMoreThingsStub fakeReturns := fake.doMoreThingsReturns fake.recordInvocation("DoMoreThings", []interface{}{arg1, arg2, arg3}) fake.doMoreThingsMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3...) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeHasVarArgs) DoMoreThingsCallCount() int { fake.doMoreThingsMutex.RLock() defer fake.doMoreThingsMutex.RUnlock() return len(fake.doMoreThingsArgsForCall) } func (fake *FakeHasVarArgs) DoMoreThingsCalls(stub func(int, int, ...string) int) { fake.doMoreThingsMutex.Lock() defer fake.doMoreThingsMutex.Unlock() fake.DoMoreThingsStub = stub } func (fake *FakeHasVarArgs) DoMoreThingsArgsForCall(i int) (int, int, []string) { fake.doMoreThingsMutex.RLock() defer fake.doMoreThingsMutex.RUnlock() argsForCall := fake.doMoreThingsArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 } func (fake *FakeHasVarArgs) DoMoreThingsReturns(result1 int) { fake.doMoreThingsMutex.Lock() defer fake.doMoreThingsMutex.Unlock() fake.DoMoreThingsStub = nil fake.doMoreThingsReturns = struct { result1 int }{result1} } func (fake *FakeHasVarArgs) DoMoreThingsReturnsOnCall(i int, result1 int) { fake.doMoreThingsMutex.Lock() defer fake.doMoreThingsMutex.Unlock() fake.DoMoreThingsStub = nil if fake.doMoreThingsReturnsOnCall == nil { fake.doMoreThingsReturnsOnCall = make(map[int]struct { result1 int }) } fake.doMoreThingsReturnsOnCall[i] = struct { result1 int }{result1} } func (fake *FakeHasVarArgs) DoThings(arg1 int, arg2 ...string) int { fake.doThingsMutex.Lock() ret, specificReturn := fake.doThingsReturnsOnCall[len(fake.doThingsArgsForCall)] fake.doThingsArgsForCall = append(fake.doThingsArgsForCall, struct { arg1 int arg2 []string }{arg1, arg2}) stub := fake.DoThingsStub fakeReturns := fake.doThingsReturns fake.recordInvocation("DoThings", []interface{}{arg1, arg2}) fake.doThingsMutex.Unlock() if stub != nil { return stub(arg1, arg2...) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeHasVarArgs) DoThingsCallCount() int { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() return len(fake.doThingsArgsForCall) } func (fake *FakeHasVarArgs) DoThingsCalls(stub func(int, ...string) int) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = stub } func (fake *FakeHasVarArgs) DoThingsArgsForCall(i int) (int, []string) { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() argsForCall := fake.doThingsArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeHasVarArgs) DoThingsReturns(result1 int) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil fake.doThingsReturns = struct { result1 int }{result1} } func (fake *FakeHasVarArgs) DoThingsReturnsOnCall(i int, result1 int) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil if fake.doThingsReturnsOnCall == nil { fake.doThingsReturnsOnCall = make(map[int]struct { result1 int }) } fake.doThingsReturnsOnCall[i] = struct { result1 int }{result1} } func (fake *FakeHasVarArgs) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeHasVarArgs) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.HasVarArgs = new(FakeHasVarArgs) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_has_var_args_with_local_types.go000066400000000000000000000041601505763253600306340ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeHasVarArgsWithLocalTypes struct { DoThingsStub func(...fixtures.LocalType) doThingsMutex sync.RWMutex doThingsArgsForCall []struct { arg1 []fixtures.LocalType } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeHasVarArgsWithLocalTypes) DoThings(arg1 ...fixtures.LocalType) { fake.doThingsMutex.Lock() fake.doThingsArgsForCall = append(fake.doThingsArgsForCall, struct { arg1 []fixtures.LocalType }{arg1}) stub := fake.DoThingsStub fake.recordInvocation("DoThings", []interface{}{arg1}) fake.doThingsMutex.Unlock() if stub != nil { fake.DoThingsStub(arg1...) } } func (fake *FakeHasVarArgsWithLocalTypes) DoThingsCallCount() int { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() return len(fake.doThingsArgsForCall) } func (fake *FakeHasVarArgsWithLocalTypes) DoThingsCalls(stub func(...fixtures.LocalType)) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = stub } func (fake *FakeHasVarArgsWithLocalTypes) DoThingsArgsForCall(i int) []fixtures.LocalType { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() argsForCall := fake.doThingsArgsForCall[i] return argsForCall.arg1 } func (fake *FakeHasVarArgsWithLocalTypes) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeHasVarArgsWithLocalTypes) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.HasVarArgsWithLocalTypes = new(FakeHasVarArgsWithLocalTypes) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_imports_go_hyphen_package.go000066400000000000000000000044671505763253600277660ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" hyphenpackage "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/go-hyphenpackage" ) type FakeImportsGoHyphenPackage struct { UseHyphenTypeStub func(hyphenpackage.HyphenType) useHyphenTypeMutex sync.RWMutex useHyphenTypeArgsForCall []struct { arg1 hyphenpackage.HyphenType } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeImportsGoHyphenPackage) UseHyphenType(arg1 hyphenpackage.HyphenType) { fake.useHyphenTypeMutex.Lock() fake.useHyphenTypeArgsForCall = append(fake.useHyphenTypeArgsForCall, struct { arg1 hyphenpackage.HyphenType }{arg1}) stub := fake.UseHyphenTypeStub fake.recordInvocation("UseHyphenType", []interface{}{arg1}) fake.useHyphenTypeMutex.Unlock() if stub != nil { fake.UseHyphenTypeStub(arg1) } } func (fake *FakeImportsGoHyphenPackage) UseHyphenTypeCallCount() int { fake.useHyphenTypeMutex.RLock() defer fake.useHyphenTypeMutex.RUnlock() return len(fake.useHyphenTypeArgsForCall) } func (fake *FakeImportsGoHyphenPackage) UseHyphenTypeCalls(stub func(hyphenpackage.HyphenType)) { fake.useHyphenTypeMutex.Lock() defer fake.useHyphenTypeMutex.Unlock() fake.UseHyphenTypeStub = stub } func (fake *FakeImportsGoHyphenPackage) UseHyphenTypeArgsForCall(i int) hyphenpackage.HyphenType { fake.useHyphenTypeMutex.RLock() defer fake.useHyphenTypeMutex.RUnlock() argsForCall := fake.useHyphenTypeArgsForCall[i] return argsForCall.arg1 } func (fake *FakeImportsGoHyphenPackage) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeImportsGoHyphenPackage) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.ImportsGoHyphenPackage = new(FakeImportsGoHyphenPackage) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_inline_struct_params.go000066400000000000000000000100301505763253600267620ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "context" "net/http" "sync" "time" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeInlineStructParams struct { DoSomethingStub func(context.Context, struct { SomeString string SomeStringPointer *string SomeTime time.Time SomeTimePointer *time.Time HTTPRequest http.Request }) error doSomethingMutex sync.RWMutex doSomethingArgsForCall []struct { arg1 context.Context arg2 struct { SomeString string SomeStringPointer *string SomeTime time.Time SomeTimePointer *time.Time HTTPRequest http.Request } } doSomethingReturns struct { result1 error } doSomethingReturnsOnCall map[int]struct { result1 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeInlineStructParams) DoSomething(arg1 context.Context, arg2 struct { SomeString string SomeStringPointer *string SomeTime time.Time SomeTimePointer *time.Time HTTPRequest http.Request }) error { fake.doSomethingMutex.Lock() ret, specificReturn := fake.doSomethingReturnsOnCall[len(fake.doSomethingArgsForCall)] fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { arg1 context.Context arg2 struct { SomeString string SomeStringPointer *string SomeTime time.Time SomeTimePointer *time.Time HTTPRequest http.Request } }{arg1, arg2}) stub := fake.DoSomethingStub fakeReturns := fake.doSomethingReturns fake.recordInvocation("DoSomething", []interface{}{arg1, arg2}) fake.doSomethingMutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeInlineStructParams) DoSomethingCallCount() int { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() return len(fake.doSomethingArgsForCall) } func (fake *FakeInlineStructParams) DoSomethingCalls(stub func(context.Context, struct { SomeString string SomeStringPointer *string SomeTime time.Time SomeTimePointer *time.Time HTTPRequest http.Request }) error) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = stub } func (fake *FakeInlineStructParams) DoSomethingArgsForCall(i int) (context.Context, struct { SomeString string SomeStringPointer *string SomeTime time.Time SomeTimePointer *time.Time HTTPRequest http.Request }) { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() argsForCall := fake.doSomethingArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeInlineStructParams) DoSomethingReturns(result1 error) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = nil fake.doSomethingReturns = struct { result1 error }{result1} } func (fake *FakeInlineStructParams) DoSomethingReturnsOnCall(i int, result1 error) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = nil if fake.doSomethingReturnsOnCall == nil { fake.doSomethingReturnsOnCall = make(map[int]struct { result1 error }) } fake.doSomethingReturnsOnCall[i] = struct { result1 error }{result1} } func (fake *FakeInlineStructParams) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeInlineStructParams) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.InlineStructParams = new(FakeInlineStructParams) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_reuses_arg_types.go000066400000000000000000000040431505763253600261270ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeReusesArgTypes struct { DoThingsStub func(string, string) doThingsMutex sync.RWMutex doThingsArgsForCall []struct { arg1 string arg2 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeReusesArgTypes) DoThings(arg1 string, arg2 string) { fake.doThingsMutex.Lock() fake.doThingsArgsForCall = append(fake.doThingsArgsForCall, struct { arg1 string arg2 string }{arg1, arg2}) stub := fake.DoThingsStub fake.recordInvocation("DoThings", []interface{}{arg1, arg2}) fake.doThingsMutex.Unlock() if stub != nil { fake.DoThingsStub(arg1, arg2) } } func (fake *FakeReusesArgTypes) DoThingsCallCount() int { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() return len(fake.doThingsArgsForCall) } func (fake *FakeReusesArgTypes) DoThingsCalls(stub func(string, string)) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = stub } func (fake *FakeReusesArgTypes) DoThingsArgsForCall(i int) (string, string) { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() argsForCall := fake.doThingsArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeReusesArgTypes) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeReusesArgTypes) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.ReusesArgTypes = new(FakeReusesArgTypes) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_second_interface.go000066400000000000000000000054071505763253600260440ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeSecondInterface struct { EmbeddedMethodStub func() string embeddedMethodMutex sync.RWMutex embeddedMethodArgsForCall []struct { } embeddedMethodReturns struct { result1 string } embeddedMethodReturnsOnCall map[int]struct { result1 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeSecondInterface) EmbeddedMethod() string { fake.embeddedMethodMutex.Lock() ret, specificReturn := fake.embeddedMethodReturnsOnCall[len(fake.embeddedMethodArgsForCall)] fake.embeddedMethodArgsForCall = append(fake.embeddedMethodArgsForCall, struct { }{}) stub := fake.EmbeddedMethodStub fakeReturns := fake.embeddedMethodReturns fake.recordInvocation("EmbeddedMethod", []interface{}{}) fake.embeddedMethodMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeSecondInterface) EmbeddedMethodCallCount() int { fake.embeddedMethodMutex.RLock() defer fake.embeddedMethodMutex.RUnlock() return len(fake.embeddedMethodArgsForCall) } func (fake *FakeSecondInterface) EmbeddedMethodCalls(stub func() string) { fake.embeddedMethodMutex.Lock() defer fake.embeddedMethodMutex.Unlock() fake.EmbeddedMethodStub = stub } func (fake *FakeSecondInterface) EmbeddedMethodReturns(result1 string) { fake.embeddedMethodMutex.Lock() defer fake.embeddedMethodMutex.Unlock() fake.EmbeddedMethodStub = nil fake.embeddedMethodReturns = struct { result1 string }{result1} } func (fake *FakeSecondInterface) EmbeddedMethodReturnsOnCall(i int, result1 string) { fake.embeddedMethodMutex.Lock() defer fake.embeddedMethodMutex.Unlock() fake.EmbeddedMethodStub = nil if fake.embeddedMethodReturnsOnCall == nil { fake.embeddedMethodReturnsOnCall = make(map[int]struct { result1 string }) } fake.embeddedMethodReturnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakeSecondInterface) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeSecondInterface) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.SecondInterface = new(FakeSecondInterface) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_something.go000066400000000000000000000133411505763253600245420ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeSomething struct { DoASliceStub func([]byte) doASliceMutex sync.RWMutex doASliceArgsForCall []struct { arg1 []byte } DoAnArrayStub func([4]byte) doAnArrayMutex sync.RWMutex doAnArrayArgsForCall []struct { arg1 [4]byte } DoNothingStub func() doNothingMutex sync.RWMutex doNothingArgsForCall []struct { } DoThingsStub func(string, uint64) (int, error) doThingsMutex sync.RWMutex doThingsArgsForCall []struct { arg1 string arg2 uint64 } doThingsReturns struct { result1 int result2 error } doThingsReturnsOnCall map[int]struct { result1 int result2 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeSomething) DoASlice(arg1 []byte) { var arg1Copy []byte if arg1 != nil { arg1Copy = make([]byte, len(arg1)) copy(arg1Copy, arg1) } fake.doASliceMutex.Lock() fake.doASliceArgsForCall = append(fake.doASliceArgsForCall, struct { arg1 []byte }{arg1Copy}) stub := fake.DoASliceStub fake.recordInvocation("DoASlice", []interface{}{arg1Copy}) fake.doASliceMutex.Unlock() if stub != nil { fake.DoASliceStub(arg1) } } func (fake *FakeSomething) DoASliceCallCount() int { fake.doASliceMutex.RLock() defer fake.doASliceMutex.RUnlock() return len(fake.doASliceArgsForCall) } func (fake *FakeSomething) DoASliceCalls(stub func([]byte)) { fake.doASliceMutex.Lock() defer fake.doASliceMutex.Unlock() fake.DoASliceStub = stub } func (fake *FakeSomething) DoASliceArgsForCall(i int) []byte { fake.doASliceMutex.RLock() defer fake.doASliceMutex.RUnlock() argsForCall := fake.doASliceArgsForCall[i] return argsForCall.arg1 } func (fake *FakeSomething) DoAnArray(arg1 [4]byte) { fake.doAnArrayMutex.Lock() fake.doAnArrayArgsForCall = append(fake.doAnArrayArgsForCall, struct { arg1 [4]byte }{arg1}) stub := fake.DoAnArrayStub fake.recordInvocation("DoAnArray", []interface{}{arg1}) fake.doAnArrayMutex.Unlock() if stub != nil { fake.DoAnArrayStub(arg1) } } func (fake *FakeSomething) DoAnArrayCallCount() int { fake.doAnArrayMutex.RLock() defer fake.doAnArrayMutex.RUnlock() return len(fake.doAnArrayArgsForCall) } func (fake *FakeSomething) DoAnArrayCalls(stub func([4]byte)) { fake.doAnArrayMutex.Lock() defer fake.doAnArrayMutex.Unlock() fake.DoAnArrayStub = stub } func (fake *FakeSomething) DoAnArrayArgsForCall(i int) [4]byte { fake.doAnArrayMutex.RLock() defer fake.doAnArrayMutex.RUnlock() argsForCall := fake.doAnArrayArgsForCall[i] return argsForCall.arg1 } func (fake *FakeSomething) DoNothing() { fake.doNothingMutex.Lock() fake.doNothingArgsForCall = append(fake.doNothingArgsForCall, struct { }{}) stub := fake.DoNothingStub fake.recordInvocation("DoNothing", []interface{}{}) fake.doNothingMutex.Unlock() if stub != nil { fake.DoNothingStub() } } func (fake *FakeSomething) DoNothingCallCount() int { fake.doNothingMutex.RLock() defer fake.doNothingMutex.RUnlock() return len(fake.doNothingArgsForCall) } func (fake *FakeSomething) DoNothingCalls(stub func()) { fake.doNothingMutex.Lock() defer fake.doNothingMutex.Unlock() fake.DoNothingStub = stub } func (fake *FakeSomething) DoThings(arg1 string, arg2 uint64) (int, error) { fake.doThingsMutex.Lock() ret, specificReturn := fake.doThingsReturnsOnCall[len(fake.doThingsArgsForCall)] fake.doThingsArgsForCall = append(fake.doThingsArgsForCall, struct { arg1 string arg2 uint64 }{arg1, arg2}) stub := fake.DoThingsStub fakeReturns := fake.doThingsReturns fake.recordInvocation("DoThings", []interface{}{arg1, arg2}) fake.doThingsMutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1, ret.result2 } return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeSomething) DoThingsCallCount() int { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() return len(fake.doThingsArgsForCall) } func (fake *FakeSomething) DoThingsCalls(stub func(string, uint64) (int, error)) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = stub } func (fake *FakeSomething) DoThingsArgsForCall(i int) (string, uint64) { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() argsForCall := fake.doThingsArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeSomething) DoThingsReturns(result1 int, result2 error) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil fake.doThingsReturns = struct { result1 int result2 error }{result1, result2} } func (fake *FakeSomething) DoThingsReturnsOnCall(i int, result1 int, result2 error) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil if fake.doThingsReturnsOnCall == nil { fake.doThingsReturnsOnCall = make(map[int]struct { result1 int result2 error }) } fake.doThingsReturnsOnCall[i] = struct { result1 int result2 error }{result1, result2} } func (fake *FakeSomething) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeSomething) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.Something = new(FakeSomething) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_something_else.go000066400000000000000000000054261505763253600255570ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeSomethingElse struct { ReturnStuffStub func() (int, int) returnStuffMutex sync.RWMutex returnStuffArgsForCall []struct { } returnStuffReturns struct { result1 int result2 int } returnStuffReturnsOnCall map[int]struct { result1 int result2 int } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeSomethingElse) ReturnStuff() (int, int) { fake.returnStuffMutex.Lock() ret, specificReturn := fake.returnStuffReturnsOnCall[len(fake.returnStuffArgsForCall)] fake.returnStuffArgsForCall = append(fake.returnStuffArgsForCall, struct { }{}) stub := fake.ReturnStuffStub fakeReturns := fake.returnStuffReturns fake.recordInvocation("ReturnStuff", []interface{}{}) fake.returnStuffMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1, ret.result2 } return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeSomethingElse) ReturnStuffCallCount() int { fake.returnStuffMutex.RLock() defer fake.returnStuffMutex.RUnlock() return len(fake.returnStuffArgsForCall) } func (fake *FakeSomethingElse) ReturnStuffCalls(stub func() (int, int)) { fake.returnStuffMutex.Lock() defer fake.returnStuffMutex.Unlock() fake.ReturnStuffStub = stub } func (fake *FakeSomethingElse) ReturnStuffReturns(result1 int, result2 int) { fake.returnStuffMutex.Lock() defer fake.returnStuffMutex.Unlock() fake.ReturnStuffStub = nil fake.returnStuffReturns = struct { result1 int result2 int }{result1, result2} } func (fake *FakeSomethingElse) ReturnStuffReturnsOnCall(i int, result1 int, result2 int) { fake.returnStuffMutex.Lock() defer fake.returnStuffMutex.Unlock() fake.ReturnStuffStub = nil if fake.returnStuffReturnsOnCall == nil { fake.returnStuffReturnsOnCall = make(map[int]struct { result1 int result2 int }) } fake.returnStuffReturnsOnCall[i] = struct { result1 int result2 int }{result1, result2} } func (fake *FakeSomethingElse) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeSomethingElse) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.SomethingElse = new(FakeSomethingElse) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_something_factory.go000066400000000000000000000054061505763253600262740ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeSomethingFactory struct { Stub func(string, map[string]interface{}) string mutex sync.RWMutex argsForCall []struct { arg1 string arg2 map[string]interface{} } returns struct { result1 string } returnsOnCall map[int]struct { result1 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeSomethingFactory) Spy(arg1 string, arg2 map[string]interface{}) string { fake.mutex.Lock() ret, specificReturn := fake.returnsOnCall[len(fake.argsForCall)] fake.argsForCall = append(fake.argsForCall, struct { arg1 string arg2 map[string]interface{} }{arg1, arg2}) stub := fake.Stub returns := fake.returns fake.recordInvocation("SomethingFactory", []interface{}{arg1, arg2}) fake.mutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1 } return returns.result1 } func (fake *FakeSomethingFactory) CallCount() int { fake.mutex.RLock() defer fake.mutex.RUnlock() return len(fake.argsForCall) } func (fake *FakeSomethingFactory) Calls(stub func(string, map[string]interface{}) string) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = stub } func (fake *FakeSomethingFactory) ArgsForCall(i int) (string, map[string]interface{}) { fake.mutex.RLock() defer fake.mutex.RUnlock() return fake.argsForCall[i].arg1, fake.argsForCall[i].arg2 } func (fake *FakeSomethingFactory) Returns(result1 string) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil fake.returns = struct { result1 string }{result1} } func (fake *FakeSomethingFactory) ReturnsOnCall(i int, result1 string) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil if fake.returnsOnCall == nil { fake.returnsOnCall = make(map[int]struct { result1 string }) } fake.returnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakeSomethingFactory) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.mutex.RLock() defer fake.mutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeSomethingFactory) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.SomethingFactory = new(FakeSomethingFactory).Spy counterfeiter-6.12.0/fixtures/fixturesfakes/fake_something_with_foreign_interface.go000066400000000000000000000055241505763253600313320ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeSomethingWithForeignInterface struct { StuffStub func(int) string stuffMutex sync.RWMutex stuffArgsForCall []struct { arg1 int } stuffReturns struct { result1 string } stuffReturnsOnCall map[int]struct { result1 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeSomethingWithForeignInterface) Stuff(arg1 int) string { fake.stuffMutex.Lock() ret, specificReturn := fake.stuffReturnsOnCall[len(fake.stuffArgsForCall)] fake.stuffArgsForCall = append(fake.stuffArgsForCall, struct { arg1 int }{arg1}) stub := fake.StuffStub fakeReturns := fake.stuffReturns fake.recordInvocation("Stuff", []interface{}{arg1}) fake.stuffMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeSomethingWithForeignInterface) StuffCallCount() int { fake.stuffMutex.RLock() defer fake.stuffMutex.RUnlock() return len(fake.stuffArgsForCall) } func (fake *FakeSomethingWithForeignInterface) StuffCalls(stub func(int) string) { fake.stuffMutex.Lock() defer fake.stuffMutex.Unlock() fake.StuffStub = stub } func (fake *FakeSomethingWithForeignInterface) StuffArgsForCall(i int) int { fake.stuffMutex.RLock() defer fake.stuffMutex.RUnlock() argsForCall := fake.stuffArgsForCall[i] return argsForCall.arg1 } func (fake *FakeSomethingWithForeignInterface) StuffReturns(result1 string) { fake.stuffMutex.Lock() defer fake.stuffMutex.Unlock() fake.StuffStub = nil fake.stuffReturns = struct { result1 string }{result1} } func (fake *FakeSomethingWithForeignInterface) StuffReturnsOnCall(i int, result1 string) { fake.stuffMutex.Lock() defer fake.stuffMutex.Unlock() fake.StuffStub = nil if fake.stuffReturnsOnCall == nil { fake.stuffReturnsOnCall = make(map[int]struct { result1 string }) } fake.stuffReturnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakeSomethingWithForeignInterface) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeSomethingWithForeignInterface) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.SomethingWithForeignInterface = new(FakeSomethingWithForeignInterface) counterfeiter-6.12.0/fixtures/fixturesfakes/fake_unexported_func.go000066400000000000000000000051731505763253600257610ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" ) type FakeUnexportedFunc struct { Stub func(string, map[string]interface{}) string mutex sync.RWMutex argsForCall []struct { arg1 string arg2 map[string]interface{} } returns struct { result1 string } returnsOnCall map[int]struct { result1 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeUnexportedFunc) Spy(arg1 string, arg2 map[string]interface{}) string { fake.mutex.Lock() ret, specificReturn := fake.returnsOnCall[len(fake.argsForCall)] fake.argsForCall = append(fake.argsForCall, struct { arg1 string arg2 map[string]interface{} }{arg1, arg2}) stub := fake.Stub returns := fake.returns fake.recordInvocation("unexportedFunc", []interface{}{arg1, arg2}) fake.mutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1 } return returns.result1 } func (fake *FakeUnexportedFunc) CallCount() int { fake.mutex.RLock() defer fake.mutex.RUnlock() return len(fake.argsForCall) } func (fake *FakeUnexportedFunc) Calls(stub func(string, map[string]interface{}) string) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = stub } func (fake *FakeUnexportedFunc) ArgsForCall(i int) (string, map[string]interface{}) { fake.mutex.RLock() defer fake.mutex.RUnlock() return fake.argsForCall[i].arg1, fake.argsForCall[i].arg2 } func (fake *FakeUnexportedFunc) Returns(result1 string) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil fake.returns = struct { result1 string }{result1} } func (fake *FakeUnexportedFunc) ReturnsOnCall(i int, result1 string) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil if fake.returnsOnCall == nil { fake.returnsOnCall = make(map[int]struct { result1 string }) } fake.returnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakeUnexportedFunc) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.mutex.RLock() defer fake.mutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeUnexportedFunc) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } counterfeiter-6.12.0/fixtures/fixturesfakes/fake_unexported_interface.go000066400000000000000000000055551505763253600267720ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" ) type FakeUnexportedInterface struct { MethodStub func(string, map[string]interface{}) string methodMutex sync.RWMutex methodArgsForCall []struct { arg1 string arg2 map[string]interface{} } methodReturns struct { result1 string } methodReturnsOnCall map[int]struct { result1 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeUnexportedInterface) Method(arg1 string, arg2 map[string]interface{}) string { fake.methodMutex.Lock() ret, specificReturn := fake.methodReturnsOnCall[len(fake.methodArgsForCall)] fake.methodArgsForCall = append(fake.methodArgsForCall, struct { arg1 string arg2 map[string]interface{} }{arg1, arg2}) stub := fake.MethodStub fakeReturns := fake.methodReturns fake.recordInvocation("Method", []interface{}{arg1, arg2}) fake.methodMutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeUnexportedInterface) MethodCallCount() int { fake.methodMutex.RLock() defer fake.methodMutex.RUnlock() return len(fake.methodArgsForCall) } func (fake *FakeUnexportedInterface) MethodCalls(stub func(string, map[string]interface{}) string) { fake.methodMutex.Lock() defer fake.methodMutex.Unlock() fake.MethodStub = stub } func (fake *FakeUnexportedInterface) MethodArgsForCall(i int) (string, map[string]interface{}) { fake.methodMutex.RLock() defer fake.methodMutex.RUnlock() argsForCall := fake.methodArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeUnexportedInterface) MethodReturns(result1 string) { fake.methodMutex.Lock() defer fake.methodMutex.Unlock() fake.MethodStub = nil fake.methodReturns = struct { result1 string }{result1} } func (fake *FakeUnexportedInterface) MethodReturnsOnCall(i int, result1 string) { fake.methodMutex.Lock() defer fake.methodMutex.Unlock() fake.MethodStub = nil if fake.methodReturnsOnCall == nil { fake.methodReturnsOnCall = make(map[int]struct { result1 string }) } fake.methodReturnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakeUnexportedInterface) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeUnexportedInterface) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } counterfeiter-6.12.0/fixtures/genericinterface/000077500000000000000000000000001505763253600216405ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/genericinterface/genericinterface.go000066400000000000000000000030021505763253600254570ustar00rootroot00000000000000package genericinterface //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate type CustomTypeT any type CustomTypeU any type CustomTypeConstraintT interface { ~string } type CustomTypeConstraintU interface { int64 | float64 } // incorrect setup. this would fail // //counterfeiter:generate . GenericInterfaceBad[T CustomType] // type GenericInterfaceBad[T CustomTypeT] interface { // ReturnT() T // TakeT(T) // TakeAndReturnT(T) T // DoSomething() // } //counterfeiter:generate . GenericInterface type GenericInterface[T CustomTypeT] interface { ReturnT() T TakeT(T) TakeAndReturnT(T) T DoSomething() } //counterfeiter:generate . GenericInterfaceCustomTypeConstraintT type GenericInterfaceCustomTypeConstraintT[T CustomTypeConstraintT] interface { ReturnT() T TakeT(T) TakeAndReturnT(T) T DoSomething() } //counterfeiter:generate . GenericInterfaceCustomTypeConstraintU type GenericInterfaceCustomTypeConstraintU[T CustomTypeConstraintU] interface { ReturnT() T TakeT(T) TakeAndReturnT(T) T DoSomething() } //counterfeiter:generate . GenericInterfaceAny type GenericInterfaceAny[T any] interface { ReturnT() T TakeT(T) TakeAndReturnT(T) T DoSomething() } //counterfeiter:generate . GenericInterfaceMultipleTypes type GenericInterfaceMultipleTypes[T CustomTypeT, U CustomTypeU] interface { ReturnT() T ReturnU() U ReturnTAndU() (T, U) TakeT(T) TakeU(U) TakeTAndU(T, U) TakeAndReturnT(T) T TakeAndReturnU(U) U TakeAndReturnTAndU(T, U) (T, U) TakeTAndReturnU(T) U DoSomething() } counterfeiter-6.12.0/fixtures/genericinterface/genericinterfacefakes/000077500000000000000000000000001505763253600261475ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/genericinterface/genericinterfacefakes/fake_generic_interface.go000066400000000000000000000144331505763253600331250ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package genericinterfacefakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericinterface" ) type FakeGenericInterface[T genericinterface.CustomTypeT] struct { DoSomethingStub func() doSomethingMutex sync.RWMutex doSomethingArgsForCall []struct { } ReturnTStub func() T returnTMutex sync.RWMutex returnTArgsForCall []struct { } returnTReturns struct { result1 T } returnTReturnsOnCall map[int]struct { result1 T } TakeAndReturnTStub func(T) T takeAndReturnTMutex sync.RWMutex takeAndReturnTArgsForCall []struct { arg1 T } takeAndReturnTReturns struct { result1 T } takeAndReturnTReturnsOnCall map[int]struct { result1 T } TakeTStub func(T) takeTMutex sync.RWMutex takeTArgsForCall []struct { arg1 T } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeGenericInterface[T]) DoSomething() { fake.doSomethingMutex.Lock() fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { }{}) stub := fake.DoSomethingStub fake.recordInvocation("DoSomething", []interface{}{}) fake.doSomethingMutex.Unlock() if stub != nil { fake.DoSomethingStub() } } func (fake *FakeGenericInterface[T]) DoSomethingCallCount() int { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() return len(fake.doSomethingArgsForCall) } func (fake *FakeGenericInterface[T]) DoSomethingCalls(stub func()) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = stub } func (fake *FakeGenericInterface[T]) ReturnT() T { fake.returnTMutex.Lock() ret, specificReturn := fake.returnTReturnsOnCall[len(fake.returnTArgsForCall)] fake.returnTArgsForCall = append(fake.returnTArgsForCall, struct { }{}) stub := fake.ReturnTStub fakeReturns := fake.returnTReturns fake.recordInvocation("ReturnT", []interface{}{}) fake.returnTMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterface[T]) ReturnTCallCount() int { fake.returnTMutex.RLock() defer fake.returnTMutex.RUnlock() return len(fake.returnTArgsForCall) } func (fake *FakeGenericInterface[T]) ReturnTCalls(stub func() T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = stub } func (fake *FakeGenericInterface[T]) ReturnTReturns(result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil fake.returnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterface[T]) ReturnTReturnsOnCall(i int, result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil if fake.returnTReturnsOnCall == nil { fake.returnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.returnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterface[T]) TakeAndReturnT(arg1 T) T { fake.takeAndReturnTMutex.Lock() ret, specificReturn := fake.takeAndReturnTReturnsOnCall[len(fake.takeAndReturnTArgsForCall)] fake.takeAndReturnTArgsForCall = append(fake.takeAndReturnTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeAndReturnTStub fakeReturns := fake.takeAndReturnTReturns fake.recordInvocation("TakeAndReturnT", []interface{}{arg1}) fake.takeAndReturnTMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterface[T]) TakeAndReturnTCallCount() int { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() return len(fake.takeAndReturnTArgsForCall) } func (fake *FakeGenericInterface[T]) TakeAndReturnTCalls(stub func(T) T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = stub } func (fake *FakeGenericInterface[T]) TakeAndReturnTArgsForCall(i int) T { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() argsForCall := fake.takeAndReturnTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterface[T]) TakeAndReturnTReturns(result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil fake.takeAndReturnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterface[T]) TakeAndReturnTReturnsOnCall(i int, result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil if fake.takeAndReturnTReturnsOnCall == nil { fake.takeAndReturnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.takeAndReturnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterface[T]) TakeT(arg1 T) { fake.takeTMutex.Lock() fake.takeTArgsForCall = append(fake.takeTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeTStub fake.recordInvocation("TakeT", []interface{}{arg1}) fake.takeTMutex.Unlock() if stub != nil { fake.TakeTStub(arg1) } } func (fake *FakeGenericInterface[T]) TakeTCallCount() int { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() return len(fake.takeTArgsForCall) } func (fake *FakeGenericInterface[T]) TakeTCalls(stub func(T)) { fake.takeTMutex.Lock() defer fake.takeTMutex.Unlock() fake.TakeTStub = stub } func (fake *FakeGenericInterface[T]) TakeTArgsForCall(i int) T { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() argsForCall := fake.takeTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterface[T]) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeGenericInterface[T]) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ genericinterface.GenericInterface[genericinterface.CustomTypeT] = new(FakeGenericInterface[genericinterface.CustomTypeT]) counterfeiter-6.12.0/fixtures/genericinterface/genericinterfacefakes/fake_generic_interface_any.go000066400000000000000000000144251505763253600337750ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package genericinterfacefakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericinterface" ) type FakeGenericInterfaceAny[T any] struct { DoSomethingStub func() doSomethingMutex sync.RWMutex doSomethingArgsForCall []struct { } ReturnTStub func() T returnTMutex sync.RWMutex returnTArgsForCall []struct { } returnTReturns struct { result1 T } returnTReturnsOnCall map[int]struct { result1 T } TakeAndReturnTStub func(T) T takeAndReturnTMutex sync.RWMutex takeAndReturnTArgsForCall []struct { arg1 T } takeAndReturnTReturns struct { result1 T } takeAndReturnTReturnsOnCall map[int]struct { result1 T } TakeTStub func(T) takeTMutex sync.RWMutex takeTArgsForCall []struct { arg1 T } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeGenericInterfaceAny[T]) DoSomething() { fake.doSomethingMutex.Lock() fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { }{}) stub := fake.DoSomethingStub fake.recordInvocation("DoSomething", []interface{}{}) fake.doSomethingMutex.Unlock() if stub != nil { fake.DoSomethingStub() } } func (fake *FakeGenericInterfaceAny[T]) DoSomethingCallCount() int { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() return len(fake.doSomethingArgsForCall) } func (fake *FakeGenericInterfaceAny[T]) DoSomethingCalls(stub func()) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = stub } func (fake *FakeGenericInterfaceAny[T]) ReturnT() T { fake.returnTMutex.Lock() ret, specificReturn := fake.returnTReturnsOnCall[len(fake.returnTArgsForCall)] fake.returnTArgsForCall = append(fake.returnTArgsForCall, struct { }{}) stub := fake.ReturnTStub fakeReturns := fake.returnTReturns fake.recordInvocation("ReturnT", []interface{}{}) fake.returnTMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceAny[T]) ReturnTCallCount() int { fake.returnTMutex.RLock() defer fake.returnTMutex.RUnlock() return len(fake.returnTArgsForCall) } func (fake *FakeGenericInterfaceAny[T]) ReturnTCalls(stub func() T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = stub } func (fake *FakeGenericInterfaceAny[T]) ReturnTReturns(result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil fake.returnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceAny[T]) ReturnTReturnsOnCall(i int, result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil if fake.returnTReturnsOnCall == nil { fake.returnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.returnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceAny[T]) TakeAndReturnT(arg1 T) T { fake.takeAndReturnTMutex.Lock() ret, specificReturn := fake.takeAndReturnTReturnsOnCall[len(fake.takeAndReturnTArgsForCall)] fake.takeAndReturnTArgsForCall = append(fake.takeAndReturnTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeAndReturnTStub fakeReturns := fake.takeAndReturnTReturns fake.recordInvocation("TakeAndReturnT", []interface{}{arg1}) fake.takeAndReturnTMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceAny[T]) TakeAndReturnTCallCount() int { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() return len(fake.takeAndReturnTArgsForCall) } func (fake *FakeGenericInterfaceAny[T]) TakeAndReturnTCalls(stub func(T) T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = stub } func (fake *FakeGenericInterfaceAny[T]) TakeAndReturnTArgsForCall(i int) T { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() argsForCall := fake.takeAndReturnTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceAny[T]) TakeAndReturnTReturns(result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil fake.takeAndReturnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceAny[T]) TakeAndReturnTReturnsOnCall(i int, result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil if fake.takeAndReturnTReturnsOnCall == nil { fake.takeAndReturnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.takeAndReturnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceAny[T]) TakeT(arg1 T) { fake.takeTMutex.Lock() fake.takeTArgsForCall = append(fake.takeTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeTStub fake.recordInvocation("TakeT", []interface{}{arg1}) fake.takeTMutex.Unlock() if stub != nil { fake.TakeTStub(arg1) } } func (fake *FakeGenericInterfaceAny[T]) TakeTCallCount() int { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() return len(fake.takeTArgsForCall) } func (fake *FakeGenericInterfaceAny[T]) TakeTCalls(stub func(T)) { fake.takeTMutex.Lock() defer fake.takeTMutex.Unlock() fake.TakeTStub = stub } func (fake *FakeGenericInterfaceAny[T]) TakeTArgsForCall(i int) T { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() argsForCall := fake.takeTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceAny[T]) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeGenericInterfaceAny[T]) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ genericinterface.GenericInterfaceAny[any] = new(FakeGenericInterfaceAny[any]) fake_generic_interface_custom_type_constraint_t.go000066400000000000000000000151351505763253600402700ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/genericinterface/genericinterfacefakes// Code generated by counterfeiter. DO NOT EDIT. package genericinterfacefakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericinterface" ) type FakeGenericInterfaceCustomTypeConstraintT[T genericinterface.CustomTypeConstraintT] struct { DoSomethingStub func() doSomethingMutex sync.RWMutex doSomethingArgsForCall []struct { } ReturnTStub func() T returnTMutex sync.RWMutex returnTArgsForCall []struct { } returnTReturns struct { result1 T } returnTReturnsOnCall map[int]struct { result1 T } TakeAndReturnTStub func(T) T takeAndReturnTMutex sync.RWMutex takeAndReturnTArgsForCall []struct { arg1 T } takeAndReturnTReturns struct { result1 T } takeAndReturnTReturnsOnCall map[int]struct { result1 T } TakeTStub func(T) takeTMutex sync.RWMutex takeTArgsForCall []struct { arg1 T } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) DoSomething() { fake.doSomethingMutex.Lock() fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { }{}) stub := fake.DoSomethingStub fake.recordInvocation("DoSomething", []interface{}{}) fake.doSomethingMutex.Unlock() if stub != nil { fake.DoSomethingStub() } } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) DoSomethingCallCount() int { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() return len(fake.doSomethingArgsForCall) } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) DoSomethingCalls(stub func()) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = stub } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) ReturnT() T { fake.returnTMutex.Lock() ret, specificReturn := fake.returnTReturnsOnCall[len(fake.returnTArgsForCall)] fake.returnTArgsForCall = append(fake.returnTArgsForCall, struct { }{}) stub := fake.ReturnTStub fakeReturns := fake.returnTReturns fake.recordInvocation("ReturnT", []interface{}{}) fake.returnTMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) ReturnTCallCount() int { fake.returnTMutex.RLock() defer fake.returnTMutex.RUnlock() return len(fake.returnTArgsForCall) } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) ReturnTCalls(stub func() T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = stub } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) ReturnTReturns(result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil fake.returnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) ReturnTReturnsOnCall(i int, result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil if fake.returnTReturnsOnCall == nil { fake.returnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.returnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeAndReturnT(arg1 T) T { fake.takeAndReturnTMutex.Lock() ret, specificReturn := fake.takeAndReturnTReturnsOnCall[len(fake.takeAndReturnTArgsForCall)] fake.takeAndReturnTArgsForCall = append(fake.takeAndReturnTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeAndReturnTStub fakeReturns := fake.takeAndReturnTReturns fake.recordInvocation("TakeAndReturnT", []interface{}{arg1}) fake.takeAndReturnTMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeAndReturnTCallCount() int { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() return len(fake.takeAndReturnTArgsForCall) } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeAndReturnTCalls(stub func(T) T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = stub } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeAndReturnTArgsForCall(i int) T { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() argsForCall := fake.takeAndReturnTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeAndReturnTReturns(result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil fake.takeAndReturnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeAndReturnTReturnsOnCall(i int, result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil if fake.takeAndReturnTReturnsOnCall == nil { fake.takeAndReturnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.takeAndReturnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeT(arg1 T) { fake.takeTMutex.Lock() fake.takeTArgsForCall = append(fake.takeTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeTStub fake.recordInvocation("TakeT", []interface{}{arg1}) fake.takeTMutex.Unlock() if stub != nil { fake.TakeTStub(arg1) } } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeTCallCount() int { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() return len(fake.takeTArgsForCall) } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeTCalls(stub func(T)) { fake.takeTMutex.Lock() defer fake.takeTMutex.Unlock() fake.TakeTStub = stub } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) TakeTArgsForCall(i int) T { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() argsForCall := fake.takeTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeGenericInterfaceCustomTypeConstraintT[T]) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } fake_generic_interface_custom_type_constraint_u.go000066400000000000000000000151351505763253600402710ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/genericinterface/genericinterfacefakes// Code generated by counterfeiter. DO NOT EDIT. package genericinterfacefakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericinterface" ) type FakeGenericInterfaceCustomTypeConstraintU[T genericinterface.CustomTypeConstraintU] struct { DoSomethingStub func() doSomethingMutex sync.RWMutex doSomethingArgsForCall []struct { } ReturnTStub func() T returnTMutex sync.RWMutex returnTArgsForCall []struct { } returnTReturns struct { result1 T } returnTReturnsOnCall map[int]struct { result1 T } TakeAndReturnTStub func(T) T takeAndReturnTMutex sync.RWMutex takeAndReturnTArgsForCall []struct { arg1 T } takeAndReturnTReturns struct { result1 T } takeAndReturnTReturnsOnCall map[int]struct { result1 T } TakeTStub func(T) takeTMutex sync.RWMutex takeTArgsForCall []struct { arg1 T } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) DoSomething() { fake.doSomethingMutex.Lock() fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { }{}) stub := fake.DoSomethingStub fake.recordInvocation("DoSomething", []interface{}{}) fake.doSomethingMutex.Unlock() if stub != nil { fake.DoSomethingStub() } } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) DoSomethingCallCount() int { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() return len(fake.doSomethingArgsForCall) } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) DoSomethingCalls(stub func()) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = stub } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) ReturnT() T { fake.returnTMutex.Lock() ret, specificReturn := fake.returnTReturnsOnCall[len(fake.returnTArgsForCall)] fake.returnTArgsForCall = append(fake.returnTArgsForCall, struct { }{}) stub := fake.ReturnTStub fakeReturns := fake.returnTReturns fake.recordInvocation("ReturnT", []interface{}{}) fake.returnTMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) ReturnTCallCount() int { fake.returnTMutex.RLock() defer fake.returnTMutex.RUnlock() return len(fake.returnTArgsForCall) } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) ReturnTCalls(stub func() T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = stub } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) ReturnTReturns(result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil fake.returnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) ReturnTReturnsOnCall(i int, result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil if fake.returnTReturnsOnCall == nil { fake.returnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.returnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeAndReturnT(arg1 T) T { fake.takeAndReturnTMutex.Lock() ret, specificReturn := fake.takeAndReturnTReturnsOnCall[len(fake.takeAndReturnTArgsForCall)] fake.takeAndReturnTArgsForCall = append(fake.takeAndReturnTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeAndReturnTStub fakeReturns := fake.takeAndReturnTReturns fake.recordInvocation("TakeAndReturnT", []interface{}{arg1}) fake.takeAndReturnTMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeAndReturnTCallCount() int { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() return len(fake.takeAndReturnTArgsForCall) } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeAndReturnTCalls(stub func(T) T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = stub } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeAndReturnTArgsForCall(i int) T { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() argsForCall := fake.takeAndReturnTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeAndReturnTReturns(result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil fake.takeAndReturnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeAndReturnTReturnsOnCall(i int, result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil if fake.takeAndReturnTReturnsOnCall == nil { fake.takeAndReturnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.takeAndReturnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeT(arg1 T) { fake.takeTMutex.Lock() fake.takeTArgsForCall = append(fake.takeTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeTStub fake.recordInvocation("TakeT", []interface{}{arg1}) fake.takeTMutex.Unlock() if stub != nil { fake.TakeTStub(arg1) } } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeTCallCount() int { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() return len(fake.takeTArgsForCall) } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeTCalls(stub func(T)) { fake.takeTMutex.Lock() defer fake.takeTMutex.Unlock() fake.TakeTStub = stub } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) TakeTArgsForCall(i int) T { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() argsForCall := fake.takeTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeGenericInterfaceCustomTypeConstraintU[T]) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } fake_generic_interface_multiple_types.go000066400000000000000000000456701505763253600362140ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/genericinterface/genericinterfacefakes// Code generated by counterfeiter. DO NOT EDIT. package genericinterfacefakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericinterface" ) type FakeGenericInterfaceMultipleTypes[T genericinterface.CustomTypeT, U genericinterface.CustomTypeU] struct { DoSomethingStub func() doSomethingMutex sync.RWMutex doSomethingArgsForCall []struct { } ReturnTStub func() T returnTMutex sync.RWMutex returnTArgsForCall []struct { } returnTReturns struct { result1 T } returnTReturnsOnCall map[int]struct { result1 T } ReturnTAndUStub func() (T, U) returnTAndUMutex sync.RWMutex returnTAndUArgsForCall []struct { } returnTAndUReturns struct { result1 T result2 U } returnTAndUReturnsOnCall map[int]struct { result1 T result2 U } ReturnUStub func() U returnUMutex sync.RWMutex returnUArgsForCall []struct { } returnUReturns struct { result1 U } returnUReturnsOnCall map[int]struct { result1 U } TakeAndReturnTStub func(T) T takeAndReturnTMutex sync.RWMutex takeAndReturnTArgsForCall []struct { arg1 T } takeAndReturnTReturns struct { result1 T } takeAndReturnTReturnsOnCall map[int]struct { result1 T } TakeAndReturnTAndUStub func(T, U) (T, U) takeAndReturnTAndUMutex sync.RWMutex takeAndReturnTAndUArgsForCall []struct { arg1 T arg2 U } takeAndReturnTAndUReturns struct { result1 T result2 U } takeAndReturnTAndUReturnsOnCall map[int]struct { result1 T result2 U } TakeAndReturnUStub func(U) U takeAndReturnUMutex sync.RWMutex takeAndReturnUArgsForCall []struct { arg1 U } takeAndReturnUReturns struct { result1 U } takeAndReturnUReturnsOnCall map[int]struct { result1 U } TakeTStub func(T) takeTMutex sync.RWMutex takeTArgsForCall []struct { arg1 T } TakeTAndReturnUStub func(T) U takeTAndReturnUMutex sync.RWMutex takeTAndReturnUArgsForCall []struct { arg1 T } takeTAndReturnUReturns struct { result1 U } takeTAndReturnUReturnsOnCall map[int]struct { result1 U } TakeTAndUStub func(T, U) takeTAndUMutex sync.RWMutex takeTAndUArgsForCall []struct { arg1 T arg2 U } TakeUStub func(U) takeUMutex sync.RWMutex takeUArgsForCall []struct { arg1 U } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) DoSomething() { fake.doSomethingMutex.Lock() fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { }{}) stub := fake.DoSomethingStub fake.recordInvocation("DoSomething", []interface{}{}) fake.doSomethingMutex.Unlock() if stub != nil { fake.DoSomethingStub() } } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) DoSomethingCallCount() int { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() return len(fake.doSomethingArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) DoSomethingCalls(stub func()) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnT() T { fake.returnTMutex.Lock() ret, specificReturn := fake.returnTReturnsOnCall[len(fake.returnTArgsForCall)] fake.returnTArgsForCall = append(fake.returnTArgsForCall, struct { }{}) stub := fake.ReturnTStub fakeReturns := fake.returnTReturns fake.recordInvocation("ReturnT", []interface{}{}) fake.returnTMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnTCallCount() int { fake.returnTMutex.RLock() defer fake.returnTMutex.RUnlock() return len(fake.returnTArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnTCalls(stub func() T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnTReturns(result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil fake.returnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnTReturnsOnCall(i int, result1 T) { fake.returnTMutex.Lock() defer fake.returnTMutex.Unlock() fake.ReturnTStub = nil if fake.returnTReturnsOnCall == nil { fake.returnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.returnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnTAndU() (T, U) { fake.returnTAndUMutex.Lock() ret, specificReturn := fake.returnTAndUReturnsOnCall[len(fake.returnTAndUArgsForCall)] fake.returnTAndUArgsForCall = append(fake.returnTAndUArgsForCall, struct { }{}) stub := fake.ReturnTAndUStub fakeReturns := fake.returnTAndUReturns fake.recordInvocation("ReturnTAndU", []interface{}{}) fake.returnTAndUMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1, ret.result2 } return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnTAndUCallCount() int { fake.returnTAndUMutex.RLock() defer fake.returnTAndUMutex.RUnlock() return len(fake.returnTAndUArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnTAndUCalls(stub func() (T, U)) { fake.returnTAndUMutex.Lock() defer fake.returnTAndUMutex.Unlock() fake.ReturnTAndUStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnTAndUReturns(result1 T, result2 U) { fake.returnTAndUMutex.Lock() defer fake.returnTAndUMutex.Unlock() fake.ReturnTAndUStub = nil fake.returnTAndUReturns = struct { result1 T result2 U }{result1, result2} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnTAndUReturnsOnCall(i int, result1 T, result2 U) { fake.returnTAndUMutex.Lock() defer fake.returnTAndUMutex.Unlock() fake.ReturnTAndUStub = nil if fake.returnTAndUReturnsOnCall == nil { fake.returnTAndUReturnsOnCall = make(map[int]struct { result1 T result2 U }) } fake.returnTAndUReturnsOnCall[i] = struct { result1 T result2 U }{result1, result2} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnU() U { fake.returnUMutex.Lock() ret, specificReturn := fake.returnUReturnsOnCall[len(fake.returnUArgsForCall)] fake.returnUArgsForCall = append(fake.returnUArgsForCall, struct { }{}) stub := fake.ReturnUStub fakeReturns := fake.returnUReturns fake.recordInvocation("ReturnU", []interface{}{}) fake.returnUMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnUCallCount() int { fake.returnUMutex.RLock() defer fake.returnUMutex.RUnlock() return len(fake.returnUArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnUCalls(stub func() U) { fake.returnUMutex.Lock() defer fake.returnUMutex.Unlock() fake.ReturnUStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnUReturns(result1 U) { fake.returnUMutex.Lock() defer fake.returnUMutex.Unlock() fake.ReturnUStub = nil fake.returnUReturns = struct { result1 U }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) ReturnUReturnsOnCall(i int, result1 U) { fake.returnUMutex.Lock() defer fake.returnUMutex.Unlock() fake.ReturnUStub = nil if fake.returnUReturnsOnCall == nil { fake.returnUReturnsOnCall = make(map[int]struct { result1 U }) } fake.returnUReturnsOnCall[i] = struct { result1 U }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnT(arg1 T) T { fake.takeAndReturnTMutex.Lock() ret, specificReturn := fake.takeAndReturnTReturnsOnCall[len(fake.takeAndReturnTArgsForCall)] fake.takeAndReturnTArgsForCall = append(fake.takeAndReturnTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeAndReturnTStub fakeReturns := fake.takeAndReturnTReturns fake.recordInvocation("TakeAndReturnT", []interface{}{arg1}) fake.takeAndReturnTMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTCallCount() int { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() return len(fake.takeAndReturnTArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTCalls(stub func(T) T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTArgsForCall(i int) T { fake.takeAndReturnTMutex.RLock() defer fake.takeAndReturnTMutex.RUnlock() argsForCall := fake.takeAndReturnTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTReturns(result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil fake.takeAndReturnTReturns = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTReturnsOnCall(i int, result1 T) { fake.takeAndReturnTMutex.Lock() defer fake.takeAndReturnTMutex.Unlock() fake.TakeAndReturnTStub = nil if fake.takeAndReturnTReturnsOnCall == nil { fake.takeAndReturnTReturnsOnCall = make(map[int]struct { result1 T }) } fake.takeAndReturnTReturnsOnCall[i] = struct { result1 T }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTAndU(arg1 T, arg2 U) (T, U) { fake.takeAndReturnTAndUMutex.Lock() ret, specificReturn := fake.takeAndReturnTAndUReturnsOnCall[len(fake.takeAndReturnTAndUArgsForCall)] fake.takeAndReturnTAndUArgsForCall = append(fake.takeAndReturnTAndUArgsForCall, struct { arg1 T arg2 U }{arg1, arg2}) stub := fake.TakeAndReturnTAndUStub fakeReturns := fake.takeAndReturnTAndUReturns fake.recordInvocation("TakeAndReturnTAndU", []interface{}{arg1, arg2}) fake.takeAndReturnTAndUMutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1, ret.result2 } return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTAndUCallCount() int { fake.takeAndReturnTAndUMutex.RLock() defer fake.takeAndReturnTAndUMutex.RUnlock() return len(fake.takeAndReturnTAndUArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTAndUCalls(stub func(T, U) (T, U)) { fake.takeAndReturnTAndUMutex.Lock() defer fake.takeAndReturnTAndUMutex.Unlock() fake.TakeAndReturnTAndUStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTAndUArgsForCall(i int) (T, U) { fake.takeAndReturnTAndUMutex.RLock() defer fake.takeAndReturnTAndUMutex.RUnlock() argsForCall := fake.takeAndReturnTAndUArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTAndUReturns(result1 T, result2 U) { fake.takeAndReturnTAndUMutex.Lock() defer fake.takeAndReturnTAndUMutex.Unlock() fake.TakeAndReturnTAndUStub = nil fake.takeAndReturnTAndUReturns = struct { result1 T result2 U }{result1, result2} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnTAndUReturnsOnCall(i int, result1 T, result2 U) { fake.takeAndReturnTAndUMutex.Lock() defer fake.takeAndReturnTAndUMutex.Unlock() fake.TakeAndReturnTAndUStub = nil if fake.takeAndReturnTAndUReturnsOnCall == nil { fake.takeAndReturnTAndUReturnsOnCall = make(map[int]struct { result1 T result2 U }) } fake.takeAndReturnTAndUReturnsOnCall[i] = struct { result1 T result2 U }{result1, result2} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnU(arg1 U) U { fake.takeAndReturnUMutex.Lock() ret, specificReturn := fake.takeAndReturnUReturnsOnCall[len(fake.takeAndReturnUArgsForCall)] fake.takeAndReturnUArgsForCall = append(fake.takeAndReturnUArgsForCall, struct { arg1 U }{arg1}) stub := fake.TakeAndReturnUStub fakeReturns := fake.takeAndReturnUReturns fake.recordInvocation("TakeAndReturnU", []interface{}{arg1}) fake.takeAndReturnUMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnUCallCount() int { fake.takeAndReturnUMutex.RLock() defer fake.takeAndReturnUMutex.RUnlock() return len(fake.takeAndReturnUArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnUCalls(stub func(U) U) { fake.takeAndReturnUMutex.Lock() defer fake.takeAndReturnUMutex.Unlock() fake.TakeAndReturnUStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnUArgsForCall(i int) U { fake.takeAndReturnUMutex.RLock() defer fake.takeAndReturnUMutex.RUnlock() argsForCall := fake.takeAndReturnUArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnUReturns(result1 U) { fake.takeAndReturnUMutex.Lock() defer fake.takeAndReturnUMutex.Unlock() fake.TakeAndReturnUStub = nil fake.takeAndReturnUReturns = struct { result1 U }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeAndReturnUReturnsOnCall(i int, result1 U) { fake.takeAndReturnUMutex.Lock() defer fake.takeAndReturnUMutex.Unlock() fake.TakeAndReturnUStub = nil if fake.takeAndReturnUReturnsOnCall == nil { fake.takeAndReturnUReturnsOnCall = make(map[int]struct { result1 U }) } fake.takeAndReturnUReturnsOnCall[i] = struct { result1 U }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeT(arg1 T) { fake.takeTMutex.Lock() fake.takeTArgsForCall = append(fake.takeTArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeTStub fake.recordInvocation("TakeT", []interface{}{arg1}) fake.takeTMutex.Unlock() if stub != nil { fake.TakeTStub(arg1) } } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTCallCount() int { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() return len(fake.takeTArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTCalls(stub func(T)) { fake.takeTMutex.Lock() defer fake.takeTMutex.Unlock() fake.TakeTStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTArgsForCall(i int) T { fake.takeTMutex.RLock() defer fake.takeTMutex.RUnlock() argsForCall := fake.takeTArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndReturnU(arg1 T) U { fake.takeTAndReturnUMutex.Lock() ret, specificReturn := fake.takeTAndReturnUReturnsOnCall[len(fake.takeTAndReturnUArgsForCall)] fake.takeTAndReturnUArgsForCall = append(fake.takeTAndReturnUArgsForCall, struct { arg1 T }{arg1}) stub := fake.TakeTAndReturnUStub fakeReturns := fake.takeTAndReturnUReturns fake.recordInvocation("TakeTAndReturnU", []interface{}{arg1}) fake.takeTAndReturnUMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndReturnUCallCount() int { fake.takeTAndReturnUMutex.RLock() defer fake.takeTAndReturnUMutex.RUnlock() return len(fake.takeTAndReturnUArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndReturnUCalls(stub func(T) U) { fake.takeTAndReturnUMutex.Lock() defer fake.takeTAndReturnUMutex.Unlock() fake.TakeTAndReturnUStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndReturnUArgsForCall(i int) T { fake.takeTAndReturnUMutex.RLock() defer fake.takeTAndReturnUMutex.RUnlock() argsForCall := fake.takeTAndReturnUArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndReturnUReturns(result1 U) { fake.takeTAndReturnUMutex.Lock() defer fake.takeTAndReturnUMutex.Unlock() fake.TakeTAndReturnUStub = nil fake.takeTAndReturnUReturns = struct { result1 U }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndReturnUReturnsOnCall(i int, result1 U) { fake.takeTAndReturnUMutex.Lock() defer fake.takeTAndReturnUMutex.Unlock() fake.TakeTAndReturnUStub = nil if fake.takeTAndReturnUReturnsOnCall == nil { fake.takeTAndReturnUReturnsOnCall = make(map[int]struct { result1 U }) } fake.takeTAndReturnUReturnsOnCall[i] = struct { result1 U }{result1} } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndU(arg1 T, arg2 U) { fake.takeTAndUMutex.Lock() fake.takeTAndUArgsForCall = append(fake.takeTAndUArgsForCall, struct { arg1 T arg2 U }{arg1, arg2}) stub := fake.TakeTAndUStub fake.recordInvocation("TakeTAndU", []interface{}{arg1, arg2}) fake.takeTAndUMutex.Unlock() if stub != nil { fake.TakeTAndUStub(arg1, arg2) } } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndUCallCount() int { fake.takeTAndUMutex.RLock() defer fake.takeTAndUMutex.RUnlock() return len(fake.takeTAndUArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndUCalls(stub func(T, U)) { fake.takeTAndUMutex.Lock() defer fake.takeTAndUMutex.Unlock() fake.TakeTAndUStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeTAndUArgsForCall(i int) (T, U) { fake.takeTAndUMutex.RLock() defer fake.takeTAndUMutex.RUnlock() argsForCall := fake.takeTAndUArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeU(arg1 U) { fake.takeUMutex.Lock() fake.takeUArgsForCall = append(fake.takeUArgsForCall, struct { arg1 U }{arg1}) stub := fake.TakeUStub fake.recordInvocation("TakeU", []interface{}{arg1}) fake.takeUMutex.Unlock() if stub != nil { fake.TakeUStub(arg1) } } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeUCallCount() int { fake.takeUMutex.RLock() defer fake.takeUMutex.RUnlock() return len(fake.takeUArgsForCall) } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeUCalls(stub func(U)) { fake.takeUMutex.Lock() defer fake.takeUMutex.Unlock() fake.TakeUStub = stub } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) TakeUArgsForCall(i int) U { fake.takeUMutex.RLock() defer fake.takeUMutex.RUnlock() argsForCall := fake.takeUArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeGenericInterfaceMultipleTypes[T, U]) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ genericinterface.GenericInterfaceMultipleTypes[genericinterface.CustomTypeT, genericinterface.CustomTypeU] = new(FakeGenericInterfaceMultipleTypes[genericinterface.CustomTypeT, genericinterface.CustomTypeU]) counterfeiter-6.12.0/fixtures/genericparam/000077500000000000000000000000001505763253600210005ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/genericparam/genericparam.go000066400000000000000000000011301505763253600237570ustar00rootroot00000000000000package genericparam import ( "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam/genericparamtype" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam/genericreturntype" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate . GenericParamFunc type GenericParamFunc func(Generic[genericparamtype.T]) Generic[genericreturntype.R] //counterfeiter:generate . GenericParamInterface type GenericParamInterface interface { DoSomething(Generic[genericparamtype.T]) Generic[genericreturntype.R] } type Generic[T any] struct{ _ T } counterfeiter-6.12.0/fixtures/genericparam/genericparamfakes/000077500000000000000000000000001505763253600244475ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/genericparam/genericparamfakes/fake_generic_param_func.go000066400000000000000000000064351505763253600316030ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package genericparamfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam/genericparamtype" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam/genericreturntype" ) type FakeGenericParamFunc struct { Stub func(genericparam.Generic[genericparamtype.T]) genericparam.Generic[genericreturntype.R] mutex sync.RWMutex argsForCall []struct { arg1 genericparam.Generic[genericparamtype.T] } returns struct { result1 genericparam.Generic[genericreturntype.R] } returnsOnCall map[int]struct { result1 genericparam.Generic[genericreturntype.R] } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeGenericParamFunc) Spy(arg1 genericparam.Generic[genericparamtype.T]) genericparam.Generic[genericreturntype.R] { fake.mutex.Lock() ret, specificReturn := fake.returnsOnCall[len(fake.argsForCall)] fake.argsForCall = append(fake.argsForCall, struct { arg1 genericparam.Generic[genericparamtype.T] }{arg1}) stub := fake.Stub returns := fake.returns fake.recordInvocation("GenericParamFunc", []interface{}{arg1}) fake.mutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return returns.result1 } func (fake *FakeGenericParamFunc) CallCount() int { fake.mutex.RLock() defer fake.mutex.RUnlock() return len(fake.argsForCall) } func (fake *FakeGenericParamFunc) Calls(stub func(genericparam.Generic[genericparamtype.T]) genericparam.Generic[genericreturntype.R]) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = stub } func (fake *FakeGenericParamFunc) ArgsForCall(i int) genericparam.Generic[genericparamtype.T] { fake.mutex.RLock() defer fake.mutex.RUnlock() return fake.argsForCall[i].arg1 } func (fake *FakeGenericParamFunc) Returns(result1 genericparam.Generic[genericreturntype.R]) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil fake.returns = struct { result1 genericparam.Generic[genericreturntype.R] }{result1} } func (fake *FakeGenericParamFunc) ReturnsOnCall(i int, result1 genericparam.Generic[genericreturntype.R]) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil if fake.returnsOnCall == nil { fake.returnsOnCall = make(map[int]struct { result1 genericparam.Generic[genericreturntype.R] }) } fake.returnsOnCall[i] = struct { result1 genericparam.Generic[genericreturntype.R] }{result1} } func (fake *FakeGenericParamFunc) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.mutex.RLock() defer fake.mutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeGenericParamFunc) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ genericparam.GenericParamFunc = new(FakeGenericParamFunc).Spy counterfeiter-6.12.0/fixtures/genericparam/genericparamfakes/fake_generic_param_interface.go000066400000000000000000000073361505763253600326110ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package genericparamfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam/genericparamtype" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam/genericreturntype" ) type FakeGenericParamInterface struct { DoSomethingStub func(genericparam.Generic[genericparamtype.T]) genericparam.Generic[genericreturntype.R] doSomethingMutex sync.RWMutex doSomethingArgsForCall []struct { arg1 genericparam.Generic[genericparamtype.T] } doSomethingReturns struct { result1 genericparam.Generic[genericreturntype.R] } doSomethingReturnsOnCall map[int]struct { result1 genericparam.Generic[genericreturntype.R] } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeGenericParamInterface) DoSomething(arg1 genericparam.Generic[genericparamtype.T]) genericparam.Generic[genericreturntype.R] { fake.doSomethingMutex.Lock() ret, specificReturn := fake.doSomethingReturnsOnCall[len(fake.doSomethingArgsForCall)] fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { arg1 genericparam.Generic[genericparamtype.T] }{arg1}) stub := fake.DoSomethingStub fakeReturns := fake.doSomethingReturns fake.recordInvocation("DoSomething", []interface{}{arg1}) fake.doSomethingMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeGenericParamInterface) DoSomethingCallCount() int { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() return len(fake.doSomethingArgsForCall) } func (fake *FakeGenericParamInterface) DoSomethingCalls(stub func(genericparam.Generic[genericparamtype.T]) genericparam.Generic[genericreturntype.R]) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = stub } func (fake *FakeGenericParamInterface) DoSomethingArgsForCall(i int) genericparam.Generic[genericparamtype.T] { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() argsForCall := fake.doSomethingArgsForCall[i] return argsForCall.arg1 } func (fake *FakeGenericParamInterface) DoSomethingReturns(result1 genericparam.Generic[genericreturntype.R]) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = nil fake.doSomethingReturns = struct { result1 genericparam.Generic[genericreturntype.R] }{result1} } func (fake *FakeGenericParamInterface) DoSomethingReturnsOnCall(i int, result1 genericparam.Generic[genericreturntype.R]) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = nil if fake.doSomethingReturnsOnCall == nil { fake.doSomethingReturnsOnCall = make(map[int]struct { result1 genericparam.Generic[genericreturntype.R] }) } fake.doSomethingReturnsOnCall[i] = struct { result1 genericparam.Generic[genericreturntype.R] }{result1} } func (fake *FakeGenericParamInterface) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeGenericParamInterface) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ genericparam.GenericParamInterface = new(FakeGenericParamInterface) counterfeiter-6.12.0/fixtures/genericparam/genericparamtype/000077500000000000000000000000001505763253600243375ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/genericparam/genericparamtype/genericparamtype.go000066400000000000000000000000501505763253600302200ustar00rootroot00000000000000package genericparamtype type T string counterfeiter-6.12.0/fixtures/genericparam/genericreturntype/000077500000000000000000000000001505763253600245565ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/genericparam/genericreturntype/genericreturntype.go000066400000000000000000000000531505763253600306610ustar00rootroot00000000000000package genericreturntype type R struct{} counterfeiter-6.12.0/fixtures/go-hyphenpackage/000077500000000000000000000000001505763253600215555ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/go-hyphenpackage/fixture.go000066400000000000000000000001771505763253600235770ustar00rootroot00000000000000package hyphenpackage // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/go-hyphenpackage" type HyphenType struct{} counterfeiter-6.12.0/fixtures/has_imports.go000066400000000000000000000002711505763253600212220ustar00rootroot00000000000000package fixtures import ( "io" "net/http" some_alias "os" ) //counterfeiter:generate . HasImports type HasImports interface { DoThings(io.Writer, *some_alias.File) *http.Client } counterfeiter-6.12.0/fixtures/has_other_types.go000066400000000000000000000001731505763253600220730ustar00rootroot00000000000000package fixtures //counterfeiter:generate . HasOtherTypes type HasOtherTypes interface { GetThing(SomeString) SomeFunc } counterfeiter-6.12.0/fixtures/has_var_args.go000066400000000000000000000004551505763253600213350ustar00rootroot00000000000000package fixtures //counterfeiter:generate . HasVarArgs type HasVarArgs interface { DoThings(int, ...string) int DoMoreThings(int, int, ...string) int } //counterfeiter:generate . HasVarArgsWithLocalTypes type HasVarArgsWithLocalTypes interface { DoThings(...LocalType) } type LocalType struct{} counterfeiter-6.12.0/fixtures/headers/000077500000000000000000000000001505763253600177565ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/headers/default.header.go.txt000066400000000000000000000001021505763253600237670ustar00rootroot00000000000000// This is a default header for all the fakes in this package // counterfeiter-6.12.0/fixtures/headers/defaultheader/000077500000000000000000000000001505763253600225535ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/headers/defaultheader/defaultheaderfakes/000077500000000000000000000000001505763253600263625ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/headers/defaultheader/defaultheaderfakes/fake_header_default.go000066400000000000000000000021041505763253600326300ustar00rootroot00000000000000// This is a default header for all the fakes in this package // // Code generated by counterfeiter. DO NOT EDIT. package defaultheaderfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/headers/defaultheader" ) type FakeHeaderDefault struct { invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeHeaderDefault) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeHeaderDefault) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ defaultheader.HeaderDefault = new(FakeHeaderDefault) counterfeiter-6.12.0/fixtures/headers/defaultheader/defaultheaderfakes/fake_header_specific.go000066400000000000000000000021231505763253600327720ustar00rootroot00000000000000// This is a specific header for only some of the fakes in this package // // Code generated by counterfeiter. DO NOT EDIT. package defaultheaderfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/headers/defaultheader" ) type FakeHeaderSpecific struct { invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeHeaderSpecific) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeHeaderSpecific) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ defaultheader.HeaderSpecific = new(FakeHeaderSpecific) counterfeiter-6.12.0/fixtures/headers/defaultheader/header.go000066400000000000000000000006121505763253600243310ustar00rootroot00000000000000package defaultheader // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/headers/defaultheader" //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -header ../default.header.go.txt -generate //counterfeiter:generate . HeaderDefault type HeaderDefault interface{} //counterfeiter:generate -header ../specific.header.go.txt . HeaderSpecific type HeaderSpecific interface{} counterfeiter-6.12.0/fixtures/headers/nodefaultheader/000077500000000000000000000000001505763253600231105ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/headers/nodefaultheader/headers.go000066400000000000000000000005551505763253600250570ustar00rootroot00000000000000package nodefaultheader // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/headers/nodefaultheader" //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate . HeaderDefault type HeaderDefault interface{} //counterfeiter:generate -header ../specific.header.go.txt . HeaderSpecific type HeaderSpecific interface{} counterfeiter-6.12.0/fixtures/headers/nodefaultheader/nodefaultheaderfakes/000077500000000000000000000000001505763253600272545ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/headers/nodefaultheader/nodefaultheaderfakes/fake_header_default.go000066400000000000000000000020101505763253600335160ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package nodefaultheaderfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/headers/nodefaultheader" ) type FakeHeaderDefault struct { invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeHeaderDefault) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeHeaderDefault) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ nodefaultheader.HeaderDefault = new(FakeHeaderDefault) counterfeiter-6.12.0/fixtures/headers/nodefaultheader/nodefaultheaderfakes/fake_header_specific.go000066400000000000000000000021311505763253600336630ustar00rootroot00000000000000// This is a specific header for only some of the fakes in this package // // Code generated by counterfeiter. DO NOT EDIT. package nodefaultheaderfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/headers/nodefaultheader" ) type FakeHeaderSpecific struct { invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeHeaderSpecific) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeHeaderSpecific) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ nodefaultheader.HeaderSpecific = new(FakeHeaderSpecific) counterfeiter-6.12.0/fixtures/headers/specific.header.go.txt000066400000000000000000000001141505763253600241330ustar00rootroot00000000000000// This is a specific header for only some of the fakes in this package // counterfeiter-6.12.0/fixtures/hyphenated_package_same_name/000077500000000000000000000000001505763253600241545ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/hyphenated_package_same_name/go.mod000066400000000000000000000001261505763253600252610ustar00rootroot00000000000000module github.com/maxbrunsfeld/counterfeiter/v6/fixtures/hyphenated_package_same_name counterfeiter-6.12.0/fixtures/hyphenated_package_same_name/hyphen-ated/000077500000000000000000000000001505763253600263625ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/hyphenated_package_same_name/hyphen-ated/some_package/000077500000000000000000000000001505763253600310005ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/hyphenated_package_same_name/hyphen-ated/some_package/types.go000066400000000000000000000002311505763253600324670ustar00rootroot00000000000000package some_package // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/hyphenated_package_same_name/hyphen-ated/some_package" type Thing int counterfeiter-6.12.0/fixtures/hyphenated_package_same_name/some_package/000077500000000000000000000000001505763253600265725ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/hyphenated_package_same_name/some_package/interface.go000066400000000000000000000006011505763253600310560ustar00rootroot00000000000000package some_package // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/hyphenated_package_same_name/some_package" import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/hyphenated_package_same_name/hyphen-ated/some_package" //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . SomeInterface type SomeInterface interface { CreateThing() some_package.Thing } counterfeiter-6.12.0/fixtures/imports_go_hyphen_package.go000066400000000000000000000003511505763253600241010ustar00rootroot00000000000000package fixtures import ( "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/go-hyphenpackage" ) //counterfeiter:generate . ImportsGoHyphenPackage type ImportsGoHyphenPackage interface { UseHyphenType(hyphenpackage.HyphenType) } counterfeiter-6.12.0/fixtures/inline_struct_params.go000066400000000000000000000005401505763253600231160ustar00rootroot00000000000000package fixtures import ( "context" "net/http" "time" ) //counterfeiter:generate . InlineStructParams type InlineStructParams interface { DoSomething(ctx context.Context, body struct { SomeString string SomeStringPointer *string SomeTime time.Time SomeTimePointer *time.Time HTTPRequest http.Request }) error } counterfeiter-6.12.0/fixtures/internalpkg/000077500000000000000000000000001505763253600206615ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/internalpkg/aliased_interface.go000066400000000000000000000003621505763253600246330ustar00rootroot00000000000000package internalpkg import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/internalpkg/internal" //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate . Context type Context = internal.Context counterfeiter-6.12.0/fixtures/internalpkg/internal/000077500000000000000000000000001505763253600224755ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/internalpkg/internal/internal_interface.go000066400000000000000000000000741505763253600266610ustar00rootroot00000000000000package internal type Context interface { DoSomething() } counterfeiter-6.12.0/fixtures/internalpkg/internalpkgfakes/000077500000000000000000000000001505763253600242115ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/internalpkg/internalpkgfakes/fake_context.go000066400000000000000000000033041505763253600272120ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package internalpkgfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/internalpkg" ) type FakeContext struct { DoSomethingStub func() doSomethingMutex sync.RWMutex doSomethingArgsForCall []struct { } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeContext) DoSomething() { fake.doSomethingMutex.Lock() fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { }{}) stub := fake.DoSomethingStub fake.recordInvocation("DoSomething", []interface{}{}) fake.doSomethingMutex.Unlock() if stub != nil { fake.DoSomethingStub() } } func (fake *FakeContext) DoSomethingCallCount() int { fake.doSomethingMutex.RLock() defer fake.doSomethingMutex.RUnlock() return len(fake.doSomethingArgsForCall) } func (fake *FakeContext) DoSomethingCalls(stub func()) { fake.doSomethingMutex.Lock() defer fake.doSomethingMutex.Unlock() fake.DoSomethingStub = stub } func (fake *FakeContext) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeContext) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ internalpkg.Context = new(FakeContext) counterfeiter-6.12.0/fixtures/multiple_interfaces.go000066400000000000000000000003221505763253600227250ustar00rootroot00000000000000package fixtures //counterfeiter:generate . FirstInterface type FirstInterface interface { DoThings() } //counterfeiter:generate . SecondInterface type SecondInterface interface { EmbeddedMethod() string } counterfeiter-6.12.0/fixtures/other_types.go000066400000000000000000000001361505763253600212370ustar00rootroot00000000000000package fixtures type SomeNum uint64 type SomeString string type SomeFunc func(SomeNum) bool counterfeiter-6.12.0/fixtures/packagegen/000077500000000000000000000000001505763253600204305ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/packagegen/apackage/000077500000000000000000000000001505763253600221645ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/packagegen/apackage/apackage.go000066400000000000000000000012401505763253600242440ustar00rootroot00000000000000package ostest import ( "fmt" "os" "time" ) func FindProcess(pid int) (*os.Process, error) { return os.FindProcess(pid) } func Hostname() (name string, err error) { return os.Hostname() } func Expand(s string, mapping func(string) string) string { return os.Expand(s, mapping) } func Clearenv() { os.Clearenv() } func Environ() []string { return os.Environ() } func Chtimes(name string, atime time.Time, mtime time.Time) error { return os.Chtimes(name, atime, mtime) } func MkdirAll(path string, perm os.FileMode) error { return os.MkdirAll(path, perm) } func Exit(code int) { os.Exit(code) } func Fictional(lol ...string) { fmt.Printf("%#v", lol) } counterfeiter-6.12.0/fixtures/packagegen/package_gen.go000066400000000000000000000006561505763253600232120ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package osshim import ( "os" "time" ) type Os interface { FindProcess(pid int) (*os.Process, error) Hostname() (name string, err error) Expand(s string, mapping func(string) string) string Clearenv() Environ() []string Chtimes(name string, atime time.Time, mtime time.Time) error MkdirAll(path string, perm os.FileMode) error Exit(code int) Fictional(lol ...string) } counterfeiter-6.12.0/fixtures/packagemode/000077500000000000000000000000001505763253600206035ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/packagemode/flag.go000066400000000000000000000011411505763253600220400ustar00rootroot00000000000000package packagemode import "flag" //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate -p github.com/maxbrunsfeld/counterfeiter/v6/fixtures/packagemode //counterfeiter:generate -o flagcustomfakesdir -p github.com/maxbrunsfeld/counterfeiter/v6/fixtures/packagemode func Arg(arg1 int) string { return flag.Arg(arg1) } func Args() []string { return flag.Args() } func Bool(arg1 string, arg2 bool, arg3 string) *bool { return flag.Bool(arg1, arg2, arg3) } func BoolVar(arg1 *bool, arg2 string, arg3 bool, arg4 string) { flag.BoolVar(arg1, arg2, arg3, arg4) } counterfeiter-6.12.0/fixtures/packagemode/flagcustomfakesdir/000077500000000000000000000000001505763253600244605ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/packagemode/flagcustomfakesdir/flagcustomfakesdirfakes/000077500000000000000000000000001505763253600313475ustar00rootroot00000000000000fake_packagemode.go000066400000000000000000000161451505763253600350540ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/packagemode/flagcustomfakesdir/flagcustomfakesdirfakes// Code generated by counterfeiter. DO NOT EDIT. package flagcustomfakesdirfakes import ( "sync" packagemodeshim "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/packagemode/flagcustomfakesdir" ) type FakePackagemode struct { ArgStub func(int) string argMutex sync.RWMutex argArgsForCall []struct { arg1 int } argReturns struct { result1 string } argReturnsOnCall map[int]struct { result1 string } ArgsStub func() []string argsMutex sync.RWMutex argsArgsForCall []struct { } argsReturns struct { result1 []string } argsReturnsOnCall map[int]struct { result1 []string } BoolStub func(string, bool, string) *bool boolMutex sync.RWMutex boolArgsForCall []struct { arg1 string arg2 bool arg3 string } boolReturns struct { result1 *bool } boolReturnsOnCall map[int]struct { result1 *bool } BoolVarStub func(*bool, string, bool, string) boolVarMutex sync.RWMutex boolVarArgsForCall []struct { arg1 *bool arg2 string arg3 bool arg4 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakePackagemode) Arg(arg1 int) string { fake.argMutex.Lock() ret, specificReturn := fake.argReturnsOnCall[len(fake.argArgsForCall)] fake.argArgsForCall = append(fake.argArgsForCall, struct { arg1 int }{arg1}) stub := fake.ArgStub fakeReturns := fake.argReturns fake.recordInvocation("Arg", []interface{}{arg1}) fake.argMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakePackagemode) ArgCallCount() int { fake.argMutex.RLock() defer fake.argMutex.RUnlock() return len(fake.argArgsForCall) } func (fake *FakePackagemode) ArgCalls(stub func(int) string) { fake.argMutex.Lock() defer fake.argMutex.Unlock() fake.ArgStub = stub } func (fake *FakePackagemode) ArgArgsForCall(i int) int { fake.argMutex.RLock() defer fake.argMutex.RUnlock() argsForCall := fake.argArgsForCall[i] return argsForCall.arg1 } func (fake *FakePackagemode) ArgReturns(result1 string) { fake.argMutex.Lock() defer fake.argMutex.Unlock() fake.ArgStub = nil fake.argReturns = struct { result1 string }{result1} } func (fake *FakePackagemode) ArgReturnsOnCall(i int, result1 string) { fake.argMutex.Lock() defer fake.argMutex.Unlock() fake.ArgStub = nil if fake.argReturnsOnCall == nil { fake.argReturnsOnCall = make(map[int]struct { result1 string }) } fake.argReturnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakePackagemode) Args() []string { fake.argsMutex.Lock() ret, specificReturn := fake.argsReturnsOnCall[len(fake.argsArgsForCall)] fake.argsArgsForCall = append(fake.argsArgsForCall, struct { }{}) stub := fake.ArgsStub fakeReturns := fake.argsReturns fake.recordInvocation("Args", []interface{}{}) fake.argsMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakePackagemode) ArgsCallCount() int { fake.argsMutex.RLock() defer fake.argsMutex.RUnlock() return len(fake.argsArgsForCall) } func (fake *FakePackagemode) ArgsCalls(stub func() []string) { fake.argsMutex.Lock() defer fake.argsMutex.Unlock() fake.ArgsStub = stub } func (fake *FakePackagemode) ArgsReturns(result1 []string) { fake.argsMutex.Lock() defer fake.argsMutex.Unlock() fake.ArgsStub = nil fake.argsReturns = struct { result1 []string }{result1} } func (fake *FakePackagemode) ArgsReturnsOnCall(i int, result1 []string) { fake.argsMutex.Lock() defer fake.argsMutex.Unlock() fake.ArgsStub = nil if fake.argsReturnsOnCall == nil { fake.argsReturnsOnCall = make(map[int]struct { result1 []string }) } fake.argsReturnsOnCall[i] = struct { result1 []string }{result1} } func (fake *FakePackagemode) Bool(arg1 string, arg2 bool, arg3 string) *bool { fake.boolMutex.Lock() ret, specificReturn := fake.boolReturnsOnCall[len(fake.boolArgsForCall)] fake.boolArgsForCall = append(fake.boolArgsForCall, struct { arg1 string arg2 bool arg3 string }{arg1, arg2, arg3}) stub := fake.BoolStub fakeReturns := fake.boolReturns fake.recordInvocation("Bool", []interface{}{arg1, arg2, arg3}) fake.boolMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakePackagemode) BoolCallCount() int { fake.boolMutex.RLock() defer fake.boolMutex.RUnlock() return len(fake.boolArgsForCall) } func (fake *FakePackagemode) BoolCalls(stub func(string, bool, string) *bool) { fake.boolMutex.Lock() defer fake.boolMutex.Unlock() fake.BoolStub = stub } func (fake *FakePackagemode) BoolArgsForCall(i int) (string, bool, string) { fake.boolMutex.RLock() defer fake.boolMutex.RUnlock() argsForCall := fake.boolArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 } func (fake *FakePackagemode) BoolReturns(result1 *bool) { fake.boolMutex.Lock() defer fake.boolMutex.Unlock() fake.BoolStub = nil fake.boolReturns = struct { result1 *bool }{result1} } func (fake *FakePackagemode) BoolReturnsOnCall(i int, result1 *bool) { fake.boolMutex.Lock() defer fake.boolMutex.Unlock() fake.BoolStub = nil if fake.boolReturnsOnCall == nil { fake.boolReturnsOnCall = make(map[int]struct { result1 *bool }) } fake.boolReturnsOnCall[i] = struct { result1 *bool }{result1} } func (fake *FakePackagemode) BoolVar(arg1 *bool, arg2 string, arg3 bool, arg4 string) { fake.boolVarMutex.Lock() fake.boolVarArgsForCall = append(fake.boolVarArgsForCall, struct { arg1 *bool arg2 string arg3 bool arg4 string }{arg1, arg2, arg3, arg4}) stub := fake.BoolVarStub fake.recordInvocation("BoolVar", []interface{}{arg1, arg2, arg3, arg4}) fake.boolVarMutex.Unlock() if stub != nil { fake.BoolVarStub(arg1, arg2, arg3, arg4) } } func (fake *FakePackagemode) BoolVarCallCount() int { fake.boolVarMutex.RLock() defer fake.boolVarMutex.RUnlock() return len(fake.boolVarArgsForCall) } func (fake *FakePackagemode) BoolVarCalls(stub func(*bool, string, bool, string)) { fake.boolVarMutex.Lock() defer fake.boolVarMutex.Unlock() fake.BoolVarStub = stub } func (fake *FakePackagemode) BoolVarArgsForCall(i int) (*bool, string, bool, string) { fake.boolVarMutex.RLock() defer fake.boolVarMutex.RUnlock() argsForCall := fake.boolVarArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 } func (fake *FakePackagemode) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakePackagemode) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ packagemodeshim.Packagemode = new(FakePackagemode) counterfeiter-6.12.0/fixtures/packagemode/flagcustomfakesdir/packagemode.go000066400000000000000000000020711505763253600272470ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package packagemodeshim import ( "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/packagemode" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate . Packagemode // Packagemode is a generated interface representing the exported functions // in the github.com/maxbrunsfeld/counterfeiter/v6/fixtures/packagemode package. type Packagemode interface { Arg(arg1 int) string Args() []string Bool(arg1 string, arg2 bool, arg3 string) *bool BoolVar(arg1 *bool, arg2 string, arg3 bool, arg4 string) } type PackagemodeShim struct{} func (p *PackagemodeShim) Arg(arg1 int) string { return packagemode.Arg(arg1) } func (p *PackagemodeShim) Args() []string { return packagemode.Args() } func (p *PackagemodeShim) Bool(arg1 string, arg2 bool, arg3 string) *bool { return packagemode.Bool(arg1, arg2, arg3) } func (p *PackagemodeShim) BoolVar(arg1 *bool, arg2 string, arg3 bool, arg4 string) { packagemode.BoolVar(arg1, arg2, arg3, arg4) } var _ Packagemode = new(PackagemodeShim) counterfeiter-6.12.0/fixtures/packagemode/packagemodeshim/000077500000000000000000000000001505763253600237245ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/packagemode/packagemodeshim/packagemode.go000066400000000000000000000020711505763253600265130ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package packagemodeshim import ( "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/packagemode" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate . Packagemode // Packagemode is a generated interface representing the exported functions // in the github.com/maxbrunsfeld/counterfeiter/v6/fixtures/packagemode package. type Packagemode interface { Arg(arg1 int) string Args() []string Bool(arg1 string, arg2 bool, arg3 string) *bool BoolVar(arg1 *bool, arg2 string, arg3 bool, arg4 string) } type PackagemodeShim struct{} func (p *PackagemodeShim) Arg(arg1 int) string { return packagemode.Arg(arg1) } func (p *PackagemodeShim) Args() []string { return packagemode.Args() } func (p *PackagemodeShim) Bool(arg1 string, arg2 bool, arg3 string) *bool { return packagemode.Bool(arg1, arg2, arg3) } func (p *PackagemodeShim) BoolVar(arg1 *bool, arg2 string, arg3 bool, arg4 string) { packagemode.BoolVar(arg1, arg2, arg3, arg4) } var _ Packagemode = new(PackagemodeShim) counterfeiter-6.12.0/fixtures/packagemode/packagemodeshim/packagemodeshimfakes/000077500000000000000000000000001505763253600300575ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/packagemode/packagemodeshim/packagemodeshimfakes/fake_packagemode.go000066400000000000000000000161171505763253600336420ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package packagemodeshimfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/packagemode/packagemodeshim" ) type FakePackagemode struct { ArgStub func(int) string argMutex sync.RWMutex argArgsForCall []struct { arg1 int } argReturns struct { result1 string } argReturnsOnCall map[int]struct { result1 string } ArgsStub func() []string argsMutex sync.RWMutex argsArgsForCall []struct { } argsReturns struct { result1 []string } argsReturnsOnCall map[int]struct { result1 []string } BoolStub func(string, bool, string) *bool boolMutex sync.RWMutex boolArgsForCall []struct { arg1 string arg2 bool arg3 string } boolReturns struct { result1 *bool } boolReturnsOnCall map[int]struct { result1 *bool } BoolVarStub func(*bool, string, bool, string) boolVarMutex sync.RWMutex boolVarArgsForCall []struct { arg1 *bool arg2 string arg3 bool arg4 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakePackagemode) Arg(arg1 int) string { fake.argMutex.Lock() ret, specificReturn := fake.argReturnsOnCall[len(fake.argArgsForCall)] fake.argArgsForCall = append(fake.argArgsForCall, struct { arg1 int }{arg1}) stub := fake.ArgStub fakeReturns := fake.argReturns fake.recordInvocation("Arg", []interface{}{arg1}) fake.argMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakePackagemode) ArgCallCount() int { fake.argMutex.RLock() defer fake.argMutex.RUnlock() return len(fake.argArgsForCall) } func (fake *FakePackagemode) ArgCalls(stub func(int) string) { fake.argMutex.Lock() defer fake.argMutex.Unlock() fake.ArgStub = stub } func (fake *FakePackagemode) ArgArgsForCall(i int) int { fake.argMutex.RLock() defer fake.argMutex.RUnlock() argsForCall := fake.argArgsForCall[i] return argsForCall.arg1 } func (fake *FakePackagemode) ArgReturns(result1 string) { fake.argMutex.Lock() defer fake.argMutex.Unlock() fake.ArgStub = nil fake.argReturns = struct { result1 string }{result1} } func (fake *FakePackagemode) ArgReturnsOnCall(i int, result1 string) { fake.argMutex.Lock() defer fake.argMutex.Unlock() fake.ArgStub = nil if fake.argReturnsOnCall == nil { fake.argReturnsOnCall = make(map[int]struct { result1 string }) } fake.argReturnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakePackagemode) Args() []string { fake.argsMutex.Lock() ret, specificReturn := fake.argsReturnsOnCall[len(fake.argsArgsForCall)] fake.argsArgsForCall = append(fake.argsArgsForCall, struct { }{}) stub := fake.ArgsStub fakeReturns := fake.argsReturns fake.recordInvocation("Args", []interface{}{}) fake.argsMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakePackagemode) ArgsCallCount() int { fake.argsMutex.RLock() defer fake.argsMutex.RUnlock() return len(fake.argsArgsForCall) } func (fake *FakePackagemode) ArgsCalls(stub func() []string) { fake.argsMutex.Lock() defer fake.argsMutex.Unlock() fake.ArgsStub = stub } func (fake *FakePackagemode) ArgsReturns(result1 []string) { fake.argsMutex.Lock() defer fake.argsMutex.Unlock() fake.ArgsStub = nil fake.argsReturns = struct { result1 []string }{result1} } func (fake *FakePackagemode) ArgsReturnsOnCall(i int, result1 []string) { fake.argsMutex.Lock() defer fake.argsMutex.Unlock() fake.ArgsStub = nil if fake.argsReturnsOnCall == nil { fake.argsReturnsOnCall = make(map[int]struct { result1 []string }) } fake.argsReturnsOnCall[i] = struct { result1 []string }{result1} } func (fake *FakePackagemode) Bool(arg1 string, arg2 bool, arg3 string) *bool { fake.boolMutex.Lock() ret, specificReturn := fake.boolReturnsOnCall[len(fake.boolArgsForCall)] fake.boolArgsForCall = append(fake.boolArgsForCall, struct { arg1 string arg2 bool arg3 string }{arg1, arg2, arg3}) stub := fake.BoolStub fakeReturns := fake.boolReturns fake.recordInvocation("Bool", []interface{}{arg1, arg2, arg3}) fake.boolMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3) } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakePackagemode) BoolCallCount() int { fake.boolMutex.RLock() defer fake.boolMutex.RUnlock() return len(fake.boolArgsForCall) } func (fake *FakePackagemode) BoolCalls(stub func(string, bool, string) *bool) { fake.boolMutex.Lock() defer fake.boolMutex.Unlock() fake.BoolStub = stub } func (fake *FakePackagemode) BoolArgsForCall(i int) (string, bool, string) { fake.boolMutex.RLock() defer fake.boolMutex.RUnlock() argsForCall := fake.boolArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 } func (fake *FakePackagemode) BoolReturns(result1 *bool) { fake.boolMutex.Lock() defer fake.boolMutex.Unlock() fake.BoolStub = nil fake.boolReturns = struct { result1 *bool }{result1} } func (fake *FakePackagemode) BoolReturnsOnCall(i int, result1 *bool) { fake.boolMutex.Lock() defer fake.boolMutex.Unlock() fake.BoolStub = nil if fake.boolReturnsOnCall == nil { fake.boolReturnsOnCall = make(map[int]struct { result1 *bool }) } fake.boolReturnsOnCall[i] = struct { result1 *bool }{result1} } func (fake *FakePackagemode) BoolVar(arg1 *bool, arg2 string, arg3 bool, arg4 string) { fake.boolVarMutex.Lock() fake.boolVarArgsForCall = append(fake.boolVarArgsForCall, struct { arg1 *bool arg2 string arg3 bool arg4 string }{arg1, arg2, arg3, arg4}) stub := fake.BoolVarStub fake.recordInvocation("BoolVar", []interface{}{arg1, arg2, arg3, arg4}) fake.boolVarMutex.Unlock() if stub != nil { fake.BoolVarStub(arg1, arg2, arg3, arg4) } } func (fake *FakePackagemode) BoolVarCallCount() int { fake.boolVarMutex.RLock() defer fake.boolVarMutex.RUnlock() return len(fake.boolVarArgsForCall) } func (fake *FakePackagemode) BoolVarCalls(stub func(*bool, string, bool, string)) { fake.boolVarMutex.Lock() defer fake.boolVarMutex.Unlock() fake.BoolVarStub = stub } func (fake *FakePackagemode) BoolVarArgsForCall(i int) (*bool, string, bool, string) { fake.boolVarMutex.RLock() defer fake.boolVarMutex.RUnlock() argsForCall := fake.boolVarArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 } func (fake *FakePackagemode) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakePackagemode) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ packagemodeshim.Packagemode = new(FakePackagemode) counterfeiter-6.12.0/fixtures/request_factory.go000066400000000000000000000002071505763253600221100ustar00rootroot00000000000000package fixtures type Params struct{} type Request struct{} type RequestFactory func(Params, map[string]interface{}) (Request, error) counterfeiter-6.12.0/fixtures/reuses_arg_types.go000066400000000000000000000001651505763253600222570ustar00rootroot00000000000000package fixtures //counterfeiter:generate . ReusesArgTypes type ReusesArgTypes interface { DoThings(x, y string) } counterfeiter-6.12.0/fixtures/something.go000066400000000000000000000002561505763253600206720ustar00rootroot00000000000000package fixtures //counterfeiter:generate . Something type Something interface { DoThings(string, uint64) (int, error) DoNothing() DoASlice([]byte) DoAnArray([4]byte) } counterfeiter-6.12.0/fixtures/something_remote.go000066400000000000000000000005251505763253600222440ustar00rootroot00000000000000package fixtures import the_aliased_package "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/aliased_package" //counterfeiter:generate . SomethingWithForeignInterface // SomethingWithForeignInterface is an interface that embeds a foreign interface. type SomethingWithForeignInterface interface { the_aliased_package.InAliasedPackage } counterfeiter-6.12.0/fixtures/sql/000077500000000000000000000000001505763253600171425ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/sql/db.go000066400000000000000000000002361505763253600200570ustar00rootroot00000000000000package sql import ( "database/sql" ) //go:generate counterfeiter . DB type DB interface { Exec(query string, args ...interface{}) (sql.Result, error) } counterfeiter-6.12.0/fixtures/sql/sqlfakes/000077500000000000000000000000001505763253600207535ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/sql/sqlfakes/fake_db.go000066400000000000000000000056541505763253600226670ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package sqlfakes import ( sqla "database/sql" "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/sql" ) type FakeDB struct { ExecStub func(string, ...interface{}) (sqla.Result, error) execMutex sync.RWMutex execArgsForCall []struct { arg1 string arg2 []interface{} } execReturns struct { result1 sqla.Result result2 error } execReturnsOnCall map[int]struct { result1 sqla.Result result2 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeDB) Exec(arg1 string, arg2 ...interface{}) (sqla.Result, error) { fake.execMutex.Lock() ret, specificReturn := fake.execReturnsOnCall[len(fake.execArgsForCall)] fake.execArgsForCall = append(fake.execArgsForCall, struct { arg1 string arg2 []interface{} }{arg1, arg2}) stub := fake.ExecStub fakeReturns := fake.execReturns fake.recordInvocation("Exec", []interface{}{arg1, arg2}) fake.execMutex.Unlock() if stub != nil { return stub(arg1, arg2...) } if specificReturn { return ret.result1, ret.result2 } return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeDB) ExecCallCount() int { fake.execMutex.RLock() defer fake.execMutex.RUnlock() return len(fake.execArgsForCall) } func (fake *FakeDB) ExecCalls(stub func(string, ...interface{}) (sqla.Result, error)) { fake.execMutex.Lock() defer fake.execMutex.Unlock() fake.ExecStub = stub } func (fake *FakeDB) ExecArgsForCall(i int) (string, []interface{}) { fake.execMutex.RLock() defer fake.execMutex.RUnlock() argsForCall := fake.execArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeDB) ExecReturns(result1 sqla.Result, result2 error) { fake.execMutex.Lock() defer fake.execMutex.Unlock() fake.ExecStub = nil fake.execReturns = struct { result1 sqla.Result result2 error }{result1, result2} } func (fake *FakeDB) ExecReturnsOnCall(i int, result1 sqla.Result, result2 error) { fake.execMutex.Lock() defer fake.execMutex.Unlock() fake.ExecStub = nil if fake.execReturnsOnCall == nil { fake.execReturnsOnCall = make(map[int]struct { result1 sqla.Result result2 error }) } fake.execReturnsOnCall[i] = struct { result1 sqla.Result result2 error }{result1, result2} } func (fake *FakeDB) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeDB) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ sql.DB = new(FakeDB) counterfeiter-6.12.0/fixtures/sync/000077500000000000000000000000001505763253600173175ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/sync/interface.go000066400000000000000000000004321505763253600216050ustar00rootroot00000000000000package sync // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/sync" //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . SyncSomething type SyncSomething interface { DoThings(string, uint64) (int, error) DoNothing() DoASlice([]byte) DoAnArray([4]byte) } counterfeiter-6.12.0/fixtures/sync/syncfakes/000077500000000000000000000000001505763253600213055ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/sync/syncfakes/fake_sync_something.go000066400000000000000000000134751505763253600256650ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package syncfakes import ( "sync" synca "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/sync" ) type FakeSyncSomething struct { DoASliceStub func([]byte) doASliceMutex sync.RWMutex doASliceArgsForCall []struct { arg1 []byte } DoAnArrayStub func([4]byte) doAnArrayMutex sync.RWMutex doAnArrayArgsForCall []struct { arg1 [4]byte } DoNothingStub func() doNothingMutex sync.RWMutex doNothingArgsForCall []struct { } DoThingsStub func(string, uint64) (int, error) doThingsMutex sync.RWMutex doThingsArgsForCall []struct { arg1 string arg2 uint64 } doThingsReturns struct { result1 int result2 error } doThingsReturnsOnCall map[int]struct { result1 int result2 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeSyncSomething) DoASlice(arg1 []byte) { var arg1Copy []byte if arg1 != nil { arg1Copy = make([]byte, len(arg1)) copy(arg1Copy, arg1) } fake.doASliceMutex.Lock() fake.doASliceArgsForCall = append(fake.doASliceArgsForCall, struct { arg1 []byte }{arg1Copy}) stub := fake.DoASliceStub fake.recordInvocation("DoASlice", []interface{}{arg1Copy}) fake.doASliceMutex.Unlock() if stub != nil { fake.DoASliceStub(arg1) } } func (fake *FakeSyncSomething) DoASliceCallCount() int { fake.doASliceMutex.RLock() defer fake.doASliceMutex.RUnlock() return len(fake.doASliceArgsForCall) } func (fake *FakeSyncSomething) DoASliceCalls(stub func([]byte)) { fake.doASliceMutex.Lock() defer fake.doASliceMutex.Unlock() fake.DoASliceStub = stub } func (fake *FakeSyncSomething) DoASliceArgsForCall(i int) []byte { fake.doASliceMutex.RLock() defer fake.doASliceMutex.RUnlock() argsForCall := fake.doASliceArgsForCall[i] return argsForCall.arg1 } func (fake *FakeSyncSomething) DoAnArray(arg1 [4]byte) { fake.doAnArrayMutex.Lock() fake.doAnArrayArgsForCall = append(fake.doAnArrayArgsForCall, struct { arg1 [4]byte }{arg1}) stub := fake.DoAnArrayStub fake.recordInvocation("DoAnArray", []interface{}{arg1}) fake.doAnArrayMutex.Unlock() if stub != nil { fake.DoAnArrayStub(arg1) } } func (fake *FakeSyncSomething) DoAnArrayCallCount() int { fake.doAnArrayMutex.RLock() defer fake.doAnArrayMutex.RUnlock() return len(fake.doAnArrayArgsForCall) } func (fake *FakeSyncSomething) DoAnArrayCalls(stub func([4]byte)) { fake.doAnArrayMutex.Lock() defer fake.doAnArrayMutex.Unlock() fake.DoAnArrayStub = stub } func (fake *FakeSyncSomething) DoAnArrayArgsForCall(i int) [4]byte { fake.doAnArrayMutex.RLock() defer fake.doAnArrayMutex.RUnlock() argsForCall := fake.doAnArrayArgsForCall[i] return argsForCall.arg1 } func (fake *FakeSyncSomething) DoNothing() { fake.doNothingMutex.Lock() fake.doNothingArgsForCall = append(fake.doNothingArgsForCall, struct { }{}) stub := fake.DoNothingStub fake.recordInvocation("DoNothing", []interface{}{}) fake.doNothingMutex.Unlock() if stub != nil { fake.DoNothingStub() } } func (fake *FakeSyncSomething) DoNothingCallCount() int { fake.doNothingMutex.RLock() defer fake.doNothingMutex.RUnlock() return len(fake.doNothingArgsForCall) } func (fake *FakeSyncSomething) DoNothingCalls(stub func()) { fake.doNothingMutex.Lock() defer fake.doNothingMutex.Unlock() fake.DoNothingStub = stub } func (fake *FakeSyncSomething) DoThings(arg1 string, arg2 uint64) (int, error) { fake.doThingsMutex.Lock() ret, specificReturn := fake.doThingsReturnsOnCall[len(fake.doThingsArgsForCall)] fake.doThingsArgsForCall = append(fake.doThingsArgsForCall, struct { arg1 string arg2 uint64 }{arg1, arg2}) stub := fake.DoThingsStub fakeReturns := fake.doThingsReturns fake.recordInvocation("DoThings", []interface{}{arg1, arg2}) fake.doThingsMutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1, ret.result2 } return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeSyncSomething) DoThingsCallCount() int { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() return len(fake.doThingsArgsForCall) } func (fake *FakeSyncSomething) DoThingsCalls(stub func(string, uint64) (int, error)) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = stub } func (fake *FakeSyncSomething) DoThingsArgsForCall(i int) (string, uint64) { fake.doThingsMutex.RLock() defer fake.doThingsMutex.RUnlock() argsForCall := fake.doThingsArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeSyncSomething) DoThingsReturns(result1 int, result2 error) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil fake.doThingsReturns = struct { result1 int result2 error }{result1, result2} } func (fake *FakeSyncSomething) DoThingsReturnsOnCall(i int, result1 int, result2 error) { fake.doThingsMutex.Lock() defer fake.doThingsMutex.Unlock() fake.DoThingsStub = nil if fake.doThingsReturnsOnCall == nil { fake.doThingsReturnsOnCall = make(map[int]struct { result1 int result2 error }) } fake.doThingsReturnsOnCall[i] = struct { result1 int result2 error }{result1, result2} } func (fake *FakeSyncSomething) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeSyncSomething) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ synca.SyncSomething = new(FakeSyncSomething) counterfeiter-6.12.0/fixtures/type_aliases/000077500000000000000000000000001505763253600210255ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/type_aliases/extra/000077500000000000000000000000001505763253600221505ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/type_aliases/extra/m.go000066400000000000000000000003161505763253600227330ustar00rootroot00000000000000package extra // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/extra" import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/extra/primitive" type M = primitive.M counterfeiter-6.12.0/fixtures/type_aliases/extra/primitive/000077500000000000000000000000001505763253600241605ustar00rootroot00000000000000counterfeiter-6.12.0/fixtures/type_aliases/extra/primitive/m.go000066400000000000000000000002061505763253600247410ustar00rootroot00000000000000package primitive // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/primitive" type M map[string]interface{} counterfeiter-6.12.0/fixtures/type_aliases/go.mod000066400000000000000000000001171505763253600221320ustar00rootroot00000000000000module github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases go 1.22 counterfeiter-6.12.0/fixtures/type_aliases/interface.go000066400000000000000000000006341505763253600233170ustar00rootroot00000000000000package type_aliases // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases" import ( "context" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/extra" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //counterfeiter:generate . WithAliasedType type WithAliasedType interface { FindExample(ctx context.Context, filter extra.M) ([]string, error) } counterfeiter-6.12.0/fixtures/typed_function.go000066400000000000000000000002001505763253600217140ustar00rootroot00000000000000package fixtures //counterfeiter:generate . SomethingFactory type SomethingFactory func(string, map[string]interface{}) string counterfeiter-6.12.0/fixtures/unexported.go000066400000000000000000000004021505763253600210630ustar00rootroot00000000000000package fixtures //counterfeiter:generate . unexportedFunc type unexportedFunc func(string, map[string]interface{}) string //counterfeiter:generate . unexportedInterface type unexportedInterface interface { Method(string, map[string]interface{}) string } counterfeiter-6.12.0/generated_fakes_test.go000066400000000000000000000170311505763253600211710ustar00rootroot00000000000000package main_test import ( "errors" "testing" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/fixturesfakes" . "github.com/onsi/gomega" "github.com/sclevine/spec" "github.com/sclevine/spec/report" ) func TestFakes(t *testing.T) { spec.Run(t, "Fakes", testFakes, spec.Report(report.Terminal{})) } func testFakes(t *testing.T, when spec.G, it spec.S) { it.Before(func() { RegisterTestingT(t) }) var fake *fixturesfakes.FakeSomething it.Before(func() { fake = new(fixturesfakes.FakeSomething) }) it("implements the specified interface", func() { var interfaceVal fixtures.Something = fake Expect(interfaceVal).NotTo(BeNil()) }) it("can have its behavior configured using stub functions", func() { fake.DoThingsStub = func(arg1 string, arg2 uint64) (int, error) { Expect(arg1).To(Equal("stuff")) Expect(arg2).To(Equal(uint64(5))) return 3, errors.New("the-error") } num, err := fake.DoThings("stuff", 5) Expect(num).To(Equal(3)) Expect(err).To(Equal(errors.New("the-error"))) }) it("can have its return values configured", func() { fake.DoThingsReturns(3, errors.New("the-error")) num, err := fake.DoThings("stuff", 5) Expect(num).To(Equal(3)) Expect(err).To(Equal(errors.New("the-error"))) }) it("returns zero values when no return value or stub is provided", func() { num, err := fake.DoThings("stuff", 5) Expect(num).To(Equal(0)) Expect(err).To(BeNil()) }) it("allows overriding previous stub functions with return values", func() { fake.DoThingsStub = func(arg1 string, arg2 uint64) (int, error) { return 3, errors.New("the-error") } fake.DoThingsReturns(4, errors.New("other-error")) num, err := fake.DoThings("stuff", 5) Expect(num).To(Equal(4)) Expect(err).To(Equal(errors.New("other-error"))) }) it("records the arguments it was called with", func() { Expect(fake.DoThingsCallCount()).To(Equal(0)) _, _ = fake.DoThings("stuff", 5) Expect(fake.DoThingsCallCount()).To(Equal(1)) arg1, arg2 := fake.DoThingsArgsForCall(0) Expect(arg1).To(Equal("stuff")) Expect(arg2).To(Equal(uint64(5))) }) it("records a slice argument as a copy", func() { buffer := []byte{1} fake.DoASlice(buffer) buffer[0] = 2 arg1 := fake.DoASliceArgsForCall(0) Expect(arg1).To(ConsistOf(byte(1))) }) it("records a nil slice argument as a nil", func() { var buffer []byte = nil fake.DoASlice(buffer) arg1 := fake.DoASliceArgsForCall(0) Expect(arg1).To(BeNil()) }) it("records an array argument as a copy", func() { buffer := [4]byte{1, 2, 3, 4} fake.DoAnArray(buffer) buffer[0] = 2 arg1 := fake.DoAnArrayArgsForCall(0) Expect(arg1).To(ConsistOf(byte(1), byte(2), byte(3), byte(4))) }) it("passes the original slice to a stub function", func() { buffer := []byte{1} fake.DoASliceStub = func(b []byte) { b[0] = 2 } fake.DoASlice(buffer) arg1 := fake.DoASliceArgsForCall(0) Expect(arg1).To(ConsistOf(byte(1))) Expect(buffer).To(ConsistOf(byte(2))) }) it("records its calls without race conditions", func() { go fake.DoNothing() Eventually(fake.DoNothingCallCount, 1.0).Should(Equal(1)) }) when("implementing an interface to show recorded methoded invocations", func() { it.Before(func() { var ifake interface{} = fake _, ok := ifake.(InvocationRecorder) Expect(ok).To(BeTrue()) }) it("records each invocation", func() { Expect(len(fake.Invocations()["DoThings"])).To(Equal(0)) Expect(len(fake.Invocations()["DoNothing"])).To(Equal(0)) Expect(len(fake.Invocations()["DoASlice"])).To(Equal(0)) Expect(len(fake.Invocations()["DoAnArray"])).To(Equal(0)) _, _ = fake.DoThings("hello", 0) Expect(len(fake.Invocations()["DoThings"])).To(Equal(1)) Expect(fake.Invocations()["DoThings"][0][0]).To(Equal("hello")) Expect(fake.Invocations()["DoThings"][0][1]).To(Equal(uint64(0))) fake.DoNothing() Expect(len(fake.Invocations()["DoNothing"])).To(Equal(1)) fake.DoASlice([]byte("HAI")) Expect(len(fake.Invocations()["DoASlice"])).To(Equal(1)) Expect(fake.Invocations()["DoASlice"][0][0]).To(Equal([]byte("HAI"))) fake.DoAnArray([4]byte{}) Expect(len(fake.Invocations()["DoAnArray"])).To(Equal(1)) Expect(fake.Invocations()["DoAnArray"][0][0]).ToNot(BeNil()) }) }) when("when two methods are called at the same time", func() { var start1 chan struct{} var start2 chan struct{} var end1 chan struct{} var end2 chan struct{} it.Before(func() { start1 = make(chan struct{}) end1 = make(chan struct{}) start2 = make(chan struct{}) end2 = make(chan struct{}) fake.DoNothingStub = func() { close(start1) end1 <- struct{}{} } fake.DoThingsStub = func(string, uint64) (int, error) { close(start2) end2 <- struct{}{} return 0, nil } go fake.DoNothing() <-start1 go func() { _, _ = fake.DoThings("abc", 1) }() <-start2 }) it.After(func() { close(end1) close(end2) }) it("does not deadlock", func() { Eventually(start1).Should(BeClosed()) Eventually(end1).Should(Receive()) Eventually(start2).Should(BeClosed()) Eventually(end2).Should(Receive()) }) }) when("when methods are called concurrently", func() { it.Before(func() { go fake.DoNothing() go func() { _, _ = fake.DoThings("", 0) }() }) it("records the call count without race conditions", func() { Eventually(fake.DoNothingCallCount).Should(Equal(1)) Eventually(fake.DoThingsCallCount).Should(Equal(1)) }) it("records the invocations without race conditions as well", func() { Eventually(func() [][]interface{} { return fake.Invocations()["DoNothing"] }).Should(HaveLen(1)) Eventually(func() [][]interface{} { return fake.Invocations()["DoThings"] }).Should(HaveLen(1)) }) }) when("when the same method is called concurrently", func() { it("does not deadlock", func() { Eventually(func() bool { a := make(chan struct{}) b := make(chan struct{}) fake.DoNothingStub = func() { select { case <-a: close(b) default: <-b } } count := 100 for i := 0; i < count; i++ { go fake.DoNothing() } sent := 0 for i := 0; i < count; i++ { b <- struct{}{} sent++ } close(a) close(b) return true }).Should(Equal(true)) }) }) when("interfaces with var-args methods", func() { var fake *fixturesfakes.FakeHasVarArgs it.Before(func() { fake = new(fixturesfakes.FakeHasVarArgs) }) it("implements the interface", func() { var interfaceVal fixtures.HasVarArgs = fake Expect(interfaceVal).NotTo(BeNil()) }) it("records the calls in a slice", func() { fake.DoThings(5, "one", "two", "three") num, strings := fake.DoThingsArgsForCall(0) Expect(num).To(Equal(5)) Expect(strings).To(Equal([]string{"one", "two", "three"})) }) it("passes the var-args to stub functions", func() { fake.DoThingsStub = func(x int, strings ...string) int { Expect(strings).To(Equal([]string{"one", "two", "three"})) return 11 } val := fake.DoThings(5, "one", "two", "three") Expect(val).To(Equal(11)) }) }) when("calling a function repeatedly and changing the returns value", func() { var fake *fixturesfakes.FakeSomething it.Before(func() { fake = new(fixturesfakes.FakeSomething) }) it("succeeds and does not cause a data race", func() { go fake.DoThingsReturns(1, nil) go func() { _, _ = fake.DoThings("1", 1) }() go fake.DoThingsReturns(1, nil) go func() { _, _ = fake.DoThings("1", 1) }() }) }) } type InvocationRecorder interface { Invocations() map[string][][]interface{} } counterfeiter-6.12.0/generator/000077500000000000000000000000001505763253600164605ustar00rootroot00000000000000counterfeiter-6.12.0/generator/cache.go000066400000000000000000000015211505763253600200510ustar00rootroot00000000000000package generator import "golang.org/x/tools/go/packages" type Cache struct { packageMap map[string]interface{} } type FakeCache struct{} func (c *FakeCache) Load(packagePath string) ([]*packages.Package, bool) { return nil, false } func (c *FakeCache) Store(packagePath string, packages []*packages.Package) {} type Cacher interface { Load(packagePath string) ([]*packages.Package, bool) Store(packagePath string, packages []*packages.Package) } func (c *Cache) Load(packagePath string) ([]*packages.Package, bool) { p, ok := c.packageMap[packagePath] if !ok { return nil, false } packages, ok := p.([]*packages.Package) return packages, ok } func (c *Cache) Store(packagePath string, packages []*packages.Package) { if c.packageMap == nil { c.packageMap = map[string]interface{}{} } c.packageMap[packagePath] = packages } counterfeiter-6.12.0/generator/ctx.go000066400000000000000000000002531505763253600176050ustar00rootroot00000000000000//go:build go1.14 package generator import "go/build" func getBuildContext(workingDir string) build.Context { ctx := build.Default ctx.Dir = workingDir return ctx } counterfeiter-6.12.0/generator/ctx_old.go000066400000000000000000000002261505763253600204430ustar00rootroot00000000000000//go:build !go1.14 package generator import "go/build" func getBuildContext(workingDir string) build.Context { ctx := build.Default return ctx } counterfeiter-6.12.0/generator/fake.go000066400000000000000000000136601505763253600177230ustar00rootroot00000000000000package generator import ( "bytes" "errors" "go/types" "log" "strings" "text/template" "unicode" "unicode/utf8" "golang.org/x/tools/go/packages" "golang.org/x/tools/imports" ) // FakeMode indicates the type of Fake to generate. type FakeMode int // FakeMode can be Interface, Function, or Package. const ( InterfaceOrFunction FakeMode = iota Package ) // Fake is used to generate a Fake implementation of an interface. type Fake struct { Packages []*packages.Package Package *packages.Package Target *types.TypeName Mode FakeMode DestinationPackage string Name string GenericTypeParametersAndConstraints string GenericTypeParameters string GenericTypeConstraints string TargetAlias string TargetName string TargetPackage string Imports Imports Methods []Method Function Method Header string } // Method is a method of the interface. type Method struct { Name string Params Params Returns Returns } // NewFake returns a Fake that loads the package and finds the interface or the // function. func NewFake(fakeMode FakeMode, targetName string, packagePath string, fakeName string, destinationPackage string, headerContent string, workingDir string, cache Cacher) (*Fake, error) { f := &Fake{ TargetName: targetName, TargetPackage: packagePath, Name: fakeName, Mode: fakeMode, DestinationPackage: destinationPackage, Imports: newImports(), Header: headerContent, } f.Imports.Add("sync", "sync") err := f.loadPackages(cache, workingDir) if err != nil { return nil, err } // TODO: Package mode here err = f.findPackage() if err != nil { return nil, err } if f.IsInterface() || f.Mode == Package { f.loadMethods() } if f.IsFunction() { err = f.loadMethodForFunction() if err != nil { return nil, err } } return f, nil } // IsInterface indicates whether the fake is for an interface. func (f *Fake) IsInterface() bool { if f.Target == nil || f.Target.Type() == nil { return false } return types.IsInterface(f.Target.Type()) } // IsFunction indicates whether the fake is for a function.. func (f *Fake) IsFunction() bool { if f.Target == nil || f.Target.Type() == nil || f.Target.Type().Underlying() == nil { return false } _, ok := f.Target.Type().Underlying().(*types.Signature) return ok } // IsConstraintInterface indicates whether the interface is a constraint interface // (contains type constraints like ~string) which cannot be implemented by concrete types. func (f *Fake) IsConstraintInterface() bool { if !f.IsInterface() { return false } iface, ok := f.Target.Type().Underlying().(*types.Interface) if !ok { return false } // check if the interface has any type constraints for i := 0; i < iface.NumEmbeddeds(); i++ { if _, ok := iface.EmbeddedType(i).(*types.Union); ok { return true } } // check for approximation constraints by examining the string representation // a bit of a hack, but the Go types API doesn't expose type constraints cleanly return strings.Contains(iface.String(), "~") } // HasConstraintInterface indicates whether any of the generic type constraints // are constraint interfaces that cannot be used in type assertions. func (f *Fake) HasConstraintInterface() bool { if f.Target == nil || f.Target.Type() == nil { return false } named, ok := f.Target.Type().(*types.Named) if !ok { return false } typeParams := named.TypeParams() if typeParams.Len() == 0 { return false } for i := 0; i < typeParams.Len(); i++ { param := typeParams.At(i) constraint := param.Constraint() // check if the constraint is a constraint interface if iface, ok := constraint.Underlying().(*types.Interface); ok { // check if this interface contains type constraints for j := 0; j < iface.NumEmbeddeds(); j++ { if _, ok := iface.EmbeddedType(j).(*types.Union); ok { return true } } // check for approximation constraints by examining the string representation // a bit of a hack, but the Go types API doesn't expose type constraints cleanly constraintStr := constraint.String() if strings.Contains(constraintStr, "~") { return true } } } return false } func unexport(s string) string { s = strings.TrimSpace(s) if s == "" { return "" } r, n := utf8.DecodeRuneInString(s) return string(unicode.ToLower(r)) + s[n:] } func isExported(s string) bool { r, _ := utf8.DecodeRuneInString(s) return unicode.IsUpper(r) } // Generate uses the Fake to generate an implementation, optionally running // goimports on the output. func (f *Fake) Generate(runImports bool) ([]byte, error) { var tmpl *template.Template if f.IsInterface() { log.Printf("Writing fake %s for interface %s to package %s\n", f.Name, f.TargetName, f.DestinationPackage) tmpl = template.Must(template.New("fake").Funcs(interfaceFuncs).Parse(interfaceTemplate)) } if f.IsFunction() { log.Printf("Writing fake %s for function %s to package %s\n", f.Name, f.TargetName, f.DestinationPackage) tmpl = template.Must(template.New("fake").Funcs(functionFuncs).Parse(functionTemplate)) } if f.Mode == Package { log.Printf("Writing fake %s for package %s to package %s\n", f.Name, f.TargetPackage, f.DestinationPackage) tmpl = template.Must(template.New("fake").Funcs(packageFuncs).Parse(packageTemplate)) } if tmpl == nil { return nil, errors.New("counterfeiter can only generate fakes for interfaces or specific functions") } b := &bytes.Buffer{} err := tmpl.Execute(b, f) if err != nil { return nil, err } if runImports { return imports.Process("counterfeiter_temp_process_file", b.Bytes(), nil) } return b.Bytes(), nil } counterfeiter-6.12.0/generator/file_reader.go000066400000000000000000000026011505763253600212470ustar00rootroot00000000000000package generator import ( "io" "os" "path/filepath" ) type FileReader interface { Get(cwd, path string) (content string, err error) } type Opener func(string) (io.ReadCloser, error) var ( defaultOpen Opener = func(p string) (io.ReadCloser, error) { return os.Open(p) } ) func (open Opener) readString(path string) (string, error) { if open == nil { open = defaultOpen } f, err := open(path) if err != nil { return "", err } defer f.Close() b, err := io.ReadAll(f) if err != nil { return "", err } return string(b), nil } type SimpleFileReader struct { Open Opener } var _ FileReader = &SimpleFileReader{} func (r *SimpleFileReader) Get(cwd, path string) (string, error) { if path == "" { return "", nil } p := normalisePath(cwd, path) return r.Open.readString(p) } type CachedFileReader struct { Open Opener cache map[string]string } var _ FileReader = &CachedFileReader{} func (r *CachedFileReader) Get(cwd, path string) (string, error) { if path == "" { return "", nil } p := normalisePath(cwd, path) if s, ok := r.cache[p]; ok { return s, nil } s, err := r.Open.readString(p) if err != nil { return "", err } if r.cache == nil { r.cache = map[string]string{} } r.cache[p] = s return s, nil } func normalisePath(cwd, path string) string { if !filepath.IsAbs(path) { path = filepath.Join(cwd, path) } return filepath.Clean(path) } counterfeiter-6.12.0/generator/file_reader_other_test.go000066400000000000000000000003101505763253600235020ustar00rootroot00000000000000//go:build !windows package generator_test const ( relFile = "file.ext" absFile = "/file.ext" workingDir = "/some/dir" relFileUp = "../file.ext" expectedFileUp = "/some/file.ext" ) counterfeiter-6.12.0/generator/file_reader_test.go000066400000000000000000000142371505763253600223160ustar00rootroot00000000000000package generator_test import ( "errors" "io" "reflect" "strings" "testing" "github.com/maxbrunsfeld/counterfeiter/v6/generator" ) func TestFileReader(t *testing.T) { t.Parallel() tests := map[string]struct { readerCreator func(generator.Opener) generator.FileReader open generator.Opener workingDir string path string expectedErrMsg string expectedContent string expectedCalls []string }{ // SimpleFileReader "[simple] when the filepath is empty, it's a noop": { readerCreator: simpleReaderCreator, }, "[simple] when open returns an error, the error bubbles up": { readerCreator: simpleReaderCreator, open: openReturningErr("some error"), path: relFile, expectedErrMsg: "some error", expectedCalls: []string{relFile, relFile}, }, "[simple] when open returns a reader, the readers content is read": { readerCreator: simpleReaderCreator, open: openReturningReader("some content 0"), path: relFile, expectedContent: "some content 0", expectedCalls: []string{relFile, relFile}, }, "[simple] when the working directory is set but the filepath is absolut, the absolute path is used": { readerCreator: simpleReaderCreator, open: openReturningReader("some content 1"), workingDir: workingDir, path: absFile, expectedContent: "some content 1", expectedCalls: []string{absFile, absFile}, }, "[simple] when the working directory and a relative filepath is set, the paths are combined & cleaned": { readerCreator: simpleReaderCreator, open: openReturningReader("some content 2"), workingDir: workingDir, path: relFileUp, expectedContent: "some content 2", expectedCalls: []string{expectedFileUp, expectedFileUp}, }, "[simple] when the reader's Read returns an error, the error bubbles up": { readerCreator: simpleReaderCreator, open: openReturningFailingReader("some read error"), path: relFile, expectedErrMsg: "some read error", expectedCalls: []string{relFile, relFile}, }, // CachedFileReader "[cached] when the filepath is empty, it's a noop": { readerCreator: cachedReaderCreator, }, "[cached] when open returns an error, the error bubbles up": { readerCreator: cachedReaderCreator, open: openReturningErr("some error"), path: relFile, expectedErrMsg: "some error", expectedCalls: []string{relFile, relFile}, // because on error, we don't cache }, "[cached] when open returns a reader, the readers content is read": { readerCreator: cachedReaderCreator, open: openReturningReader("some content 3"), path: relFile, expectedContent: "some content 3", expectedCalls: []string{relFile}, }, "[cached] when the working directory is set but the filepath is absolut, the absolute path is used": { readerCreator: cachedReaderCreator, open: openReturningReader("some content 4"), workingDir: workingDir, path: absFile, expectedContent: "some content 4", expectedCalls: []string{absFile}, }, "[cached] when the working directory and a relative filepath is set, the paths are combined & cleaned": { readerCreator: cachedReaderCreator, open: openReturningReader("some content 5"), workingDir: workingDir, path: relFileUp, expectedContent: "some content 5", expectedCalls: []string{expectedFileUp}, }, "[cached] when the reader's Read returns an error, the error bubbles up": { readerCreator: cachedReaderCreator, open: openReturningFailingReader("some read error"), path: relFile, expectedErrMsg: "some read error", expectedCalls: []string{relFile, relFile}, // because on error, we don't cache }, } for name, tc := range tests { tc := tc t.Run(name, func(t *testing.T) { t.Parallel() spy := &openSpy{Func: tc.open} reader := tc.readerCreator(spy.Open) readAndCheckContent := func() { content, err := reader.Get(tc.workingDir, tc.path) checkErr(t, err, tc.expectedErrMsg) if a, e := content, tc.expectedContent; e != a { t.Errorf("Expected content to be '%s', got '%s'", e, a) } } // let's run the tests twice, to check on caching readAndCheckContent() readAndCheckContent() if a, e := spy.Calls, tc.expectedCalls; !reflect.DeepEqual(e, a) { t.Errorf("Expected open call args to be %#v, got %#v", e, a) } }) } } func simpleReaderCreator(o generator.Opener) generator.FileReader { return &generator.SimpleFileReader{Open: o} } func cachedReaderCreator(o generator.Opener) generator.FileReader { return &generator.CachedFileReader{Open: o} } func openReturningErr(err string) generator.Opener { return func(_ string) (io.ReadCloser, error) { return nil, errors.New(err) } } func openReturningReader(content string) generator.Opener { return func(_ string) (io.ReadCloser, error) { return io.NopCloser(strings.NewReader(content)), nil } } func openReturningFailingReader(err string) generator.Opener { return func(_ string) (io.ReadCloser, error) { r := &erroringReader{ reader: io.NopCloser(strings.NewReader("some random file content")), err: errors.New(err), } return r, nil } } func checkErr(t *testing.T, err error, msg string) { t.Helper() if msg == "" { if err != nil { t.Errorf("Expected no error to occur, got %v", err) } return } if err == nil { t.Errorf("Expected error '%s', got no error", msg) return } if a, e := err.Error(), msg; a != e { t.Errorf("Expected error '%s', got: '%s'", e, a) } } type openSpy struct { Func generator.Opener Calls []string } func (o *openSpy) Open(p string) (io.ReadCloser, error) { o.Calls = append(o.Calls, p) return o.Func(p) } var _ generator.Opener = (&openSpy{}).Open type erroringReader struct { reader io.ReadCloser callCount int err error } func (r *erroringReader) Read(p []byte) (int, error) { r.callCount++ if r.callCount >= 2 { return 0, r.err } return r.reader.Read(p) } func (r *erroringReader) Close() error { return r.reader.Close() } var _ io.ReadCloser = &erroringReader{} counterfeiter-6.12.0/generator/file_reader_windows_test.go000066400000000000000000000003231505763253600240570ustar00rootroot00000000000000//go:build windows package generator_test const ( relFile = "file.ext" absFile = "c:\\file.ext" workingDir = "c:\\some\\dir" relFileUp = "..\\file.ext" expectedFileUp = "c:\\some\\file.ext" ) counterfeiter-6.12.0/generator/function_loader.go000066400000000000000000000006731505763253600221700ustar00rootroot00000000000000package generator import ( "errors" "go/types" ) func (f *Fake) loadMethodForFunction() error { t, ok := f.Target.Type().(*types.Named) if !ok { return errors.New("target is not a named type") } sig, ok := t.Underlying().(*types.Signature) if !ok { return errors.New("target does not have an underlying function signature") } f.addTypesForMethod(sig) f.Function = methodForSignature(sig, f.TargetName, f.Imports) return nil } counterfeiter-6.12.0/generator/function_template.go000066400000000000000000000106551505763253600225360ustar00rootroot00000000000000package generator import ( "strings" "text/template" ) var functionFuncs = template.FuncMap{ "ToLower": strings.ToLower, "UnExport": unexport, "Replace": strings.Replace, "IsExported": isExported, } const functionTemplate string = `{{.Header}}// Code generated by counterfeiter. DO NOT EDIT. package {{.DestinationPackage}} import ( {{- range $index, $import := .Imports.ByAlias}} {{$import}} {{- end}} ) type {{.Name}} struct { Stub func({{.Function.Params.AsArgs}}) {{.Function.Returns.AsReturnSignature}} mutex sync.RWMutex argsForCall []struct{ {{- range .Function.Params}} {{.Name}} {{if .IsVariadic}}{{Replace .Type "..." "[]" -1}}{{else}}{{.Type}}{{end}} {{- end}} } {{- if .Function.Returns.HasLength}} returns struct{ {{- range .Function.Returns}} {{UnExport .Name}} {{.Type}} {{- end}} } returnsOnCall map[int]struct{ {{- range .Function.Returns}} {{UnExport .Name}} {{.Type}} {{- end}} } {{- end}} invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *{{.Name}}) Spy({{.Function.Params.AsNamedArgsWithTypes}}) {{.Function.Returns.AsReturnSignature}} { {{- range .Function.Params.Slices}} var {{UnExport .Name}}Copy {{.Type}} if {{UnExport .Name}} != nil { {{UnExport .Name}}Copy = make({{.Type}}, len({{UnExport .Name}})) copy({{UnExport .Name}}Copy, {{UnExport .Name}}) } {{- end}} fake.mutex.Lock() {{if .Function.Returns.HasLength}}ret, specificReturn := fake.returnsOnCall[len(fake.argsForCall)] {{end}}fake.argsForCall = append(fake.argsForCall, struct{ {{- range .Function.Params}} {{.Name}} {{if .IsVariadic}}{{Replace .Type "..." "[]" -1}}{{else}}{{.Type}}{{end}} {{- end}} }{ {{- .Function.Params.AsNamedArgs -}} }) stub := fake.Stub {{- if .Function.Returns.HasLength}} returns := fake.returns {{- end}} fake.recordInvocation("{{.TargetName}}", []interface{}{ {{- if .Function.Params.HasLength}}{{.Function.Params.AsNamedArgs}}{{end -}} }) fake.mutex.Unlock() if stub != nil { {{if .Function.Returns.HasLength}}return stub({{.Function.Params.AsNamedArgsForInvocation}}){{else}}fake.Stub({{.Function.Params.AsNamedArgsForInvocation}}){{end}} } {{- if .Function.Returns.HasLength}} if specificReturn { return {{.Function.Returns.WithPrefix "ret."}} } return {{.Function.Returns.WithPrefix "returns."}} {{- end}} } func (fake *{{.Name}}) CallCount() int { fake.mutex.RLock() defer fake.mutex.RUnlock() return len(fake.argsForCall) } func (fake *{{.Name}}) Calls(stub func({{.Function.Params.AsArgs}}) {{.Function.Returns.AsReturnSignature}}) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = stub } {{if .Function.Params.HasLength -}} func (fake *{{.Name}}) ArgsForCall(i int) {{.Function.Params.AsReturnSignature}} { fake.mutex.RLock() defer fake.mutex.RUnlock() return {{.Function.Params.WithPrefix "fake.argsForCall[i]."}} } {{- end}} {{if .Function.Returns.HasLength -}} func (fake *{{.Name}}) Returns({{.Function.Returns.AsNamedArgsWithTypes}}) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil fake.returns = struct { {{- range .Function.Returns}} {{UnExport .Name}} {{.Type}} {{- end}} }{ {{- .Function.Returns.AsNamedArgs -}} } } func (fake *{{.Name}}) ReturnsOnCall(i int, {{.Function.Returns.AsNamedArgsWithTypes}}) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil if fake.returnsOnCall == nil { fake.returnsOnCall = make(map[int]struct { {{- range .Function.Returns}} {{UnExport .Name}} {{.Type}} {{- end}} }) } fake.returnsOnCall[i] = struct { {{- range .Function.Returns}} {{UnExport .Name}} {{.Type}} {{- end}} }{ {{- .Function.Returns.AsNamedArgs -}} } } {{- end}} func (fake *{{.Name}}) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.mutex.RLock() defer fake.mutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *{{.Name}}) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } {{if IsExported .TargetName -}} var _ {{.TargetAlias}}.{{.TargetName}} = new({{.Name}}).Spy {{- end}} ` counterfeiter-6.12.0/generator/generator_internals_test.go000066400000000000000000000274151505763253600241240ustar00rootroot00000000000000package generator import ( "io" "log" "runtime" "testing" . "github.com/onsi/gomega" "github.com/sclevine/spec" "github.com/sclevine/spec/report" "golang.org/x/tools/go/packages" ) func TestGenerator(t *testing.T) { log.SetOutput(io.Discard) // Comment this out to see verbose log output log.SetFlags(log.Llongfile) spec.Run(t, "Generator", testGenerator, spec.Report(report.Terminal{})) } func testGenerator(t *testing.T, when spec.G, it spec.S) { var ( f *Fake err error ) it.Before(func() { RegisterTestingT(t) }) when("constructing a fake with NewFake()", func() { when("the target is a nonexistent package", func() { it("errors", func() { c := &Cache{} f, err = NewFake(InterfaceOrFunction, "NonExistent", "nonexistentpackage", "FakeNonExistent", "nonexistentpackagefakes", "", "", c) Expect(err).To(HaveOccurred()) Expect(f).To(BeNil()) }) }) when("the target is a package with a nonexistent interface", func() { it("errors", func() { c := &Cache{} f, err = NewFake(InterfaceOrFunction, "NonExistent", "os", "FakeNonExistent", "osfakes", "", "", c) Expect(err).To(HaveOccurred()) Expect(f).To(BeNil()) }) }) when("the target is an interface that exists", func() { it("succeeds", func() { c := &Cache{} f, err = NewFake(InterfaceOrFunction, "FileInfo", "os", "FakeFileInfo", "osfakes", "", "", c) Expect(err).NotTo(HaveOccurred()) Expect(f).NotTo(BeNil()) Expect(f.TargetAlias).To(Equal("os")) Expect(f.TargetName).To(Equal("FileInfo")) Expect(f.TargetPackage).To(Equal("os")) Expect(f.Name).To(Equal("FakeFileInfo")) Expect(f.Mode).To(Equal(InterfaceOrFunction)) Expect(f.DestinationPackage).To(Equal("osfakes")) switch runtime.Version()[0:6] { case "go1.15", "go1.14": Expect(f.Imports).To(BeEquivalentTo(Imports{ ByAlias: map[string]Import{ "os": {Alias: "os", PkgPath: "os"}, "sync": {Alias: "sync", PkgPath: "sync"}, "time": {Alias: "time", PkgPath: "time"}, }, ByPkgPath: map[string]Import{ "os": {Alias: "os", PkgPath: "os"}, "sync": {Alias: "sync", PkgPath: "sync"}, "time": {Alias: "time", PkgPath: "time"}, }, })) default: Expect(f.Imports).To(BeEquivalentTo(Imports{ ByAlias: map[string]Import{ "os": {Alias: "os", PkgPath: "os"}, "sync": {Alias: "sync", PkgPath: "sync"}, "time": {Alias: "time", PkgPath: "time"}, "fs": {Alias: "fs", PkgPath: "io/fs"}, }, ByPkgPath: map[string]Import{ "os": {Alias: "os", PkgPath: "os"}, "sync": {Alias: "sync", PkgPath: "sync"}, "time": {Alias: "time", PkgPath: "time"}, "io/fs": {Alias: "fs", PkgPath: "io/fs"}, }, })) } Expect(f.Function).To(BeZero()) Expect(f.Packages).NotTo(BeNil()) Expect(f.Package).NotTo(BeNil()) Expect(f.Methods).To(HaveLen(6)) }) }) when("the target is a function that exists", func() { it("succeeds", func() { c := &Cache{} f, err = NewFake(InterfaceOrFunction, "HandlerFunc", "net/http", "FakeHandlerFunc", "httpfakes", "", "", c) Expect(err).NotTo(HaveOccurred()) Expect(f).NotTo(BeNil()) Expect(f.TargetAlias).To(Equal("http")) Expect(f.TargetName).To(Equal("HandlerFunc")) Expect(f.TargetPackage).To(Equal("net/http")) Expect(f.Name).To(Equal("FakeHandlerFunc")) Expect(f.Mode).To(Equal(InterfaceOrFunction)) Expect(f.DestinationPackage).To(Equal("httpfakes")) Expect(f.Imports).To(BeEquivalentTo(Imports{ ByAlias: map[string]Import{ "http": {Alias: "http", PkgPath: "net/http"}, "sync": {Alias: "sync", PkgPath: "sync"}, }, ByPkgPath: map[string]Import{ "net/http": {Alias: "http", PkgPath: "net/http"}, "sync": {Alias: "sync", PkgPath: "sync"}, }, })) Expect(f.Function).NotTo(BeZero()) Expect(f.Packages).NotTo(BeNil()) Expect(f.Package).NotTo(BeNil()) Expect(f.Methods).To(HaveLen(0)) Expect(f.Function.Name).To(Equal("HandlerFunc")) Expect(f.Function.Params).To(HaveLen(2)) Expect(f.Function.Returns).To(BeEmpty()) }) }) }) when("manually constructing a fake", func() { it.Before(func() { f = &Fake{Imports: newImports()} }) when("duplicate import package names are added", func() { it.Before(func() { f.Imports.Add("sync", "sync") f.Imports.Add("sync", "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/sync") f.Imports.Add("sync", "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/othersync") }) it("all packages have unique aliases", func() { Expect(f.Imports).To(BeEquivalentTo(Imports{ ByAlias: map[string]Import{ "sync": {Alias: "sync", PkgPath: "sync"}, "synca": {Alias: "synca", PkgPath: "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/sync"}, "syncb": {Alias: "syncb", PkgPath: "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/othersync"}, }, ByPkgPath: map[string]Import{ "sync": {Alias: "sync", PkgPath: "sync"}, "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/sync": {Alias: "synca", PkgPath: "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/sync"}, "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/othersync": {Alias: "syncb", PkgPath: "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/othersync"}, }, })) }) }) when("inspecting the target", func() { when("the target is not set", func() { it("IsInterface() is false", func() { Expect(f.IsInterface()).To(BeFalse()) }) it("IsFunction() is false", func() { Expect(f.IsFunction()).To(BeFalse()) }) }) when("the target is an interface", func() { it.Before(func() { f.Mode = InterfaceOrFunction f.TargetPackage = "os" f.TargetName = "FileInfo" c := &Cache{} err := f.loadPackages(c, "") Expect(err).NotTo(HaveOccurred()) err = f.findPackage() Expect(err).NotTo(HaveOccurred()) }) it("IsInterface() is true", func() { Expect(f.IsInterface()).To(BeTrue()) }) it("IsFunction() is false", func() { Expect(f.IsFunction()).To(BeFalse()) }) }) when("the target is a function", func() { it.Before(func() { f.Mode = InterfaceOrFunction f.TargetPackage = "net/http" f.TargetName = "HandlerFunc" c := &Cache{} err := f.loadPackages(c, "") Expect(err).NotTo(HaveOccurred()) err = f.findPackage() Expect(err).NotTo(HaveOccurred()) }) it("IsInterface() is false", func() { Expect(f.IsInterface()).To(BeFalse()) }) it("IsFunction() is true", func() { Expect(f.IsFunction()).To(BeTrue()) }) }) when("the target is a struct", func() { it.Before(func() { f.Mode = InterfaceOrFunction f.TargetPackage = "net/http" f.TargetName = "Client" c := &Cache{} err := f.loadPackages(c, "") Expect(err).NotTo(HaveOccurred()) err = f.findPackage() Expect(err).To(HaveOccurred()) }) it("is not a function", func() { Expect(f.IsFunction()).To(BeFalse()) }) it("is not an interface", func() { Expect(f.IsInterface()).To(BeFalse()) }) }) }) when("in interface mode", func() { it.Before(func() { f.Mode = InterfaceOrFunction }) when("targeting the os.FileInfo interface", func() { it.Before(func() { f.TargetPackage = "os" f.TargetName = "FileInfo" c := &Cache{} err := f.loadPackages(c, "") Expect(err).NotTo(HaveOccurred()) }) }) }) when("in package mode", func() { it.Before(func() { f.Mode = Package }) when("targeting a nonexistent package", func() { it("returns an error", func() { f.TargetPackage = "counterfeiternonexistentpackage" c := &Cache{} err := f.loadPackages(c, "") Expect(err).To(HaveOccurred()) }) }) when("targeting the os package", func() { it.Before(func() { f.TargetPackage = "os" c := &Cache{} err := f.loadPackages(c, "") Expect(err).NotTo(HaveOccurred()) }) it("can load packages", func() { Expect(len(f.Packages)).To(BeNumerically(">=", 1)) Expect(f.Packages[0].Name).To(Equal("os")) }) it("can find the package with the os package path", func() { err := f.findPackage() Expect(err).NotTo(HaveOccurred()) Expect(f.Package).NotTo(BeNil()) Expect(f.Package).To(Equal(f.Packages[0])) }) it("skips invalid packages", func() { var p []*packages.Package empty := &packages.Package{} p = append(p, empty) p = append(p, f.Packages...) f.Packages = p err := f.findPackage() Expect(err).NotTo(HaveOccurred()) Expect(f.Package).NotTo(BeNil()) Expect(f.Package).To(Equal(f.Packages[1])) }) it("can identify the method set for the package", func() { err := f.findPackage() Expect(err).NotTo(HaveOccurred()) methods := packageMethodSet(f.Package) Expect(len(methods)).To(BeNumerically(">=", 51)) // yes, this is crazy because go 1.11 added a function }) it("can load the methods", func() { err := f.findPackage() Expect(err).NotTo(HaveOccurred()) f.loadMethods() Expect(len(f.Methods)).To(BeNumerically(">=", 51)) // yes, this is crazy because go 1.11 added a function switch runtime.Version()[0:6] { case "go1.15", "go1.14": Expect(len(f.Imports.ByAlias)).To(Equal(2)) default: Expect(len(f.Imports.ByAlias)).To(Equal(3)) } }) }) }) when("working with imports", func() { when("there are no imports", func() { it("returns an empty alias map", func() { Expect(f.Imports.ByAlias).To(BeEmpty()) }) it("turns a vendor path into the correct import", func() { i := f.Imports.Add("apackage", "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/vendored/vendor/apackage") Expect(i.Alias).To(Equal("apackage")) Expect(i.PkgPath).To(Equal("apackage")) i = f.Imports.Add("anotherpackage", "vendor/anotherpackage") Expect(i.Alias).To(Equal("anotherpackage")) Expect(i.PkgPath).To(Equal("anotherpackage")) }) }) when("there is a single import", func() { it.Before(func() { f.Imports.Add("os", "os") }) it("is present in the map", func() { Expect(f.Imports).To(BeEquivalentTo(Imports{ ByAlias: map[string]Import{ "os": {Alias: "os", PkgPath: "os"}, }, ByPkgPath: map[string]Import{ "os": {Alias: "os", PkgPath: "os"}, }, })) }) it("returns the existing imports if there is a path match", func() { i := f.Imports.Add("aliasedos", "os") Expect(i.Alias).To(Equal("os")) Expect(i.PkgPath).To(Equal("os")) Expect(f.Imports).To(BeEquivalentTo(Imports{ ByAlias: map[string]Import{ "os": {Alias: "os", PkgPath: "os"}, }, ByPkgPath: map[string]Import{ "os": {Alias: "os", PkgPath: "os"}, }, })) }) }) }) }) when("helper functions", func() { when("unexport()", func() { it("is a no-op on an empty string", func() { Expect(unexport("")).To(Equal("")) Expect(unexport(" ")).To(Equal("")) }) it("makes the first letter lowercase", func() { Expect(unexport("TheExportedThing")).To(Equal("theExportedThing")) }) it("leaves unexported things unchanged", func() { Expect(unexport("theUnexportedThing")).To(Equal("theUnexportedThing")) }) }) when("isExported()", func() { it("returns false for an empty string", func() { Expect(isExported("")).To(BeFalse()) Expect(isExported(" ")).To(BeFalse()) }) it("returns true when the first rune is upper case", func() { Expect(isExported("Identifier")).To(BeTrue()) Expect(isExported("Æąpsilon")).To(BeTrue()) }) it("returns false when the first rune not upper case", func() { Expect(isExported("identifier")).To(BeFalse()) Expect(isExported("Ɗpsilon")).To(BeFalse()) }) }) }) } counterfeiter-6.12.0/generator/import.go000066400000000000000000000034321505763253600203230ustar00rootroot00000000000000package generator import ( "fmt" "go/types" "path" "strings" "golang.org/x/tools/imports" ) // Imports indexes imports by package path and alias so that all imports have a // unique alias, and no package is included twice. type Imports struct { ByAlias map[string]Import ByPkgPath map[string]Import } func newImports() Imports { return Imports{ ByAlias: make(map[string]Import), ByPkgPath: make(map[string]Import), } } // Import is a package import with the associated alias for that package. type Import struct { Alias string PkgPath string } // String returns a string that may be used as an import line in a go source // file. Imports with aliases that match the package basename are printed without // an alias. func (i Import) String() string { if path.Base(i.PkgPath) == i.Alias { return `"` + i.PkgPath + `"` } return fmt.Sprintf(`%s "%s"`, i.Alias, i.PkgPath) } // Add creates an import with the given alias and path, and adds it to // Fake.Imports. func (i *Imports) Add(alias string, path string) Import { path = imports.VendorlessPath(strings.TrimSpace(path)) alias = strings.TrimSpace(alias) imp, exists := i.ByPkgPath[path] if exists { return imp } _, exists = i.ByAlias[alias] if exists { alias = uniqueAliasForImport(alias, i.ByAlias) } result := Import{Alias: alias, PkgPath: path} i.ByPkgPath[path] = result i.ByAlias[alias] = result return result } func uniqueAliasForImport(alias string, imports map[string]Import) string { for i := 0; ; i++ { newAlias := alias + string('a'+byte(i)) if _, exists := imports[newAlias]; !exists { return newAlias } } } // AliasForPackage returns a package alias for the package. func (i *Imports) AliasForPackage(p *types.Package) string { return i.ByPkgPath[imports.VendorlessPath(p.Path())].Alias } counterfeiter-6.12.0/generator/import_test.go000066400000000000000000000014351505763253600213630ustar00rootroot00000000000000package generator import ( "testing" "github.com/onsi/gomega" ) func TestImport_String(t *testing.T) { var testcases = []struct { name string imp Import expected string }{ { name: "stdlib package", imp: Import{Alias: "os", PkgPath: "os"}, expected: `"os"`, }, { name: "alias matches base name", imp: Import{Alias: "foo", PkgPath: "example.com/goo/foo"}, expected: `"example.com/goo/foo"`, }, { name: "custom package alias", imp: Import{Alias: "thinga", PkgPath: "example.com/go-thing"}, expected: `thinga "example.com/go-thing"`, }, } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { o := gomega.NewGomegaWithT(t) o.Expect(tc.imp.String()).To(gomega.Equal(tc.expected)) }) } } counterfeiter-6.12.0/generator/interface_loader.go000066400000000000000000000045161505763253600223030ustar00rootroot00000000000000package generator import ( "fmt" "go/types" "strings" "golang.org/x/tools/go/types/typeutil" ) func (f *Fake) addTypesForMethod(sig *types.Signature) { for i := 0; i < sig.Results().Len(); i++ { ret := sig.Results().At(i) f.addImportsFor(ret.Type()) } for i := 0; i < sig.Params().Len(); i++ { param := sig.Params().At(i) f.addImportsFor(param.Type()) } } func methodForSignature(sig *types.Signature, methodName string, imports Imports) Method { params := []Param{} for i := 0; i < sig.Params().Len(); i++ { param := sig.Params().At(i) isVariadic := i == sig.Params().Len()-1 && sig.Variadic() typ := types.TypeString(param.Type(), imports.AliasForPackage) if isVariadic { typ = "..." + typ[2:] // Change []string to ...string } p := Param{ Name: fmt.Sprintf("arg%v", i+1), Type: typ, IsVariadic: isVariadic, IsSlice: strings.HasPrefix(typ, "[]"), } params = append(params, p) } returns := []Return{} for i := 0; i < sig.Results().Len(); i++ { ret := sig.Results().At(i) r := Return{ Name: fmt.Sprintf("result%v", i+1), Type: types.TypeString(ret.Type(), imports.AliasForPackage), } returns = append(returns, r) } return Method{ Name: methodName, Returns: returns, Params: params, } } // interfaceMethodSet identifies the methods that are exported for a given // interface. func interfaceMethodSet(t types.Type) []*rawMethod { if t == nil { return nil } var result []*rawMethod methods := typeutil.IntuitiveMethodSet(t, nil) for i := range methods { if methods[i].Obj() == nil || methods[i].Type() == nil { continue } fun, ok := methods[i].Obj().(*types.Func) if !ok { continue } sig, ok := methods[i].Type().(*types.Signature) if !ok { continue } result = append(result, &rawMethod{ Func: fun, Signature: sig, }) } return result } func (f *Fake) loadMethods() { var methods []*rawMethod if f.Mode == Package { methods = packageMethodSet(f.Package) } else { if !f.IsInterface() || f.Target == nil || f.Target.Type() == nil { return } methods = interfaceMethodSet(f.Target.Type()) } for i := range methods { f.addTypesForMethod(methods[i].Signature) } for i := range methods { method := methodForSignature(methods[i].Signature, methods[i].Func.Name(), f.Imports) f.Methods = append(f.Methods, method) } } counterfeiter-6.12.0/generator/interface_template.go000066400000000000000000000127461505763253600226540ustar00rootroot00000000000000package generator import ( "strings" "text/template" "golang.org/x/text/cases" "golang.org/x/text/language" ) var title = cases.Title(language.Und, cases.NoLower) var hasConstraintInterface = func(f *Fake) bool { return f.HasConstraintInterface() } var interfaceFuncs = template.FuncMap{ "ToLower": strings.ToLower, "UnExport": unexport, "Replace": strings.Replace, "IsExported": isExported, "Title": title.String, "HasConstraintInterface": hasConstraintInterface, } const interfaceTemplate string = `{{.Header}}// Code generated by counterfeiter. DO NOT EDIT. package {{.DestinationPackage}} import ( {{- range $index, $import := .Imports.ByAlias}} {{$import}} {{- end}} ) type {{.Name}}{{.GenericTypeParametersAndConstraints}} struct { {{- range .Methods}} {{.Name}}Stub func({{.Params.AsArgs}}) {{.Returns.AsReturnSignature}} {{UnExport .Name}}Mutex sync.RWMutex {{UnExport .Name}}ArgsForCall []struct{ {{- range .Params}} {{.Name}} {{if .IsVariadic}}{{Replace .Type "..." "[]" -1}}{{else}}{{.Type}}{{end}} {{- end}} } {{- if .Returns.HasLength}} {{UnExport .Name}}Returns struct{ {{- range .Returns}} {{UnExport .Name}} {{.Type}} {{- end}} } {{UnExport .Name}}ReturnsOnCall map[int]struct{ {{- range .Returns}} {{UnExport .Name}} {{.Type}} {{- end}} } {{- end}} {{- end}} invocations map[string][][]interface{} invocationsMutex sync.RWMutex } {{range .Methods -}} func (fake *{{$.Name}}{{$.GenericTypeParameters}}) {{.Name}}({{.Params.AsNamedArgsWithTypes}}) {{.Returns.AsReturnSignature}} { {{- range .Params.Slices}} var {{UnExport .Name}}Copy {{.Type}} if {{UnExport .Name}} != nil { {{UnExport .Name}}Copy = make({{.Type}}, len({{UnExport .Name}})) copy({{UnExport .Name}}Copy, {{UnExport .Name}}) } {{- end}} fake.{{UnExport .Name}}Mutex.Lock() {{- if .Returns.HasLength}} ret, specificReturn := fake.{{UnExport .Name}}ReturnsOnCall[len(fake.{{UnExport .Name}}ArgsForCall)] {{- end}} fake.{{UnExport .Name}}ArgsForCall = append(fake.{{UnExport .Name}}ArgsForCall, struct{ {{- range .Params}} {{.Name}} {{if .IsVariadic}}{{Replace .Type "..." "[]" -1}}{{else}}{{.Type}}{{end}} {{- end}} }{ {{- .Params.AsNamedArgs -}} }) stub := fake.{{.Name}}Stub {{- if .Returns.HasLength}} fakeReturns := fake.{{UnExport .Name}}Returns {{- end}} fake.recordInvocation("{{.Name}}", []interface{}{ {{- if .Params.HasLength}}{{.Params.AsNamedArgs}}{{end -}} }) fake.{{UnExport .Name}}Mutex.Unlock() if stub != nil { {{- if .Returns.HasLength}} return stub({{.Params.AsNamedArgsForInvocation}}){{else}}fake.{{.Name}}Stub({{.Params.AsNamedArgsForInvocation}}) {{- end}} } {{- if .Returns.HasLength}} if specificReturn { return {{.Returns.WithPrefix "ret."}} } return {{.Returns.WithPrefix "fakeReturns."}} {{- end}} } func (fake *{{$.Name}}{{$.GenericTypeParameters}}) {{Title .Name}}CallCount() int { fake.{{UnExport .Name}}Mutex.RLock() defer fake.{{UnExport .Name}}Mutex.RUnlock() return len(fake.{{UnExport .Name}}ArgsForCall) } func (fake *{{$.Name}}{{$.GenericTypeParameters}}) {{Title .Name}}Calls(stub func({{.Params.AsArgs}}) {{.Returns.AsReturnSignature}}) { fake.{{UnExport .Name}}Mutex.Lock() defer fake.{{UnExport .Name}}Mutex.Unlock() fake.{{.Name}}Stub = stub } {{if .Params.HasLength -}} func (fake *{{$.Name}}{{$.GenericTypeParameters}}) {{Title .Name}}ArgsForCall(i int) {{.Params.AsReturnSignature}} { fake.{{UnExport .Name}}Mutex.RLock() defer fake.{{UnExport .Name}}Mutex.RUnlock() argsForCall := fake.{{UnExport .Name}}ArgsForCall[i] return {{.Params.WithPrefix "argsForCall."}} } {{- end}} {{if .Returns.HasLength -}} func (fake *{{$.Name}}{{$.GenericTypeParameters}}) {{Title .Name}}Returns({{.Returns.AsNamedArgsWithTypes}}) { fake.{{UnExport .Name}}Mutex.Lock() defer fake.{{UnExport .Name}}Mutex.Unlock() fake.{{.Name}}Stub = nil fake.{{UnExport .Name}}Returns = struct { {{- range .Returns}} {{UnExport .Name}} {{.Type}} {{- end}} }{ {{- .Returns.AsNamedArgs -}} } } func (fake *{{$.Name}}{{$.GenericTypeParameters}}) {{Title .Name}}ReturnsOnCall(i int, {{.Returns.AsNamedArgsWithTypes}}) { fake.{{UnExport .Name}}Mutex.Lock() defer fake.{{UnExport .Name}}Mutex.Unlock() fake.{{.Name}}Stub = nil if fake.{{UnExport .Name}}ReturnsOnCall == nil { fake.{{UnExport .Name}}ReturnsOnCall = make(map[int]struct { {{- range .Returns}} {{UnExport .Name}} {{.Type}} {{- end}} }) } fake.{{UnExport .Name}}ReturnsOnCall[i] = struct { {{- range .Returns}} {{UnExport .Name}} {{.Type}} {{- end}} }{ {{- .Returns.AsNamedArgs -}} } } {{end -}} {{end}} func (fake *{{.Name}}{{$.GenericTypeParameters}}) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *{{.Name}}{{$.GenericTypeParameters}}) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } {{if IsExported .TargetName -}} {{if not (HasConstraintInterface .) -}} var _ {{.TargetAlias}}.{{.TargetName}}{{.GenericTypeConstraints}} = new({{.Name}}{{.GenericTypeConstraints}}) {{- end}} {{- end}} ` counterfeiter-6.12.0/generator/loader.go000066400000000000000000000134111505763253600202550ustar00rootroot00000000000000package generator import ( "fmt" "go/build" "go/types" "log" "path/filepath" "reflect" "strings" "golang.org/x/tools/go/packages" "golang.org/x/tools/imports" ) func (f *Fake) loadPackages(c Cacher, workingDir string) error { log.Println("loading packages...") p, ok := c.Load(f.TargetPackage) if ok { f.Packages = p log.Printf("loaded %v packages from cache\n", len(f.Packages)) return nil } importPath := f.TargetPackage if !filepath.IsAbs(importPath) { ctx := getBuildContext(workingDir) bp, err := ctx.Import(f.TargetPackage, workingDir, build.FindOnly) if err != nil { return err } importPath = bp.ImportPath } p, err := packages.Load(&packages.Config{ Mode: packages.NeedName | packages.NeedFiles | packages.NeedImports | packages.NeedDeps | packages.NeedTypes | packages.NeedTypesInfo, Dir: workingDir, Tests: true, }, importPath) if err != nil { return err } for i := range p { if len(p[i].Errors) > 0 { if i == 0 { err = p[i].Errors[0] } for j := range p[i].Errors { log.Printf("error loading packages: %v", strings.TrimPrefix(fmt.Sprintf("%v", p[i].Errors[j]), "-: ")) } } } if err != nil { return err } f.Packages = p c.Store(f.TargetPackage, p) log.Printf("loaded %v packages\n", len(f.Packages)) return nil } func (f *Fake) getGenericTypeData(typeName *types.TypeName) (paramNames []string, constraintNames []string, paramAndConstraintNames []string, found bool) { if named, ok := typeName.Type().(*types.Named); ok { if _, ok := named.Underlying().(*types.Interface); ok { typeParams := named.TypeParams() if typeParams.Len() > 0 { for i := 0; i < typeParams.Len(); i++ { param := typeParams.At(i) paramName := param.Obj().Name() constraint := param.Constraint() constraintSections := strings.Split(constraint.String(), "/") constraintName := constraintSections[len(constraintSections)-1] paramNames = append(paramNames, paramName) constraintNames = append(constraintNames, constraintName) paramAndConstraintNames = append(paramAndConstraintNames, fmt.Sprintf("%s %s", paramName, constraintName)) found = true } } } } return } func (f *Fake) findPackage() error { var target *types.TypeName var pkg *packages.Package genericTypeParametersAndConstraints := []string{} genericTypeConstraints := []string{} genericTypeParameters := []string{} for i := range f.Packages { if f.Packages[i].Types == nil || f.Packages[i].Types.Scope() == nil { continue } pkg = f.Packages[i] if f.Mode == Package { break } raw := pkg.Types.Scope().Lookup(f.TargetName) if raw != nil { if typeName, ok := raw.(*types.TypeName); ok { if paramNames, constraintNames, paramAndConstraintNames, found := f.getGenericTypeData(typeName); found { genericTypeParameters = append(genericTypeParameters, paramNames...) genericTypeConstraints = append(genericTypeConstraints, constraintNames...) genericTypeParametersAndConstraints = append( genericTypeParametersAndConstraints, paramAndConstraintNames..., ) } target = typeName break } } pkg = nil } if pkg == nil { switch f.Mode { case Package: return fmt.Errorf("cannot find package with name: %s", f.TargetPackage) case InterfaceOrFunction: return fmt.Errorf("cannot find package with target: %s", f.TargetName) } } f.Target = target f.Package = pkg f.TargetPackage = imports.VendorlessPath(pkg.PkgPath) if len(genericTypeParameters) > 0 { f.GenericTypeParametersAndConstraints = fmt.Sprintf("[%s]", strings.Join(genericTypeParametersAndConstraints, ", ")) f.GenericTypeParameters = fmt.Sprintf("[%s]", strings.Join(genericTypeParameters, ", ")) f.GenericTypeConstraints = fmt.Sprintf("[%s]", strings.Join(genericTypeConstraints, ", ")) } t := f.Imports.Add(pkg.Name, f.TargetPackage) f.TargetAlias = t.Alias if f.Mode != Package { f.TargetName = target.Name() } if f.Mode == InterfaceOrFunction { if !f.IsInterface() && !f.IsFunction() { return fmt.Errorf("cannot generate a fake for %s because it is not an interface or function", f.TargetName) } if f.IsConstraintInterface() { return fmt.Errorf("cannot generate a fake for %s because it is a constraint interface (contains type constraints like ~string) which cannot be implemented by concrete types", f.TargetName) } } if f.IsInterface() { log.Printf("Found interface with name: [%s]\n", f.TargetName) } if f.IsFunction() { log.Printf("Found function with name: [%s]\n", f.TargetName) } if f.Mode == Package { log.Printf("Found package with name: [%s]\n", f.TargetPackage) } return nil } // addImportsFor inspects the given type and adds imports to the fake if importable // types are found. func (f *Fake) addImportsFor(typ types.Type) { if typ == nil { return } switch t := typ.(type) { case *types.Basic: return case *types.Pointer: f.addImportsFor(t.Elem()) case *types.Map: f.addImportsFor(t.Key()) f.addImportsFor(t.Elem()) case *types.Chan: f.addImportsFor(t.Elem()) case *types.Alias: f.addImportsForNamedType(t) case *types.Named: f.addImportsForNamedType(t) case *types.Slice: f.addImportsFor(t.Elem()) case *types.Array: f.addImportsFor(t.Elem()) case *types.Interface: return case *types.Signature: f.addTypesForMethod(t) case *types.Struct: for i := 0; i < t.NumFields(); i++ { f.addImportsFor(t.Field(i).Type()) } default: log.Printf("!!! WARNING: Missing case for type %s\n", reflect.TypeOf(typ).String()) } } func (f *Fake) addImportsForNamedType(t interface { Obj() *types.TypeName TypeArgs() *types.TypeList }) { if t.Obj() != nil && t.Obj().Pkg() != nil { typeArgs := t.TypeArgs() for i := 0; i < typeArgs.Len(); i++ { f.addImportsFor(typeArgs.At(i)) } f.Imports.Add(t.Obj().Pkg().Name(), t.Obj().Pkg().Path()) } } counterfeiter-6.12.0/generator/package_loader.go000066400000000000000000000014241505763253600217310ustar00rootroot00000000000000package generator import ( "go/types" "golang.org/x/tools/go/packages" ) type rawMethod struct { Func *types.Func Signature *types.Signature } // packageMethodSet identifies the functions that are exported from a given // package. func packageMethodSet(p *packages.Package) []*rawMethod { if p == nil || p.Types == nil || p.Types.Scope() == nil { return nil } var result []*rawMethod scope := p.Types.Scope() for _, name := range scope.Names() { obj := scope.Lookup(name) if !obj.Exported() { continue // skip unexported names } fun, ok := obj.(*types.Func) if !ok { continue } sig, ok := obj.Type().(*types.Signature) if !ok { continue } result = append(result, &rawMethod{ Func: fun, Signature: sig, }) } return result } counterfeiter-6.12.0/generator/package_template.go000066400000000000000000000023361505763253600223010ustar00rootroot00000000000000package generator import ( "strings" "text/template" ) var packageFuncs = template.FuncMap{ "ToLower": strings.ToLower, "UnExport": unexport, "Replace": strings.Replace, "Generate": func(suffix string) string { return suffix + ":generate" }, // yes, this seems insane but ensures that we can use `go generate ./...` from the main package } const packageTemplate string = `{{.Header}}// Code generated by counterfeiter. DO NOT EDIT. package {{.DestinationPackage}} import ( {{- range $index, $import := .Imports.ByAlias}} {{$import}} {{- end}} ) //{{Generate "go"}} go run github.com/maxbrunsfeld/counterfeiter/v6 -generate //{{Generate "counterfeiter"}} . {{.Name}} // {{.Name}} is a generated interface representing the exported functions // in the {{.TargetPackage}} package. type {{.Name}} interface { {{- range .Methods}} {{.Name}}({{.Params.AsNamedArgsWithTypes}}) {{.Returns.AsReturnSignature}} {{- end}} } type {{.Name}}Shim struct {} {{- range .Methods}} func (p *{{$.Name}}Shim) {{.Name}}({{.Params.AsNamedArgsWithTypes}}) {{.Returns.AsReturnSignature}} { {{if .Returns.HasLength}}return {{end}}{{$.TargetAlias}}.{{.Name}}({{.Params.AsNamedArgsForInvocation}}) } {{end}} var _ {{.Name}} = new({{.Name}}Shim) ` counterfeiter-6.12.0/generator/param.go000066400000000000000000000056261505763253600201200ustar00rootroot00000000000000package generator import "strings" // Params is a slice of Param. type Params []Param // Param is an argument to a function. type Param struct { Name string Type string IsVariadic bool IsSlice bool } // Slices returns those params that are a slice. func (p Params) Slices() Params { var result Params for i := range p { if p[i].IsSlice { result = append(result, p[i]) } } return result } // HasLength returns true if there are params. It returns false if there are no // params. func (p Params) HasLength() bool { return len(p) > 0 } // WithPrefix builds a string representing a functions parameters, and adds a // prefix to each. func (p Params) WithPrefix(prefix string) string { if len(p) == 0 { return "" } params := []string{} for i := range p { if prefix == "" { params = append(params, unexport(p[i].Name)) } else { params = append(params, prefix+unexport(p[i].Name)) } } return strings.Join(params, ", ") } // AsArgs builds a string that represents the parameters to a function as // arguments to a function invocation. func (p Params) AsArgs() string { if len(p) == 0 { return "" } params := []string{} for i := range p { params = append(params, p[i].Type) } return strings.Join(params, ", ") } // AsNamedArgsWithTypes builds a string that represents parameters as named // arguments to a function, with associated types. func (p Params) AsNamedArgsWithTypes() string { if len(p) == 0 { return "" } params := []string{} for i := range p { params = append(params, unexport(p[i].Name)+" "+p[i].Type) } return strings.Join(params, ", ") } // AsNamedArgs builds a string that represents parameters as named arguments. func (p Params) AsNamedArgs() string { if len(p) == 0 { return "" } params := []string{} for i := range p { if p[i].IsSlice { params = append(params, unexport(p[i].Name)+"Copy") } else { params = append(params, unexport(p[i].Name)) } } return strings.Join(params, ", ") } // AsNamedArgsForInvocation builds a string that represents a function's // arguments as required for invocation of the function. func (p Params) AsNamedArgsForInvocation() string { if len(p) == 0 { return "" } params := []string{} for i := range p { if p[i].IsVariadic { params = append(params, unexport(p[i].Name)+"...") } else { params = append(params, unexport(p[i].Name)) } } return strings.Join(params, ", ") } // AsReturnSignature builds a string representing signature for the params of // a function. func (p Params) AsReturnSignature() string { if len(p) == 0 { return "" } if len(p) == 1 { if p[0].IsVariadic { return strings.Replace(p[0].Type, "...", "[]", -1) } return p[0].Type } result := "(" for i := range p { t := p[i].Type if p[i].IsVariadic { t = strings.Replace(t, "...", "[]", -1) } result = result + t if i < len(p) { result = result + ", " } } result = result + ")" return result } counterfeiter-6.12.0/generator/return.go000066400000000000000000000036101505763253600203260ustar00rootroot00000000000000package generator import ( "strings" ) // Returns is a slice of Return. type Returns []Return // Return is the result of a method's invocation. type Return struct { Name string Type string } // HasLength is true if there are returns, else false. func (r Returns) HasLength() bool { return len(r) > 0 } // WithPrefix builds a string representing the parameters returned from a // function, and adds a prefix to each. func (r Returns) WithPrefix(p string) string { if len(r) == 0 { return "" } rets := []string{} for i := range r { if p == "" { rets = append(rets, unexport(r[i].Name)) } else { rets = append(rets, p+unexport(r[i].Name)) } } return strings.Join(rets, ", ") } // AsArgs builds a string representing the arguments passed to a function. func (r Returns) AsArgs() string { if len(r) == 0 { return "" } rets := []string{} for i := range r { rets = append(rets, r[i].Type) } return strings.Join(rets, ", ") } // AsNamedArgsWithTypes builds a string representing a function's named // arguments, with associated types. func (r Returns) AsNamedArgsWithTypes() string { if len(r) == 0 { return "" } rets := []string{} for i := range r { rets = append(rets, unexport(r[i].Name)+" "+r[i].Type) } return strings.Join(rets, ", ") } // AsNamedArgs builds a string representing a function's named arguments. func (r Returns) AsNamedArgs() string { if len(r) == 0 { return "" } rets := []string{} for i := range r { rets = append(rets, unexport(r[i].Name)) } return strings.Join(rets, ", ") } // AsReturnSignature builds a string representing signature for the returns of // a function. func (r Returns) AsReturnSignature() string { if len(r) == 0 { return "" } if len(r) == 1 { return r[0].Type } result := "(" for i := range r { result = result + r[i].Type if i < len(r) { result = result + ", " } } result = result + ")" return result } counterfeiter-6.12.0/go.mod000066400000000000000000000007521505763253600156040ustar00rootroot00000000000000module github.com/maxbrunsfeld/counterfeiter/v6 require ( github.com/onsi/gomega v1.38.2 github.com/sclevine/spec v1.4.0 golang.org/x/text v0.29.0 golang.org/x/tools v0.36.0 ) require ( github.com/google/go-cmp v0.7.0 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/mod v0.27.0 // indirect golang.org/x/net v0.43.0 // indirect golang.org/x/sync v0.17.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect ) go 1.24.0 toolchain go1.25.1 counterfeiter-6.12.0/go.sum000066400000000000000000000064651505763253600156400ustar00rootroot00000000000000github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0= github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8= github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/onsi/ginkgo/v2 v2.25.1 h1:Fwp6crTREKM+oA6Cz4MsO8RhKQzs2/gOIVOUscMAfZY= github.com/onsi/ginkgo/v2 v2.25.1/go.mod h1:ppTWQ1dh9KM/F1XgpeRqelR+zHVwV81DGRSDnFxK7Sk= github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A= github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k= github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8= github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM= go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ= golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc= golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg= golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= counterfeiter-6.12.0/integration/000077500000000000000000000000001505763253600170155ustar00rootroot00000000000000counterfeiter-6.12.0/integration/copy_test.go000066400000000000000000000042551505763253600213630ustar00rootroot00000000000000package integration_test import ( "io" "io/fs" "os" "path/filepath" "strings" ) // Copy copies src to dest, doesn't matter if src is a directory or a file func Copy(src, dest string) error { info, err := os.Lstat(src) if err != nil { return err } return copy(src, dest, info) } // copy dispatches copy-funcs according to the mode. // Because this "copy" could be called recursively, // "info" MUST be given here, NOT nil. func copy(src, dest string, info os.FileInfo) error { if info.Mode()&os.ModeSymlink != 0 { return lcopy(src, dest, info) } if info.IsDir() { if strings.HasSuffix(src, "fakes") { return nil } return dcopy(src, dest, info) } return fcopy(src, dest, info) } // fcopy is for just a file, // with considering existence of parent directory // and file permission. func fcopy(src, dest string, info os.FileInfo) error { if err := os.MkdirAll(filepath.Dir(dest), os.ModePerm); err != nil { return err } f, err := os.Create(dest) if err != nil { return err } defer f.Close() if err = os.Chmod(f.Name(), info.Mode()); err != nil { return err } s, err := os.Open(src) if err != nil { return err } defer s.Close() _, err = io.Copy(f, s) return err } // dcopy is for a directory, // with scanning contents inside the directory // and pass everything to "copy" recursively. func dcopy(srcdir, destdir string, info os.FileInfo) error { if err := os.MkdirAll(destdir, info.Mode()); err != nil { return err } entries, err := os.ReadDir(srcdir) if err != nil { return err } contents := make([]fs.FileInfo, 0, len(entries)) for _, entry := range entries { info, err := entry.Info() if err != nil { return err } contents = append(contents, info) } for _, content := range contents { cs, cd := filepath.Join(srcdir, content.Name()), filepath.Join(destdir, content.Name()) if err := copy(cs, cd, content); err != nil { // If any error, exit immediately return err } } return nil } // lcopy is for a symlink, // with just creating a new symlink by replicating src symlink. func lcopy(src, dest string, info os.FileInfo) error { src, err := os.Readlink(src) if err != nil { return err } return os.Symlink(src, dest) } counterfeiter-6.12.0/integration/empty.go000066400000000000000000000001301505763253600204740ustar00rootroot00000000000000package integration // empty go file to prevent go build from complaining in go <=1.10 counterfeiter-6.12.0/integration/roundtrip_module_test.go000066400000000000000000000006161505763253600240010ustar00rootroot00000000000000//go:build go1.11 package integration_test import ( "testing" "github.com/sclevine/spec" "github.com/sclevine/spec/report" ) func TestIntegration(t *testing.T) { suite := spec.New("integration", spec.Report(report.Terminal{})) suite("round trip as module", testRoundTripAsModule) suite.Run(t) } func testRoundTripAsModule(t *testing.T, when spec.G, it spec.S) { runTests(t, when, it) } counterfeiter-6.12.0/integration/roundtrip_test.go000066400000000000000000000201111505763253600224240ustar00rootroot00000000000000package integration_test import ( "fmt" "io" "log" "os" "path/filepath" "strings" "testing" . "github.com/onsi/gomega" "github.com/sclevine/spec" "github.com/maxbrunsfeld/counterfeiter/v6/generator" ) func runTests(t *testing.T, when spec.G, it spec.S) { log.SetOutput(io.Discard) // Comment this out to see verbose log output log.SetFlags(log.Llongfile) var ( baseDir string relativeDir string testDir string copyDirFunc func() copyFileFunc func(name string) initModuleFunc func() writeToTestData bool ) name := "working with a module" it.Before(func() { RegisterTestingT(t) var err error testDir, err = os.MkdirTemp("", "counterfeiter-integration") Expect(err).NotTo(HaveOccurred()) os.Unsetenv("GOPATH") baseDir = testDir err = os.MkdirAll(baseDir, 0777) Expect(err).ToNot(HaveOccurred()) relativeDir = filepath.Join("..", "fixtures") copyDirFunc = func() { err = os.MkdirAll(baseDir, 0777) Expect(err).ToNot(HaveOccurred()) err = Copy(relativeDir, baseDir) Expect(err).ToNot(HaveOccurred()) } copyFileFunc = func(name string) { dir := baseDir d := filepath.Dir(name) if d != "." { dir = filepath.Join(dir, d) } err = os.MkdirAll(dir, 0777) Expect(err).ToNot(HaveOccurred()) b, err := os.ReadFile(filepath.Join(relativeDir, name)) Expect(err).ToNot(HaveOccurred()) err = os.WriteFile(filepath.Join(baseDir, name), b, 0755) Expect(err).ToNot(HaveOccurred()) } initModuleFunc = func() { copyFileFunc("blank.go") err := os.WriteFile(filepath.Join(baseDir, "go.mod"), []byte("module github.com/maxbrunsfeld/counterfeiter/v6/fixtures"), 0755) Expect(err).ToNot(HaveOccurred()) } // Set this to true to write the output of tests to the testdata/output // directory 🙃 happy debugging! // writeToTestData = true }) it.After(func() { if baseDir == "" { return } err := os.RemoveAll(testDir) Expect(err).ToNot(HaveOccurred()) }) when("generating a fake for stdlib interfaces", func() { const ( noHeader = "noheader" withHeader = "header" ) t := func(header, variant string) { it("succeeds", func() { initModuleFunc() cache := &generator.FakeCache{} f, err := generator.NewFake(generator.InterfaceOrFunction, "WriteCloser", "io", "FakeWriteCloser", "custom", header, baseDir, cache) Expect(err).NotTo(HaveOccurred()) b, err := f.Generate(true) // Flip to false to see output if goimports fails Expect(err).NotTo(HaveOccurred()) if writeToTestData { WriteOutput(b, filepath.Join("testdata", "output", "write_closer", "actual."+variant+".go")) } WriteOutput(b, filepath.Join(baseDir, "fixturesfakes", "fake_write_closer."+variant+".go")) RunBuild(baseDir) b2, err := os.ReadFile(filepath.Join("testdata", "expected_fake_writecloser."+variant+".txt")) Expect(err).NotTo(HaveOccurred()) Expect(string(b2)).To(Equal(string(b))) }) } t("", noHeader) t("// some header\n//\n\n", withHeader) }) when("generating an interface for a package", func() { it("succeeds", func() { initModuleFunc() cache := &generator.FakeCache{} f, err := generator.NewFake(generator.Package, "", "os", "Os", "custom", "", baseDir, cache) Expect(err).NotTo(HaveOccurred()) b, err := f.Generate(true) // Flip to false to see output if goimports fails Expect(err).NotTo(HaveOccurred()) if writeToTestData { WriteOutput(b, filepath.Join("testdata", "output", "package_mode", "actual.go")) } WriteOutput(b, filepath.Join(baseDir, "fixturesfakes", "fake_os.go")) RunBuild(baseDir) }) }) when("generating interfaces using type aliases", func() { it.Before(func() { relativeDir = filepath.Join(relativeDir, "type_aliases") copyDirFunc() }) it("imports the aliased type, not the underlying type", func() { cache := &generator.FakeCache{} pkgPath := "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases" interfaceName := "WithAliasedType" fakePackageName := "type_aliasesfakes" f, err := generator.NewFake(generator.InterfaceOrFunction, interfaceName, pkgPath, "Fake"+interfaceName, fakePackageName, "", baseDir, cache) Expect(err).NotTo(HaveOccurred()) b, err := f.Generate(false) Expect(err).NotTo(HaveOccurred()) Expect(string(b)).NotTo(ContainSubstring("primitive")) Expect(string(b)).To(ContainSubstring(`"github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/extra"`)) }) }) when(name, func() { t := func(interfaceName string, filename string, subDir string, files ...string) { when("working with "+filename, func() { it.Before(func() { if subDir != "" { baseDir = filepath.Join(baseDir, subDir) relativeDir = filepath.Join(relativeDir, subDir) } log.Println(testDir) copyFileFunc(filename) for i := range files { copyFileFunc(files[i]) } }) it("succeeds", func() { suffix := strings.Replace(subDir, "\\", "/", -1) if suffix != "" { suffix = "/" + suffix } WriteOutput([]byte(fmt.Sprintf("module github.com/maxbrunsfeld/counterfeiter/v6/fixtures%s\n", suffix)), filepath.Join(baseDir, "go.mod")) cache := &generator.FakeCache{} f, err := generator.NewFake(generator.InterfaceOrFunction, interfaceName, fmt.Sprintf("github.com/maxbrunsfeld/counterfeiter/v6/fixtures%s", suffix), "Fake"+interfaceName, "fixturesfakes", "", baseDir, cache) Expect(err).NotTo(HaveOccurred()) b, err := f.Generate(true) // Flip to false to see output if goimports fails Expect(err).NotTo(HaveOccurred()) if writeToTestData { WriteOutput(b, filepath.Join("testdata", "output", strings.Replace(filename, ".go", "", -1), "actual.go")) } WriteOutput(b, filepath.Join(baseDir, "fixturesfakes", "fake_"+filename)) RunBuild(baseDir) }) }) } t("SomethingElse", "compound_return.go", "") t("DotImports", "dot_imports.go", "") t("EmbedsInterfaces", "embeds_interfaces.go", "", filepath.Join("another_package", "types.go")) t("AliasedInterface", "aliased_interfaces.go", "", filepath.Join("another_package", "types.go")) t("HasImports", "has_imports.go", "") t("HasOtherTypes", "has_other_types.go", "", "other_types.go") t("HasVarArgs", "has_var_args.go", "") t("HasVarArgsWithLocalTypes", "has_var_args.go", "") t("ImportsGoHyphenPackage", "imports_go_hyphen_package.go", "", filepath.Join("go-hyphenpackage", "fixture.go")) t("FirstInterface", "multiple_interfaces.go", "") t("SecondInterface", "multiple_interfaces.go", "") t("InlineStructParams", "inline_struct_params.go", "") t("RequestFactory", "request_factory.go", "") t("ReusesArgTypes", "reuses_arg_types.go", "") t("SomethingWithForeignInterface", "something_remote.go", "", filepath.Join("aliased_package", "in_aliased_package.go")) t("Something", "something.go", "") t("SomethingFactory", "typed_function.go", "") t("SyncSomething", "interface.go", "sync") when("working with duplicate packages", func() { t := func(interfaceName string, offset string, fakePackageName string) { when("working with "+interfaceName, func() { it.Before(func() { relativeDir = filepath.Join(relativeDir, "dup_packages") copyDirFunc() }) it("succeeds", func() { pkgPath := "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages" if offset != "" { pkgPath = pkgPath + "/" + offset } cache := &generator.FakeCache{} f, err := generator.NewFake(generator.InterfaceOrFunction, interfaceName, pkgPath, "Fake"+interfaceName, fakePackageName, "", baseDir, cache) Expect(err).NotTo(HaveOccurred()) b, err := f.Generate(false) // Flip to false to see output if goimports fails Expect(err).NotTo(HaveOccurred()) if writeToTestData { WriteOutput(b, filepath.Join("testdata", "output", "dup_"+strings.ToLower(interfaceName), "actual.go")) } WriteOutput(b, filepath.Join(baseDir, offset, fakePackageName, "fake_"+strings.ToLower(interfaceName)+".go")) RunBuild(filepath.Join(baseDir, offset, fakePackageName)) }) }) } t("MultiAB", "foo", "foofakes") t("AliasV1", "", "dup_packagesfakes") }) }) } counterfeiter-6.12.0/integration/testdata/000077500000000000000000000000001505763253600206265ustar00rootroot00000000000000counterfeiter-6.12.0/integration/testdata/expected_fake_multiab.txt000066400000000000000000000130061505763253600256730ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package foofakes import ( "sync" fooa "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/a/foo" foob "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/b/foo" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages/foo" ) type FakeMultiAB struct { MineStub func() foo.S mineMutex sync.RWMutex mineArgsForCall []struct{} mineReturns struct { result1 foo.S } mineReturnsOnCall map[int]struct { result1 foo.S } FromAStub func() fooa.S fromAMutex sync.RWMutex fromAArgsForCall []struct{} fromAReturns struct { result1 fooa.S } fromAReturnsOnCall map[int]struct { result1 fooa.S } FromBStub func() foob.S fromBMutex sync.RWMutex fromBArgsForCall []struct{} fromBReturns struct { result1 foob.S } fromBReturnsOnCall map[int]struct { result1 foob.S } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeMultiAB) Mine() foo.S { fake.mineMutex.Lock() ret, specificReturn := fake.mineReturnsOnCall[len(fake.mineArgsForCall)] fake.mineArgsForCall = append(fake.mineArgsForCall, struct{}{}) stub := fake.MineStub fakeReturns := fake.mineReturns fake.mineMutex.Unlock() fake.recordInvocation("Mine", []interface{}{}) if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeMultiAB) MineCallCount() int { fake.mineMutex.RLock() defer fake.mineMutex.RUnlock() return len(fake.mineArgsForCall) } func (fake *FakeMultiAB) MineCalls(stub func() foo.S) { fake.mineMutex.Lock() defer fake.mineMutex.Unlock() fake.MineStub = stub } func (fake *FakeMultiAB) MineReturns(result1 foo.S) { fake.mineMutex.Lock() defer fake.mineMutex.Unlock() fake.MineStub = nil fake.mineReturns = struct { result1 foo.S }{result1} } func (fake *FakeMultiAB) MineReturnsOnCall(i int, result1 foo.S) { fake.mineMutex.Lock() defer fake.mineMutex.Unlock() fake.MineStub = nil if fake.mineReturnsOnCall == nil { fake.mineReturnsOnCall = make(map[int]struct { result1 foo.S }) } fake.mineReturnsOnCall[i] = struct { result1 foo.S }{result1} } func (fake *FakeMultiAB) FromA() fooa.S { fake.fromAMutex.Lock() ret, specificReturn := fake.fromAReturnsOnCall[len(fake.fromAArgsForCall)] fake.fromAArgsForCall = append(fake.fromAArgsForCall, struct{}{}) stub := fake.FromAStub fakeReturns := fake.fromAReturns fake.recordInvocation("FromA", []interface{}{}) fake.fromAMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeMultiAB) FromACallCount() int { fake.fromAMutex.RLock() defer fake.fromAMutex.RUnlock() return len(fake.fromAArgsForCall) } func (fake *FakeMultiAB) FromACalls(stub func() fooa.S) { fake.fromAMutex.Lock() defer fake.fromAMutex.Unlock() fake.FromAStub = stub } func (fake *FakeMultiAB) FromAReturns(result1 fooa.S) { fake.fromAMutex.Lock() defer fake.fromAMutex.Unlock() fake.FromAStub = nil fake.fromAReturns = struct { result1 fooa.S }{result1} } func (fake *FakeMultiAB) FromAReturnsOnCall(i int, result1 fooa.S) { fake.fromAMutex.Lock() defer fake.fromAMutex.Unlock() fake.FromAStub = nil if fake.fromAReturnsOnCall == nil { fake.fromAReturnsOnCall = make(map[int]struct { result1 fooa.S }) } fake.fromAReturnsOnCall[i] = struct { result1 fooa.S }{result1} } func (fake *FakeMultiAB) FromB() foob.S { fake.fromBMutex.Lock() ret, specificReturn := fake.fromBReturnsOnCall[len(fake.fromBArgsForCall)] fake.fromBArgsForCall = append(fake.fromBArgsForCall, struct{}{}) stub := fake.FromBStub fakeReturns := fake.fromBReturns fake.recordInvocation("FromB", []interface{}{}) fake.fromBMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeMultiAB) FromBCallCount() int { fake.fromBMutex.RLock() defer fake.fromBMutex.RUnlock() return len(fake.fromBArgsForCall) } func (fake *FakeMultiAB) FromBCalls(stub func() foob.S) { fake.fromBMutex.Lock() defer fake.fromBMutex.Unlock() fake.FromBStub = stub } func (fake *FakeMultiAB) FromBReturns(result1 foob.S) { fake.fromBMutex.Lock() defer fake.fromBMutex.Unlock() fake.FromBStub = nil fake.fromBReturns = struct { result1 foob.S }{result1} } func (fake *FakeMultiAB) FromBReturnsOnCall(i int, result1 foob.S) { fake.fromBMutex.Lock() defer fake.fromBMutex.Unlock() fake.FromBStub = nil if fake.fromBReturnsOnCall == nil { fake.fromBReturnsOnCall = make(map[int]struct { result1 foob.S }) } fake.fromBReturnsOnCall[i] = struct { result1 foob.S }{result1} } func (fake *FakeMultiAB) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.mineMutex.RLock() defer fake.mineMutex.RUnlock() fake.fromAMutex.RLock() defer fake.fromAMutex.RUnlock() fake.fromBMutex.RLock() defer fake.fromBMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeMultiAB) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ foo.MultiAB = new(FakeMultiAB) counterfeiter-6.12.0/integration/testdata/expected_fake_somethingfactory.txt000066400000000000000000000054061505763253600276300ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package fixturesfakes import ( "sync" "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" ) type FakeSomethingFactory struct { Stub func(string, map[string]interface{}) string mutex sync.RWMutex argsForCall []struct { arg1 string arg2 map[string]interface{} } returns struct { result1 string } returnsOnCall map[int]struct { result1 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeSomethingFactory) Spy(arg1 string, arg2 map[string]interface{}) string { fake.mutex.Lock() ret, specificReturn := fake.returnsOnCall[len(fake.argsForCall)] fake.argsForCall = append(fake.argsForCall, struct { arg1 string arg2 map[string]interface{} }{arg1, arg2}) stub := fake.Stub returns := fake.returns fake.recordInvocation("SomethingFactory", []interface{}{arg1, arg2}) fake.mutex.Unlock() if stub != nil { return stub(arg1, arg2) } if specificReturn { return ret.result1 } return returns.result1 } func (fake *FakeSomethingFactory) CallCount() int { fake.mutex.RLock() defer fake.mutex.RUnlock() return len(fake.argsForCall) } func (fake *FakeSomethingFactory) Calls(stub func(string, map[string]interface{}) string) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = stub } func (fake *FakeSomethingFactory) ArgsForCall(i int) (string, map[string]interface{}) { fake.mutex.RLock() defer fake.mutex.RUnlock() return fake.argsForCall[i].arg1, fake.argsForCall[i].arg2 } func (fake *FakeSomethingFactory) Returns(result1 string) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil fake.returns = struct { result1 string }{result1} } func (fake *FakeSomethingFactory) ReturnsOnCall(i int, result1 string) { fake.mutex.Lock() defer fake.mutex.Unlock() fake.Stub = nil if fake.returnsOnCall == nil { fake.returnsOnCall = make(map[int]struct { result1 string }) } fake.returnsOnCall[i] = struct { result1 string }{result1} } func (fake *FakeSomethingFactory) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.mutex.RLock() defer fake.mutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeSomethingFactory) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ fixtures.SomethingFactory = new(FakeSomethingFactory).Spy counterfeiter-6.12.0/integration/testdata/expected_fake_writecloser.header.txt000066400000000000000000000105061505763253600300310ustar00rootroot00000000000000// some header // // Code generated by counterfeiter. DO NOT EDIT. package custom import ( "io" "sync" ) type FakeWriteCloser struct { CloseStub func() error closeMutex sync.RWMutex closeArgsForCall []struct { } closeReturns struct { result1 error } closeReturnsOnCall map[int]struct { result1 error } WriteStub func([]byte) (int, error) writeMutex sync.RWMutex writeArgsForCall []struct { arg1 []byte } writeReturns struct { result1 int result2 error } writeReturnsOnCall map[int]struct { result1 int result2 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeWriteCloser) Close() error { fake.closeMutex.Lock() ret, specificReturn := fake.closeReturnsOnCall[len(fake.closeArgsForCall)] fake.closeArgsForCall = append(fake.closeArgsForCall, struct { }{}) stub := fake.CloseStub fakeReturns := fake.closeReturns fake.recordInvocation("Close", []interface{}{}) fake.closeMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeWriteCloser) CloseCallCount() int { fake.closeMutex.RLock() defer fake.closeMutex.RUnlock() return len(fake.closeArgsForCall) } func (fake *FakeWriteCloser) CloseCalls(stub func() error) { fake.closeMutex.Lock() defer fake.closeMutex.Unlock() fake.CloseStub = stub } func (fake *FakeWriteCloser) CloseReturns(result1 error) { fake.closeMutex.Lock() defer fake.closeMutex.Unlock() fake.CloseStub = nil fake.closeReturns = struct { result1 error }{result1} } func (fake *FakeWriteCloser) CloseReturnsOnCall(i int, result1 error) { fake.closeMutex.Lock() defer fake.closeMutex.Unlock() fake.CloseStub = nil if fake.closeReturnsOnCall == nil { fake.closeReturnsOnCall = make(map[int]struct { result1 error }) } fake.closeReturnsOnCall[i] = struct { result1 error }{result1} } func (fake *FakeWriteCloser) Write(arg1 []byte) (int, error) { var arg1Copy []byte if arg1 != nil { arg1Copy = make([]byte, len(arg1)) copy(arg1Copy, arg1) } fake.writeMutex.Lock() ret, specificReturn := fake.writeReturnsOnCall[len(fake.writeArgsForCall)] fake.writeArgsForCall = append(fake.writeArgsForCall, struct { arg1 []byte }{arg1Copy}) stub := fake.WriteStub fakeReturns := fake.writeReturns fake.recordInvocation("Write", []interface{}{arg1Copy}) fake.writeMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1, ret.result2 } return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeWriteCloser) WriteCallCount() int { fake.writeMutex.RLock() defer fake.writeMutex.RUnlock() return len(fake.writeArgsForCall) } func (fake *FakeWriteCloser) WriteCalls(stub func([]byte) (int, error)) { fake.writeMutex.Lock() defer fake.writeMutex.Unlock() fake.WriteStub = stub } func (fake *FakeWriteCloser) WriteArgsForCall(i int) []byte { fake.writeMutex.RLock() defer fake.writeMutex.RUnlock() argsForCall := fake.writeArgsForCall[i] return argsForCall.arg1 } func (fake *FakeWriteCloser) WriteReturns(result1 int, result2 error) { fake.writeMutex.Lock() defer fake.writeMutex.Unlock() fake.WriteStub = nil fake.writeReturns = struct { result1 int result2 error }{result1, result2} } func (fake *FakeWriteCloser) WriteReturnsOnCall(i int, result1 int, result2 error) { fake.writeMutex.Lock() defer fake.writeMutex.Unlock() fake.WriteStub = nil if fake.writeReturnsOnCall == nil { fake.writeReturnsOnCall = make(map[int]struct { result1 int result2 error }) } fake.writeReturnsOnCall[i] = struct { result1 int result2 error }{result1, result2} } func (fake *FakeWriteCloser) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeWriteCloser) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ io.WriteCloser = new(FakeWriteCloser) counterfeiter-6.12.0/integration/testdata/expected_fake_writecloser.noheader.txt000066400000000000000000000104631505763253600303700ustar00rootroot00000000000000// Code generated by counterfeiter. DO NOT EDIT. package custom import ( "io" "sync" ) type FakeWriteCloser struct { CloseStub func() error closeMutex sync.RWMutex closeArgsForCall []struct { } closeReturns struct { result1 error } closeReturnsOnCall map[int]struct { result1 error } WriteStub func([]byte) (int, error) writeMutex sync.RWMutex writeArgsForCall []struct { arg1 []byte } writeReturns struct { result1 int result2 error } writeReturnsOnCall map[int]struct { result1 int result2 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } func (fake *FakeWriteCloser) Close() error { fake.closeMutex.Lock() ret, specificReturn := fake.closeReturnsOnCall[len(fake.closeArgsForCall)] fake.closeArgsForCall = append(fake.closeArgsForCall, struct { }{}) stub := fake.CloseStub fakeReturns := fake.closeReturns fake.recordInvocation("Close", []interface{}{}) fake.closeMutex.Unlock() if stub != nil { return stub() } if specificReturn { return ret.result1 } return fakeReturns.result1 } func (fake *FakeWriteCloser) CloseCallCount() int { fake.closeMutex.RLock() defer fake.closeMutex.RUnlock() return len(fake.closeArgsForCall) } func (fake *FakeWriteCloser) CloseCalls(stub func() error) { fake.closeMutex.Lock() defer fake.closeMutex.Unlock() fake.CloseStub = stub } func (fake *FakeWriteCloser) CloseReturns(result1 error) { fake.closeMutex.Lock() defer fake.closeMutex.Unlock() fake.CloseStub = nil fake.closeReturns = struct { result1 error }{result1} } func (fake *FakeWriteCloser) CloseReturnsOnCall(i int, result1 error) { fake.closeMutex.Lock() defer fake.closeMutex.Unlock() fake.CloseStub = nil if fake.closeReturnsOnCall == nil { fake.closeReturnsOnCall = make(map[int]struct { result1 error }) } fake.closeReturnsOnCall[i] = struct { result1 error }{result1} } func (fake *FakeWriteCloser) Write(arg1 []byte) (int, error) { var arg1Copy []byte if arg1 != nil { arg1Copy = make([]byte, len(arg1)) copy(arg1Copy, arg1) } fake.writeMutex.Lock() ret, specificReturn := fake.writeReturnsOnCall[len(fake.writeArgsForCall)] fake.writeArgsForCall = append(fake.writeArgsForCall, struct { arg1 []byte }{arg1Copy}) stub := fake.WriteStub fakeReturns := fake.writeReturns fake.recordInvocation("Write", []interface{}{arg1Copy}) fake.writeMutex.Unlock() if stub != nil { return stub(arg1) } if specificReturn { return ret.result1, ret.result2 } return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeWriteCloser) WriteCallCount() int { fake.writeMutex.RLock() defer fake.writeMutex.RUnlock() return len(fake.writeArgsForCall) } func (fake *FakeWriteCloser) WriteCalls(stub func([]byte) (int, error)) { fake.writeMutex.Lock() defer fake.writeMutex.Unlock() fake.WriteStub = stub } func (fake *FakeWriteCloser) WriteArgsForCall(i int) []byte { fake.writeMutex.RLock() defer fake.writeMutex.RUnlock() argsForCall := fake.writeArgsForCall[i] return argsForCall.arg1 } func (fake *FakeWriteCloser) WriteReturns(result1 int, result2 error) { fake.writeMutex.Lock() defer fake.writeMutex.Unlock() fake.WriteStub = nil fake.writeReturns = struct { result1 int result2 error }{result1, result2} } func (fake *FakeWriteCloser) WriteReturnsOnCall(i int, result1 int, result2 error) { fake.writeMutex.Lock() defer fake.writeMutex.Unlock() fake.WriteStub = nil if fake.writeReturnsOnCall == nil { fake.writeReturnsOnCall = make(map[int]struct { result1 int result2 error }) } fake.writeReturnsOnCall[i] = struct { result1 int result2 error }{result1, result2} } func (fake *FakeWriteCloser) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } func (fake *FakeWriteCloser) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { fake.invocations = map[string][][]interface{}{} } if fake.invocations[key] == nil { fake.invocations[key] = [][]interface{}{} } fake.invocations[key] = append(fake.invocations[key], args) } var _ io.WriteCloser = new(FakeWriteCloser) counterfeiter-6.12.0/integration/util_test.go000066400000000000000000000011161505763253600213570ustar00rootroot00000000000000package integration_test import ( "bytes" "fmt" "os" "os/exec" "path/filepath" "io/fs" . "github.com/onsi/gomega" ) func WriteOutput(b []byte, file string) { _ = os.MkdirAll(filepath.Dir(file), 0700) _ = os.WriteFile(file, b, fs.FileMode(0600)) } func RunBuild(baseDir string) { cmd := exec.Command("go", "build", "./...") cmd.Dir = baseDir stdout := &bytes.Buffer{} stderr := &bytes.Buffer{} cmd.Stdout = stdout cmd.Stderr = stderr err := cmd.Run() if err != nil { fmt.Println(stdout.String()) fmt.Println(stderr.String()) } Expect(err).NotTo(HaveOccurred()) } counterfeiter-6.12.0/main.go000066400000000000000000000121731505763253600157510ustar00rootroot00000000000000package main import ( "errors" "fmt" "go/format" "io" "log" "os" "path/filepath" "runtime/debug" "runtime/pprof" "github.com/maxbrunsfeld/counterfeiter/v6/arguments" "github.com/maxbrunsfeld/counterfeiter/v6/command" "github.com/maxbrunsfeld/counterfeiter/v6/generator" ) func main() { debug.SetGCPercent(-1) if err := run(); err != nil { fail("%v", err) } } func run() error { profile := os.Getenv("COUNTERFEITER_PROFILE") != "" if profile { p, err := filepath.Abs(filepath.Join(".", "counterfeiter.profile")) if err != nil { return err } f, err := os.Create(p) if err != nil { return err } if err := pprof.StartCPUProfile(f); err != nil { return err } fmt.Printf("Profile: %s\n", p) defer pprof.StopCPUProfile() } log.SetFlags(log.Lshortfile) if !isDebug() { log.SetOutput(io.Discard) } cwd, err := os.Getwd() if err != nil { return errors.New("Error - couldn't determine current working directory") } var cache generator.Cacher var headerReader generator.FileReader if disableCache() { cache = &generator.FakeCache{} headerReader = &generator.SimpleFileReader{} } else { cache = &generator.Cache{} headerReader = &generator.CachedFileReader{} } var invocations []command.Invocation var args *arguments.ParsedArguments args, _ = arguments.New(os.Args, cwd, filepath.EvalSymlinks, os.Stat) generateMode := false if args != nil { generateMode = args.GenerateMode } if !generateMode && shouldPrintGenerateWarning() { fmt.Printf("\nWARNING: Invoking counterfeiter multiple times from \"go generate\" is slow.\nConsider using counterfeiter:generate directives to speed things up.\nSee https://github.com/maxbrunsfeld/counterfeiter#step-2b---add-counterfeitergenerate-directives for more information.\nSet the \"COUNTERFEITER_NO_GENERATE_WARNING\" environment variable to suppress this message.\n\n") } invocations, err = command.Detect(cwd, os.Args, generateMode) if err != nil { return err } for i := range invocations { a, err := arguments.New(invocations[i].Args, cwd, filepath.EvalSymlinks, os.Stat) if err != nil { return err } // If the '//counterfeiter:generate ...' line does not have a '-header' // flag, we use the one from the "global" // '//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate -header /some/header.txt' // line (which defaults to none). By doing so, we can configure the header // once per package, which is probably the most common case for adding // licence headers (i.e. all the fakes will have the same licence headers). a.HeaderFile = or(a.HeaderFile, args.HeaderFile) err = generate(cwd, a, cache, headerReader) if err != nil { return err } } return nil } func or(opts ...string) string { for _, s := range opts { if s != "" { return s } } return "" } func isDebug() bool { return os.Getenv("COUNTERFEITER_DEBUG") != "" } func disableCache() bool { return os.Getenv("COUNTERFEITER_DISABLECACHE") != "" } func shouldPrintGenerateWarning() bool { return invokedByGoGenerate() && os.Getenv("COUNTERFEITER_NO_GENERATE_WARNING") == "" } func invokedByGoGenerate() bool { return os.Getenv("DOLLAR") == "$" } func generate(workingDir string, args *arguments.ParsedArguments, cache generator.Cacher, headerReader generator.FileReader) error { if !args.Quiet { if err := reportStarting(workingDir, args.OutputPath, args.FakeImplName); err != nil { return err } } b, err := doGenerate(workingDir, args, cache, headerReader) if err != nil { return err } if err := printCode(b, args.OutputPath, args.PrintToStdOut); err != nil { return err } if !args.Quiet { fmt.Fprint(os.Stderr, "Done\n") } return nil } func doGenerate(workingDir string, args *arguments.ParsedArguments, cache generator.Cacher, headerReader generator.FileReader) ([]byte, error) { mode := generator.InterfaceOrFunction if args.GenerateInterfaceAndShimFromPackageDirectory { mode = generator.Package } headerContent, err := headerReader.Get(workingDir, args.HeaderFile) if err != nil { return nil, err } f, err := generator.NewFake(mode, args.InterfaceName, args.PackagePath, args.FakeImplName, args.DestinationPackageName, headerContent, workingDir, cache) if err != nil { return nil, err } return f.Generate(true) } func printCode(code []byte, outputPath string, printToStdOut bool) error { formattedCode, err := format.Source(code) if err != nil { return err } if printToStdOut { fmt.Println(string(formattedCode)) return nil } _ = os.MkdirAll(filepath.Dir(outputPath), 0777) file, err := os.Create(outputPath) if err != nil { return fmt.Errorf("Couldn't create fake file - %v", err) } _, err = file.Write(formattedCode) if err != nil { return fmt.Errorf("Couldn't write to fake file - %v", err) } return nil } func reportStarting(workingDir string, outputPath, fakeName string) error { rel, err := filepath.Rel(workingDir, outputPath) if err != nil { return err } msg := fmt.Sprintf("Writing `%s` to `%s`... ", fakeName, rel) if isDebug() { msg = msg + "\n" } fmt.Fprint(os.Stderr, msg) return nil } func fail(s string, args ...interface{}) { fmt.Printf("\n"+s+"\n", args...) os.Exit(1) } counterfeiter-6.12.0/scripts/000077500000000000000000000000001505763253600161615ustar00rootroot00000000000000counterfeiter-6.12.0/scripts/checkclean.sh000077500000000000000000000006141505763253600206010ustar00rootroot00000000000000#!/usr/bin/env bash set -eu cd "$(dirname "$0")/.." echo echo "Validating that generated fakes have not changed..." echo git diff --exit-code if output=$(git status --porcelain) && [ ! -z "$output" ]; then echo "the working copy is not clean; make sure that go generate ./... has been run, and" echo "that you have committed or ignored all files before running ./scripts/ci.sh" exit 1 fi counterfeiter-6.12.0/scripts/ci.ps1000066400000000000000000000020741505763253600172040ustar00rootroot00000000000000echo "=========================" echo "windows build is starting" echo "=========================" function ExitWithCode { param ( $exitcode ) $host.SetShouldExit($exitcode) exit } echo "running go vet..." echo "-------------------" echo "" go vet ./... if ($LASTEXITCODE -ne 0) { ExitWithCode -exitcode $LASTEXITCODE } echo "installing counterfeiter..." echo "---------------------------" echo "" go install . if ($LASTEXITCODE -ne 0) { ExitWithCode -exitcode $LASTEXITCODE } set-alias counterfeiter counterfeiter.exe echo "generating fakes..." echo "-------------------" echo "" go generate ./... if ($LASTEXITCODE -ne 0) { ExitWithCode -exitcode $LASTEXITCODE } echo "ensuring generated fakes compile..." echo "-----------------------------------" echo "" go build -v ./... if ($LASTEXITCODE -ne 0) { ExitWithCode -exitcode $LASTEXITCODE } echo "running tests..." echo "----------------" echo "" go test -v -race ./... if ($LASTEXITCODE -ne 0) { ExitWithCode -exitcode $LASTEXITCODE } echo "Windows test suite was a 'sweet' success" counterfeiter-6.12.0/scripts/ci.sh000077500000000000000000000041401505763253600171120ustar00rootroot00000000000000#!/usr/bin/env bash set -eu cd "$(dirname "$0")/.." pwd GOCOMMAND="go" # GOCOMMAND="go1.22rc1" # run ${GOCOMMAND} vet to verify everything builds and to check common issues echo echo "Running ${GOCOMMAND} vet..." echo ${GOCOMMAND} vet ./... # counterfeit all the things echo echo "Installing counterfeiter..." echo ${GOCOMMAND} install . # counterfeit all the things echo echo "Generating fakes used by tests..." echo ${GOCOMMAND} generate ./... # validate that the generated fakes match the committed fakes echo echo "Validating that generated fakes have not changed..." echo git diff --exit-code if output=$(git status --porcelain) && [ ! -z "$output" ]; then echo "the working copy is not clean; make sure that ${GOCOMMAND} generate ./... has been run, and" echo "that you have committed or ignored all files before running ./scripts/ci.sh" exit 1 fi # check that the fakes compile echo echo "Ensuring generated fakes compile..." echo ${GOCOMMAND} build -v ./... # run the tests using the fakes echo echo "Running tests..." echo ${GOCOMMAND} test -race ./... echo " _______ _ _ _______ _______ _______ | || | _ | || || || | | _____|| || || || ___|| ___||_ _| | |_____ | || |___ | |___ | | |_____ || || ___|| ___| | | _____| || _ || |___ | |___ | | |_______||__| |__||_______||_______| |___| _______ __ __ ___ _______ _______ | || | | || | | || | | _____|| | | || | |_ _|| ___| | |_____ | |_| || | | | | |___ |_____ || || | | | | ___| _____| || || | | | | |___ |_______||_______||___| |___| |_______| _______ __ __ _______ _______ _______ _______ _______ | || | | || || || || || | | _____|| | | || || || ___|| _____|| _____| | |_____ | |_| || || || |___ | |_____ | |_____ |_____ || || _|| _|| ___||_____ ||_____ | _____| || || |_ | |_ | |___ _____| | _____| | |_______||_______||_______||_______||_______||_______||_______| " counterfeiter-6.12.0/scripts/cleanfakes.sh000077500000000000000000000001641505763253600206150ustar00rootroot00000000000000#!/usr/bin/env bash set -eu cd "$(dirname "$0")/.." pwd find ./ -path '*fakes/fake*.go' -print0 | xargs -0 rm -rf counterfeiter-6.12.0/scripts/counterfeiter.bat000066400000000000000000000000221505763253600215210ustar00rootroot00000000000000counterfeiter.exe