Skip to content

Commit

Permalink
feat(nargo): add test to example noir program (#1039)
Browse files Browse the repository at this point in the history
* feat(nargo): add test to example noir program

* fix(nargo): insert correct compiler version in manifest
  • Loading branch information
TomAFrench authored Mar 27, 2023
1 parent 5a66dec commit f994c4f
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions crates/nargo/src/cli/new_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +18,27 @@ pub(crate) struct NewCommand {
path: Option<PathBuf>,
}

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);

Expand All @@ -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());
Expand Down

0 comments on commit f994c4f

Please sign in to comment.