diff --git a/crates/nargo/src/cli/new_cmd.rs b/crates/nargo/src/cli/new_cmd.rs index 20f3187cdd0..9d39f8d1d83 100644 --- a/crates/nargo/src/cli/new_cmd.rs +++ b/crates/nargo/src/cli/new_cmd.rs @@ -4,8 +4,9 @@ use crate::{ }; use super::fs::{create_named_dir, write_to_file}; -use super::NargoConfig; +use super::{NargoConfig, CARGO_PKG_VERSION}; use clap::Args; +use const_format::formatcp; use std::path::{Path, PathBuf}; /// Create a new binary project @@ -17,6 +18,27 @@ pub(crate) struct NewCommand { path: Option, } +const SETTINGS: &str = formatcp!( + r#"[package] +authors = [""] +compiler_version = "{CARGO_PKG_VERSION}" + +[dependencies]"#, +); + +const EXAMPLE: &str = r#"fn main(x : Field, y : pub Field) { + constrain x != y; +} + +#[test] +fn test_main() { + main(1, 2); + + // Uncomment to make test fail + // main(1, 1); +} +"#; + pub(crate) fn run(args: NewCommand, config: NargoConfig) -> Result<(), CliError> { let package_dir = config.program_dir.join(args.package_name); @@ -27,17 +49,6 @@ pub(crate) fn run(args: NewCommand, config: NargoConfig) -> Result<(), CliError> let src_dir = package_dir.join(Path::new(SRC_DIR)); create_named_dir(&src_dir, "src"); - const EXAMPLE: &str = - concat!("fn main(x : Field, y : pub Field) {\n", " constrain x != y;\n", "}"); - - const SETTINGS: &str = concat!( - "[package]\n", - "authors = [\"\"]\n", - "compiler_version = \"0.1\"\n", - "\n", - "[dependencies]" - ); - write_to_file(SETTINGS.as_bytes(), &package_dir.join(PKG_FILE)); write_to_file(EXAMPLE.as_bytes(), &src_dir.join("main.nr")); println!("Project successfully created! Binary located at {}", package_dir.display());