Add test that ensures rust protos build with reserved keywords

Also confirmed that this fails to build without the `r#` inside singular_scalar.cc

PiperOrigin-RevId: 546906226
pull/13253/head
Hong Shin 2 years ago committed by Copybara-Service
parent 4f20efbb78
commit b01794cb3b
  1. 32
      rust/test/BUILD
  2. 37
      rust/test/reserved.proto
  3. 18
      rust/test/shared/BUILD
  4. 39
      rust/test/shared/reserved_test.rs

@ -175,3 +175,35 @@ rust_upb_proto_library(
],
deps = [":no_package_proto"],
)
proto_library(
name = "reserved_proto",
testonly = True,
srcs = ["reserved.proto"],
)
cc_proto_library(
name = "reserved_cc_proto",
testonly = True,
deps = [":reserved_proto"],
)
rust_cc_proto_library(
name = "reserved_cc_rust_proto",
testonly = True,
visibility = [
"//rust/test/cpp:__subpackages__",
"//rust/test/shared:__subpackages__",
],
deps = [":reserved_cc_proto"],
)
rust_upb_proto_library(
name = "reserved_upb_rust_proto",
testonly = True,
visibility = [
"//rust/test/shared:__subpackages__",
"//rust/test/upb:__subpackages__",
],
deps = [":reserved_proto"],
)

@ -0,0 +1,37 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google LLC. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto2";
package naming;
message Reserved {
optional int32 for = 1; // for is a reserved word in rust, let's make sure we can compile it
}

@ -54,6 +54,24 @@ rust_test(
],
)
rust_test(
name = "reserved_cpp_test",
srcs = ["reserved_test.rs"],
deps = [
"//rust/test:reserved_cc_rust_proto",
"//rust/test:unittest_cc_rust_proto",
],
)
rust_test(
name = "reserved_upb_test",
srcs = ["reserved_test.rs"],
deps = [
"//rust/test:reserved_upb_rust_proto",
"//rust/test:unittest_upb_rust_proto",
],
)
rust_test(
name = "nested_messages_cpp_test",
srcs = ["nested_messages_test.rs"],

@ -0,0 +1,39 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google LLC. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/// Test covering proto compilation with reserved words.
use reserved_proto::naming::Reserved;
#[test]
fn test_reserved_keyword_in_accessors() {
let msg = Reserved::new();
let res = msg.r#for();
assert_eq!(res, 0);
}
Loading…
Cancel
Save