Code compiles, but tests fail

This commit is contained in:
2026-05-04 09:04:28 -07:00
parent d9be36726f
commit 87b111faf5
4 changed files with 50 additions and 7 deletions
+2 -3
View File
@@ -1,10 +1,9 @@
use env_logger::init; use env_logger::init;
use log::{error, info}; use log::{error, info};
use roto::generator::generate_rust_code; use roto::generator::generate_rust_code;
use roto::google::protobuf::descriptor::{ use roto::proto_gen::google::protobuf::descriptor::{
FileDescriptorSet CodeGeneratorRequest, CodeGeneratorResponse, FileDescriptorSet, ResponseFile,
}; };
use roto::google::protobuf::compiler::plugin::{CodeGeneratorRequest, CodeGeneratorResponse};
use roto::ProtoBuilder; use roto::ProtoBuilder;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
+3 -3
View File
@@ -1,8 +1,8 @@
use crate::google::protobuf::descriptor::{
FileDescriptorSet, FieldDescriptorProto, DescriptorProto, EnumDescriptorProto, FileDescriptorProto use crate::proto_gen::google::protobuf::descriptor::{
CodeGeneratorRequest, CodeGeneratorResponse, FileDescriptorSet, ResponseFile, DescriptorProto, EnumDescriptorProto, FileDescriptorProto, FieldDescriptorProto
}; };
use crate::google::protobuf::compiler::plugin::{CodeGeneratorRequest, CodeGeneratorResponse};
use crate::{ProtoAccessor, Result, RotoError}; use crate::{ProtoAccessor, Result, RotoError};
use std::str; use std::str;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
+1 -1
View File
@@ -1,6 +1,6 @@
pub mod proto_gen; pub mod proto_gen;
pub mod generator; pub mod generator;
pub mod google; // pub mod google;
// Uncomment this to check if the code compiles // Uncomment this to check if the code compiles
// #[path = "../proto/google/protobuf/descriptor.rs"] // #[path = "../proto/google/protobuf/descriptor.rs"]
// pub mod descriptor; // pub mod descriptor;
+44
View File
@@ -0,0 +1,44 @@
use roto::generator::generate_rust_code;
use roto::proto_gen::google::protobuf::descriptor::FileDescriptorSet;
use std::fs;
#[test]
fn test_nested_proto_generation_contains_modules() {
let request_path = "data/request.bin";
if !std::path::Path::new(request_path).exists() {
panic!("data/request.bin not found. This test requires the sample request binary.");
}
let data = fs::read(request_path).expect("Failed to read request.bin");
// The existing test logic to build a FileDescriptorSet from CodeGeneratorRequest
// We can simplify this by just wrapping the data if it's already a FileDescriptorSet,
// but request.bin is usually a CodeGeneratorRequest.
// Let's use the same logic as build_generated_code.rs to get a FileDescriptorSet
let request = roto::proto_gen::google::protobuf::compiler::plugin::CodeGeneratorRequest::new(&data)
.expect("Failed to parse CodeGeneratorRequest");
let mut set_buf = Vec::new();
for file_res in request.proto_file() {
let (file_data, _) = file_res.expect("Failed to iterate proto_file");
set_buf.push(10);
let len = file_data.len() as u64;
let mut len_buf = [0u8; 10];
let len_size = roto::write_varint(len, &mut len_buf).expect("Failed to write varint length");
set_buf.extend_from_slice(&len_buf[..len_size]);
set_buf.extend_from_slice(file_data);
}
let set = FileDescriptorSet::new(&set_buf).expect("Failed to create FileDescriptorSet");
let generated_files = generate_rust_code(&set, None, false);
let all_code: String = generated_files.into_iter().map(|(_, content)| content).collect();
println!("Generated Code:\n{}", all_code);
// We want to see if any message has a nested module.
// Since we don't know exactly what's in request.bin, we'll look for ANY 'pub mod' inside the generated code
// that isn't at the top level (though the generator puts them inside the message definition).
assert!(all_code.contains("pub mod "), "Generated code should contain at least one nested module for nested types");
assert!(all_code.contains("pub struct "), "Generated code should contain structs");
}