tower-rs / tower-grpc

A gRPC client & server implementation.
MIT License
562 stars 73 forks source link

Protobuf comments may be interpreted as doctests #214

Open olix0r opened 4 years ago

olix0r commented 4 years ago

When a protobuf file includes comments that indent or triple-quote text, the generated code fails doctests. For example, a protobuf like the following:

https://github.com/linkerd/linkerd2-proxy/blob/fffe76dae9c72a2184848de5e863206f7e5ebd4b/opencensus-proto/opencensus/proto/trace/v1/trace.proto#L154-L157

will cause test failures like:

running 1 test
test /home/ver/b/l2-proxy/target/debug/build/opencensus-proto-052098f4f8ec2ee6/out/opencensus.proto.trace.v1.rs - trace::v1::span::Attributes::attribute_map (line 150) ... FAILED

failures:

---- /home/ver/b/l2-proxy/target/debug/build/opencensus-proto-052098f4f8ec2ee6/out/opencensus.proto.trace.v1.rs - trace::v1::span::Attributes::attribute_map (line 150) stdout ----
error: expected type, found `"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"`
 --> /home/ver/b/l2-proxy/target/debug/build/opencensus-proto-052098f4f8ec2ee6/out/opencensus.proto.trace.v1.rs:151:21
  |
3 | "/http/user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
  |                   - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type
  |                   |
  |                   tried to parse a type due to this

error: aborting due to previous error

Couldn't compile the test.

failures:
    /home/ver/b/l2-proxy/target/debug/build/opencensus-proto-052098f4f8ec2ee6/out/opencensus.proto.trace.v1.rs - trace::v1::span::Attributes::attribute_map (line 150)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

The generated code should disable doctest from attempting to compile comments originating from protobuf.

mzabaluev commented 4 years ago

There should be a generator option on how to treat the comments from .proto: ignore, include verbatim as markdown, or try to sanitize as markdown-neutral text.