protoc-gen-debug

command
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

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