Fix path resolution in codegen build tests
Use absolute paths for temporary project directories and dependencies to improve reliability. Update the generated Cargo.toml with additional dependencies and remove the offline flag from cargo build.
This commit is contained in:
@@ -17,8 +17,9 @@ fn test_map_generated_code_builds() {
|
||||
);
|
||||
|
||||
// 2. Setup a temporary Cargo project to verify the code builds
|
||||
let root = std::env::current_dir().expect("Failed to get current directory");
|
||||
let temp_project_dir = root.join("test_map_gen_project");
|
||||
let codegen_root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let project_root = codegen_root.parent().expect("Failed to get project root");
|
||||
let temp_project_dir = std::path::PathBuf::from("/tmp/roto_test_map_gen_project");
|
||||
|
||||
// Clean up previous runs
|
||||
if temp_project_dir.exists() {
|
||||
@@ -27,8 +28,7 @@ fn test_map_generated_code_builds() {
|
||||
|
||||
// Create new library project
|
||||
let status = Command::new("cargo")
|
||||
.args(["new", "--lib", "test_map_gen_project"])
|
||||
.current_dir(&root)
|
||||
.args(["new", "--lib", temp_project_dir.to_str().expect("Invalid path")])
|
||||
.status()
|
||||
.expect("Failed to run cargo new");
|
||||
assert!(status.success(), "cargo new failed");
|
||||
@@ -38,8 +38,11 @@ fn test_map_generated_code_builds() {
|
||||
let cargo_toml_content =
|
||||
fs::read_to_string(&cargo_toml_path).expect("Failed to read Cargo.toml");
|
||||
let updated_cargo_toml = format!(
|
||||
"{}\n\nroto-codegen = {{ path = \"..\" }}\nroto-runtime = {{ path = \"../../runtime\" }}\nbytes = \"1.7\"\ntonic = \"0.12\"\ntokio-stream = \"0.1\"\n\n[workspace]\n",
|
||||
cargo_toml_content
|
||||
"{}\n\nroto-codegen = {{ path = \"{}\" }}\nroto-runtime = {{ path = \"{}\" }}\nroto-tonic = {{ path = \"{}\" }}\nbytes = \"1.7\"\ntonic = \"0.12\"\ntokio-stream = \"0.1\"\ntower = \"0.4\"\nfutures-util = \"0.3\"\nhttp-body-util = \"0.1\"\nhttp-body = \"1.0\"\n\n[workspace]\n",
|
||||
cargo_toml_content,
|
||||
codegen_root.to_string_lossy(),
|
||||
project_root.join("runtime").to_string_lossy(),
|
||||
project_root.join("roto-tonic").to_string_lossy()
|
||||
);
|
||||
fs::write(cargo_toml_path, updated_cargo_toml).expect("Failed to write Cargo.toml");
|
||||
|
||||
@@ -55,7 +58,7 @@ fn test_map_generated_code_builds() {
|
||||
|
||||
// 5. Attempt to build the project
|
||||
let build_status = Command::new("cargo")
|
||||
.args(["--offline", "build"])
|
||||
.args(["build"])
|
||||
.current_dir(&temp_project_dir)
|
||||
.status()
|
||||
.expect("Failed to run cargo build");
|
||||
|
||||
@@ -17,8 +17,9 @@ fn test_types_generated_code_builds() {
|
||||
);
|
||||
|
||||
// 2. Setup a temporary Cargo project to verify the code builds
|
||||
let root = std::env::current_dir().expect("Failed to get current directory");
|
||||
let temp_project_dir = root.join("test_types_gen_project");
|
||||
let codegen_root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let project_root = codegen_root.parent().expect("Failed to get project root");
|
||||
let temp_project_dir = std::path::PathBuf::from("/tmp/roto_test_types_gen_project");
|
||||
|
||||
// Clean up previous runs
|
||||
if temp_project_dir.exists() {
|
||||
@@ -27,8 +28,7 @@ fn test_types_generated_code_builds() {
|
||||
|
||||
// Create new library project
|
||||
let status = Command::new("cargo")
|
||||
.args(["new", "--lib", "test_types_gen_project"])
|
||||
.current_dir(&root)
|
||||
.args(["new", "--lib", temp_project_dir.to_str().expect("Invalid path")])
|
||||
.status()
|
||||
.expect("Failed to run cargo new");
|
||||
assert!(status.success(), "cargo new failed");
|
||||
@@ -38,8 +38,11 @@ fn test_types_generated_code_builds() {
|
||||
let cargo_toml_content =
|
||||
fs::read_to_string(&cargo_toml_path).expect("Failed to read Cargo.toml");
|
||||
let updated_cargo_toml = format!(
|
||||
"{}\n\nroto-codegen = {{ path = \"..\" }}\nroto-runtime = {{ path = \"../../runtime\" }}\nbytes = \"1.7\"\ntonic = \"0.12\"\ntokio-stream = \"0.1\"\n\n[workspace]\n",
|
||||
cargo_toml_content
|
||||
"{}\n\nroto-codegen = {{ path = \"{}\" }}\nroto-runtime = {{ path = \"{}\" }}\nroto-tonic = {{ path = \"{}\" }}\nbytes = \"1.7\"\ntonic = \"0.12\"\ntokio-stream = \"0.1\"\ntower = \"0.4\"\nfutures-util = \"0.3\"\nhttp-body-util = \"0.1\"\nhttp-body = \"1.0\"\n\n[workspace]\n",
|
||||
cargo_toml_content,
|
||||
codegen_root.to_string_lossy(),
|
||||
project_root.join("runtime").to_string_lossy(),
|
||||
project_root.join("roto-tonic").to_string_lossy()
|
||||
);
|
||||
fs::write(cargo_toml_path, updated_cargo_toml).expect("Failed to write Cargo.toml");
|
||||
|
||||
@@ -60,7 +63,7 @@ fn test_types_generated_code_builds() {
|
||||
|
||||
// 5. Attempt to build the project
|
||||
let build_status = Command::new("cargo")
|
||||
.args(["--offline", "build"])
|
||||
.args(["build"])
|
||||
.current_dir(&temp_project_dir)
|
||||
.status()
|
||||
.expect("Failed to run cargo build");
|
||||
|
||||
Reference in New Issue
Block a user