From eb4a3a3594568d1ac960510ffa33b5864ad34761 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Tue, 23 Jul 2024 18:53:38 +0300 Subject: [PATCH 1/2] chore: use git tag for the new project template in cargo-miden QoL improvements to the new project template test: select the local path to the template in test. --- tools/cargo-miden/src/new_project.rs | 1 + tools/cargo-miden/tests/build.rs | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/cargo-miden/src/new_project.rs b/tools/cargo-miden/src/new_project.rs index ad4625555..fbf865fb0 100644 --- a/tools/cargo-miden/src/new_project.rs +++ b/tools/cargo-miden/src/new_project.rs @@ -74,6 +74,7 @@ impl NewCommand { }, None => TemplatePath { git: Some("https://github.com/0xPolygonMiden/rust-templates".into()), + tag: Some("v0.2.0".into()), auto_path: Some("account".into()), ..Default::default() }, diff --git a/tools/cargo-miden/tests/build.rs b/tools/cargo-miden/tests/build.rs index 48edc029b..71d51de88 100644 --- a/tools/cargo-miden/tests/build.rs +++ b/tools/cargo-miden/tests/build.rs @@ -1,4 +1,4 @@ -use std::{env, fs}; +use std::{env, fs, vec}; use cargo_component_core::terminal; use cargo_miden::run; @@ -6,6 +6,14 @@ use cargo_miden::run; // NOTE: This test sets the current working directory so don't run it in parallel with tests // that depend on the current directory +fn new_project_args(project_name: &str, template_path: Option<&str>) -> Vec { + let mut args = vec!["cargo", "miden", "new", project_name]; + if let Some(template_path) = template_path { + args.extend(["--template-path", template_path]); + }; + args.into_iter().map(|s| s.to_string()).collect() +} + #[test] fn build_new_project_from_template() { // Signal to `cargo-miden` that we're running in a test harness. @@ -19,12 +27,24 @@ fn build_new_project_from_template() { env::set_current_dir(&temp_dir).unwrap(); let project_name = "test-proj"; let expected_new_project_dir = &temp_dir.join(project_name); + dbg!(&expected_new_project_dir); if expected_new_project_dir.exists() { fs::remove_dir_all(expected_new_project_dir).unwrap(); } - let args = ["cargo", "miden", "new", project_name].into_iter().map(|s| s.to_string()); + + let args = new_project_args(project_name, None); + // let args = new_project_args( + // project_name, + // Some( + // &(format!( + // "{}/../../../rust-templates/account", + // std::env::var("CARGO_MANIFEST_DIR").unwrap() + // )), + // ), + // ); + let terminal = terminal::Terminal::new(terminal::Verbosity::Verbose, terminal::Color::Auto); - let outputs = run(args, &terminal).expect("Failed to create new project"); + let outputs = run(args.into_iter(), &terminal).expect("Failed to create new project"); let new_project_path = outputs.first().unwrap().canonicalize().unwrap(); dbg!(&new_project_path); assert!(new_project_path.exists()); From 0e82c141c0fb980e51ff5757e65128454d67166e Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Wed, 24 Jul 2024 10:47:54 +0300 Subject: [PATCH 2/2] fix(cargo-miden): force new project name to not be kebab-cased --- tools/cargo-miden/src/new_project.rs | 21 ++++++++++++--------- tools/cargo-miden/tests/build.rs | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/cargo-miden/src/new_project.rs b/tools/cargo-miden/src/new_project.rs index fbf865fb0..6fc533ce8 100644 --- a/tools/cargo-miden/src/new_project.rs +++ b/tools/cargo-miden/src/new_project.rs @@ -80,18 +80,21 @@ impl NewCommand { }, }; + let destination = self + .path + .parent() + .map(|p| { + use path_absolutize::Absolutize; + p.absolutize().map(|p| p.to_path_buf()) + }) + .transpose() + .context("Failed to convert destination path to an absolute path")?; let generate_args = GenerateArgs { template_path, - destination: self - .path - .parent() - .map(|p| { - use path_absolutize::Absolutize; - p.absolutize().map(|p| p.to_path_buf()) - }) - .transpose() - .context("Failed to convert destination path to an absolute path")?, + destination, name: Some(name), + // Force the `name` to not be kebab-cased + force: true, force_git_init: true, verbose: true, define, diff --git a/tools/cargo-miden/tests/build.rs b/tools/cargo-miden/tests/build.rs index 71d51de88..a0a780308 100644 --- a/tools/cargo-miden/tests/build.rs +++ b/tools/cargo-miden/tests/build.rs @@ -25,7 +25,7 @@ fn build_new_project_from_template() { let restore_dir = env::current_dir().unwrap(); let temp_dir = env::temp_dir(); env::set_current_dir(&temp_dir).unwrap(); - let project_name = "test-proj"; + let project_name = "test_proj_underscore"; let expected_new_project_dir = &temp_dir.join(project_name); dbg!(&expected_new_project_dir); if expected_new_project_dir.exists() {