protoc-gen-debug

command
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

protoc-gen-debug

This plugin can be used to create test files containing the entire encoded CodeGeneratorRequest passed from a protoc execution. This is useful for testing plugins programmatically without having to run protoc. For an example usage, check out ast_test.go in the project root as well as testdata/graph for the test cases.

Executing the plugin will place a code_generator_request.pb.bin file in the specified output location which can be fed directly into a PG* plugin via the ProtocInput init option.

Installation

For a local install:

make bin/protoc-gen-debug

For a global install into $GOPATH/bin:

go install github.com/lyft/protoc-gen-star/protoc-gen-debug

Usage

To create the code_generator_request.pb.bin file for all protos in the current directory:

protoc \
  --plugin=protoc-gen-debug=path/to/protoc-gen-debug \
  --debug_out=".:." \
  *.proto

To use the code_generator_request.pb.bin in PG*:

func TestModule(t *testing.T) {
  req, err := os.Open("./code_generator_request.pb.bin")
  if err != nil {
    t.Fatal(err)
  }
  
  fs := afero.NewMemMapFs()
  res := &bytes.Buffer{}
  
  pgs.Init(
    pgs.ProtocInput(req),  // use the pre-generated request
    pgs.ProtocOutput(res), // capture CodeGeneratorResponse
    pgs.FileSystem(fs),    // capture any custom files written directly to disk
  ).RegisterModule(&MyModule{}).Render()
  
  // check res and the fs for output
}

Documentation

Overview

protoc-gen-debug emits the raw encoded CodeGeneratorRequest from a protoc execution to a file. This is particularly useful for testing (see the testdata/graph package for test cases).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL