Skip to content

Commit

Permalink
chore: use git tag for the new project template in cargo-miden
Browse files Browse the repository at this point in the history
QoL improvements to the new project template test: select the
local path to the template in test.
  • Loading branch information
greenhat committed Jul 26, 2024
1 parent fcac669 commit eb4a3a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions tools/cargo-miden/src/new_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
Expand Down
26 changes: 23 additions & 3 deletions tools/cargo-miden/tests/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use std::{env, fs};
use std::{env, fs, vec};

use cargo_component_core::terminal;
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<String> {
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.
Expand All @@ -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());
Expand Down

0 comments on commit eb4a3a3

Please sign in to comment.