Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nargo): add test to example noir program #1039

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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