Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): Refactor skip debug test #1922

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/skip_debug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ prost = "0.13"
tonic = { path = "../../tonic" }

[build-dependencies]
prost-build = "0.13"
tonic-build = { path = "../../tonic-build" }
19 changes: 1 addition & 18 deletions tests/skip_debug/build.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
fn main() {
let config = prost_build::Config::default();
tonic_build::configure()
.skip_debug("test.Test")
.skip_debug("test.Output")
.build_client(true)
.build_server(true)
.compile_protos_with_config(config, &["proto/test.proto"], &["proto"])
.compile_protos(&["proto/test.proto"], &["proto"])
.unwrap();

// Add a dummy impl Debug to the skipped debug implementations to avoid missing impl Debug errors
let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
let file_path = out.join("test.rs");
let mut file_contents = std::fs::read_to_string(&file_path).unwrap();
let debug_impl = r#"
impl std::fmt::Debug for Output {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Output").finish()
}
}
"#;
file_contents.push_str(debug_impl);

// Replace the original file with the modified content
std::fs::write(&file_path, file_contents).unwrap();
}
8 changes: 8 additions & 0 deletions tests/skip_debug/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
pub mod pb {
tonic::include_proto!("test");

// Add a dummy impl Debug to the skipped debug implementations to avoid
// missing impl Debug errors and check debug is not implemented for Output.
impl std::fmt::Debug for Output {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Output").finish()
}
}
}