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:
@@ -68,10 +68,11 @@ fn test_generated_code_builds() {
|
|||||||
|
|
||||||
// 4. Write the generated code to src/lib.rs
|
// 4. Write the generated code to src/lib.rs
|
||||||
// The generated code uses `use crate::{...}`, but it's now in a separate crate.
|
// 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();
|
let mut all_code = String::new();
|
||||||
for (_, content) in generated_files {
|
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");
|
all_code.push_str("\n");
|
||||||
}
|
}
|
||||||
let lib_path = temp_project_dir.join("src/lib.rs");
|
let lib_path = temp_project_dir.join("src/lib.rs");
|
||||||
|
|||||||
@@ -55,12 +55,12 @@ fn test_helloworld_generated_code_builds() {
|
|||||||
// 4. Write the generated code to src/lib.rs
|
// 4. Write the generated code to src/lib.rs
|
||||||
let mut all_code = String::new();
|
let mut all_code = String::new();
|
||||||
for (_, content) in generated_files {
|
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");
|
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");
|
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
|
// 5. Attempt to build the project
|
||||||
let build_status = Command::new("cargo")
|
let build_status = Command::new("cargo")
|
||||||
|
|||||||
@@ -49,22 +49,26 @@ fn test_map_generated_code_builds() {
|
|||||||
// 4. Write the generated code to src/lib.rs
|
// 4. Write the generated code to src/lib.rs
|
||||||
let mut all_code = String::new();
|
let mut all_code = String::new();
|
||||||
for (_, content) in generated_files {
|
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");
|
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");
|
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
|
// 5. Attempt to build the project
|
||||||
let build_status = Command::new("cargo")
|
let output = Command::new("cargo")
|
||||||
.args(["build"])
|
.args(["build"])
|
||||||
.current_dir(&temp_project_dir)
|
.current_dir(&temp_project_dir)
|
||||||
.status()
|
.output()
|
||||||
.expect("Failed to run cargo build");
|
.expect("Failed to run cargo build");
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
eprintln!("Cargo build failed:\n{}", String::from_utf8_lossy(&output.stderr));
|
||||||
|
}
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
build_status.success(),
|
output.status.success(),
|
||||||
"The generated Rust code for test_map.proto failed to build in a standalone project!"
|
"The generated Rust code for test_map.proto failed to build in a standalone project!"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,17 +49,12 @@ fn test_types_generated_code_builds() {
|
|||||||
// 4. Write the generated code to src/lib.rs
|
// 4. Write the generated code to src/lib.rs
|
||||||
let mut all_code = String::new();
|
let mut all_code = String::new();
|
||||||
for (_, content) in generated_files {
|
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");
|
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");
|
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
|
// 5. Attempt to build the project
|
||||||
let build_status = Command::new("cargo")
|
let build_status = Command::new("cargo")
|
||||||
|
|||||||
Reference in New Issue
Block a user