Code Monkey home page Code Monkey logo

depstubber's Introduction

depstubber

This is a tool that generates type-correct stubs for dependencies, for use in testing. It is particularly useful for testing static analysis applications, where including library source code may be undesirable. It was written and is currently used for testing CodeQL Go.

The general usage pattern if vendoring is desired will look something like:

go install github.com/github/depstubber
go mod tidy # required to generate go.sum
# generate a vendor/module.txt for the go 1.24 vendor consistency check
depstubber -write_module_txt
depstubber -vendor github.com/my/package Type1,Type2 SomeFunc,SomeVariable

The last line can be executed using Go's built in generate subcommand, by adding a comment to any relevant Go file that looks like this:

//go:generate depstubber -vendor github.com/my/package Type1,Type2 SomeFunc,SomeVariable

Then, run go generate <package>, where <package> is the package containing the file the comment was added to. This will automatically run the depstubber command.

Limitations:

  • It is limited to a single package at a time.
  • There is no way to automatically stub all exports.
  • It does not generate memory-compatible types, as unexported types are skipped.
  • There is no way to automatically detect exports used in a program.
  • There is no way to specify specific methods on a type; all methods are automatically stubbed.
  • It cannot currently distinguish between type aliases. This is a limitation of the reflect package.

Please feel free to submit a pull request for any of the above, or with any other improvements. See CONTRIBUTING.md for more information.

For information about what improvements may be in progress, see issues.

To build, simply run go build with Go 1.14 or higher.

This project contains a significant amount of code copied from the GoMock project, as well as from the Go standard library. The mock code has been adapted to generate stub versions of requested exported fields instead of generating a mock implementation of an interface. The licenses for both these codebases can be found in the NOTICE file.

It is licensed under Apache-2.0. For more information, see the LICENSE file.

depstubber's People

Contributors

max-schaefer avatar

Stargazers

Shawn Charles avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.