Update crate references in codegen tests

Update imports to use `roto_tonic` instead of `crate` for BufferPool
and StatusBody. Remove the broad replacement of `crate` with `roto`
and add error output to `test_map_build.rs`.
This commit is contained in:
2026-05-16 19:45:46 -07:00
parent 56fc787f7a
commit b11b068345
4 changed files with 19 additions and 19 deletions
+3 -2
View File
@@ -68,10 +68,11 @@ fn test_generated_code_builds() {
// 4. Write the generated code to src/lib.rs
// The generated code uses `use crate::{...}`, but it's now in a separate crate.
// Replace `crate` with `roto` to reference the types in the dependency.
// Replace `crate` with `roto_tonic` to reference the types in the dependency.
let mut all_code = String::new();
for (_, content) in generated_files {
all_code.push_str(&content);
let replaced = content.replace("use crate::{BufferPool, StatusBody};", "use roto_tonic::{BufferPool, StatusBody};");
all_code.push_str(&replaced);
all_code.push_str("\n");
}
let lib_path = temp_project_dir.join("src/lib.rs");
+3 -3
View File
@@ -55,12 +55,12 @@ fn test_helloworld_generated_code_builds() {
// 4. Write the generated code to src/lib.rs
let mut all_code = String::new();
for (_, content) in generated_files {
all_code.push_str(&content);
let replaced = content.replace("use crate::{BufferPool, StatusBody};", "use roto_tonic::{BufferPool, StatusBody};");
all_code.push_str(&replaced);
all_code.push_str("\n");
}
let final_code = all_code.replace("use crate::", "use roto::");
let lib_path = temp_project_dir.join("src/lib.rs");
fs::write(lib_path, final_code).expect("Failed to write generated code to src/lib.rs");
fs::write(lib_path, all_code).expect("Failed to write generated code to src/lib.rs");
// 5. Attempt to build the project
let build_status = Command::new("cargo")
+10 -6
View File
@@ -49,22 +49,26 @@ fn test_map_generated_code_builds() {
// 4. Write the generated code to src/lib.rs
let mut all_code = String::new();
for (_, content) in generated_files {
all_code.push_str(&content);
let replaced = content.replace("use crate::{BufferPool, StatusBody};", "use roto_tonic::{BufferPool, StatusBody};");
all_code.push_str(&replaced);
all_code.push_str("\n");
}
let final_code = all_code.replace("use crate::", "use roto::");
let lib_path = temp_project_dir.join("src/lib.rs");
fs::write(lib_path, final_code).expect("Failed to write generated code to src/lib.rs");
fs::write(lib_path, all_code).expect("Failed to write generated code to src/lib.rs");
// 5. Attempt to build the project
let build_status = Command::new("cargo")
let output = Command::new("cargo")
.args(["build"])
.current_dir(&temp_project_dir)
.status()
.output()
.expect("Failed to run cargo build");
if !output.status.success() {
eprintln!("Cargo build failed:\n{}", String::from_utf8_lossy(&output.stderr));
}
assert!(
build_status.success(),
output.status.success(),
"The generated Rust code for test_map.proto failed to build in a standalone project!"
);
}
+3 -8
View File
@@ -49,17 +49,12 @@ fn test_types_generated_code_builds() {
// 4. Write the generated code to src/lib.rs
let mut all_code = String::new();
for (_, content) in generated_files {
all_code.push_str(&content);
let replaced = content.replace("use crate::{BufferPool, StatusBody};", "use roto_tonic::{BufferPool, StatusBody};");
all_code.push_str(&replaced);
all_code.push_str("\n");
}
// The generated code uses `use crate::{...}`, but it's now in a separate crate.
// Replace `crate` with `roto` to reference the types in the dependency.
// Note: in build_generated_code.rs it does replace("use crate::", "use roto::").
// But here the generated code might not have dependencies since it's a single file.
// However, to be safe and consistent with the template:
let final_code = all_code.replace("use crate::", "use roto::");
let lib_path = temp_project_dir.join("src/lib.rs");
fs::write(lib_path, final_code).expect("Failed to write generated code to src/lib.rs");
fs::write(lib_path, all_code).expect("Failed to write generated code to src/lib.rs");
// 5. Attempt to build the project
let build_status = Command::new("cargo")