all tests pass except parser

This commit is contained in:
collin 2022-02-07 17:30:41 -05:00
parent 9cd774d38f
commit 341af23af0

View File

@ -232,197 +232,197 @@ fn handle_error<T>(res: Result<T>) -> T {
}
}
}
#[cfg(test)]
mod cli_tests {
use crate::{run_with_args, Opt};
use leo_errors::{CliError, Result};
use snarkvm_utilities::Write;
use std::path::PathBuf;
use structopt::StructOpt;
use test_dir::{DirBuilder, FileType, TestDir};
// Runs Command from cmd-like argument "leo run --arg1 --arg2".
fn run_cmd(args: &str, path: &Option<PathBuf>) -> Result<()> {
let args = args.split(' ').collect::<Vec<&str>>();
let mut opts = Opt::from_iter_safe(args).map_err(CliError::opt_args_error)?;
if path.is_some() {
opts.path = path.clone();
}
if !opts.debug {
// turn off tracing for all tests
opts.quiet = true;
}
run_with_args(opts)
}
// Create a test directory with name.
fn testdir(name: &str) -> TestDir {
TestDir::temp().create(name, FileType::Dir)
}
#[test]
fn global_options() {
let path = Some(PathBuf::from("examples/pedersen-hash"));
assert!(run_cmd("leo build", &path).is_ok());
assert!(run_cmd("leo -q build", &path).is_ok());
}
#[test]
fn global_options_fail() {
assert!(run_cmd("leo --path ../../examples/no-directory-there build", &None).is_err());
assert!(run_cmd("leo -v build", &None).is_err());
}
#[test]
fn init() {
let dir = testdir("test");
let path = Some(dir.path("test"));
assert!(run_cmd("leo init", &path).is_ok());
assert!(run_cmd("leo init", &path).is_err()); // 2nd time
}
#[test]
fn init_fail() {
let dir = testdir("incorrect_name");
let path = Some(dir.path("incorrect_name"));
let fake = Some(PathBuf::from("no_such_directory"));
assert!(run_cmd("leo init", &fake).is_err());
assert!(run_cmd("leo init", &path).is_err());
}
#[test]
fn new() {
let dir = testdir("new");
let path = Some(dir.path("new"));
assert!(run_cmd("leo new test", &path).is_ok());
assert!(run_cmd("leo new test", &path).is_err()); // 2nd time
assert!(run_cmd("leo new wrong_name", &path).is_err());
}
#[test]
#[should_panic]
fn unimplemented() {
assert!(run_cmd("leo lint", &None).is_err());
assert!(run_cmd("leo deploy", &None).is_err());
}
#[test]
fn clean() {
let path = &Some(PathBuf::from("examples/pedersen-hash"));
assert!(run_cmd("leo build", path).is_ok());
assert!(run_cmd("leo clean", path).is_ok());
}
#[test]
fn build_optimizations() {
let dir = testdir("build-test");
let path = dir.path("build-test");
assert!(run_cmd("leo new setup-test", &Some(path.clone())).is_ok());
let build_path = &Some(path.join("setup-test"));
assert!(run_cmd("leo build --disable-all-optimizations", build_path).is_ok());
assert!(run_cmd("leo build --disable-code-elimination", build_path).is_ok());
assert!(run_cmd("leo build --disable-constant-folding", build_path).is_ok());
}
#[test]
fn setup_prove_run_clean() {
let dir = testdir("test");
let path = dir.path("test");
assert!(run_cmd("leo new setup-test", &Some(path.clone())).is_ok());
let setup_path = &Some(path.join("setup-test"));
assert!(run_cmd("leo setup", setup_path).is_ok());
assert!(run_cmd("leo setup", setup_path).is_ok());
assert!(run_cmd("leo setup --skip-key-check", setup_path).is_ok());
assert!(run_cmd("leo prove --skip-key-check", setup_path).is_ok());
assert!(run_cmd("leo run --skip-key-check", setup_path).is_ok());
assert!(run_cmd("leo clean", setup_path).is_ok());
}
#[test]
#[ignore]
fn test_import() {
let dir = testdir("test");
let path = dir.path("test");
assert!(run_cmd("leo new import", &Some(path.clone())).is_ok());
let import_path = &Some(path.join("import"));
assert!(run_cmd("leo add no-package/definitely-no", import_path).is_err());
assert!(run_cmd("leo add justice-league/u8u32", import_path).is_ok());
assert!(run_cmd("leo remove u8u32", import_path).is_ok());
assert!(run_cmd("leo add --author justice-league --package u8u32", import_path).is_ok());
assert!(run_cmd("leo remove u8u32", import_path).is_ok());
assert!(run_cmd("leo remove u8u32", import_path).is_err());
}
#[test]
fn test_missing_file() {
let dir = testdir("test");
let path = dir.path("test");
assert!(run_cmd("leo new test-file-missing", &Some(path.clone())).is_ok());
let path = path.join("test-file-missing");
let file = path.join("src/main.leo");
let path = Some(path);
assert!(run_cmd("leo test", &path).is_ok());
std::fs::remove_file(&file).unwrap();
assert!(run_cmd("leo test", &path).is_err());
}
#[test]
fn test_sudoku() {
let path = &Some(PathBuf::from("examples/silly-sudoku"));
assert!(run_cmd("leo build", path).is_ok());
assert!(run_cmd("leo test", path).is_ok());
assert!(run_cmd("leo test -f examples/silly-sudoku/src/lib.leo", path).is_ok());
assert!(run_cmd("leo test -f examples/silly-sudoku/src/main.leo", path).is_ok());
}
#[test]
fn test_install() {
let dir = testdir("test");
let path = dir.path("test");
assert!(run_cmd("leo new install", &Some(path.clone())).is_ok());
let install_path = &Some(path.join("install"));
let mut file = std::fs::OpenOptions::new()
.write(true)
.append(true)
.open(path.join("install/Leo.toml"))
.unwrap();
assert!(run_cmd("leo fetch", install_path).is_ok());
assert!(file
.write_all(
br#"
sudoku = {author = "justice-league", package = "u8u32", version = "0.1.0"}
"#
)
.is_ok());
assert!(run_cmd("leo fetch", install_path).is_ok());
assert!(run_cmd("leo build", install_path).is_ok());
}
}
// todo (collin): uncomment after refactor
// #[cfg(test)]
// mod cli_tests {
// use crate::{run_with_args, Opt};
// use leo_errors::{CliError, Result};
//
// use snarkvm_utilities::Write;
// use std::path::PathBuf;
// use structopt::StructOpt;
// use test_dir::{DirBuilder, FileType, TestDir};
//
// // Runs Command from cmd-like argument "leo run --arg1 --arg2".
// fn run_cmd(args: &str, path: &Option<PathBuf>) -> Result<()> {
// let args = args.split(' ').collect::<Vec<&str>>();
// let mut opts = Opt::from_iter_safe(args).map_err(CliError::opt_args_error)?;
//
// if path.is_some() {
// opts.path = path.clone();
// }
//
// if !opts.debug {
// // turn off tracing for all tests
// opts.quiet = true;
// }
//
// run_with_args(opts)
// }
//
// // Create a test directory with name.
// fn testdir(name: &str) -> TestDir {
// TestDir::temp().create(name, FileType::Dir)
// }
//
// #[test]
// fn global_options() {
// let path = Some(PathBuf::from("examples/pedersen-hash"));
//
// assert!(run_cmd("leo build", &path).is_ok());
// assert!(run_cmd("leo -q build", &path).is_ok());
// }
//
// #[test]
// fn global_options_fail() {
// assert!(run_cmd("leo --path ../../examples/no-directory-there build", &None).is_err());
// assert!(run_cmd("leo -v build", &None).is_err());
// }
//
// #[test]
// fn init() {
// let dir = testdir("test");
// let path = Some(dir.path("test"));
//
// assert!(run_cmd("leo init", &path).is_ok());
// assert!(run_cmd("leo init", &path).is_err()); // 2nd time
// }
//
// #[test]
// fn init_fail() {
// let dir = testdir("incorrect_name");
// let path = Some(dir.path("incorrect_name"));
// let fake = Some(PathBuf::from("no_such_directory"));
//
// assert!(run_cmd("leo init", &fake).is_err());
// assert!(run_cmd("leo init", &path).is_err());
// }
//
// #[test]
// fn new() {
// let dir = testdir("new");
// let path = Some(dir.path("new"));
//
// assert!(run_cmd("leo new test", &path).is_ok());
// assert!(run_cmd("leo new test", &path).is_err()); // 2nd time
// assert!(run_cmd("leo new wrong_name", &path).is_err());
// }
//
// #[test]
// #[should_panic]
// fn unimplemented() {
// assert!(run_cmd("leo lint", &None).is_err());
// assert!(run_cmd("leo deploy", &None).is_err());
// }
//
// #[test]
// fn clean() {
// let path = &Some(PathBuf::from("examples/pedersen-hash"));
//
// assert!(run_cmd("leo build", path).is_ok());
// assert!(run_cmd("leo clean", path).is_ok());
// }
//
// #[test]
// fn build_optimizations() {
// let dir = testdir("build-test");
// let path = dir.path("build-test");
//
// assert!(run_cmd("leo new setup-test", &Some(path.clone())).is_ok());
//
// let build_path = &Some(path.join("setup-test"));
//
// assert!(run_cmd("leo build --disable-all-optimizations", build_path).is_ok());
// assert!(run_cmd("leo build --disable-code-elimination", build_path).is_ok());
// assert!(run_cmd("leo build --disable-constant-folding", build_path).is_ok());
// }
//
// #[test]
// fn setup_prove_run_clean() {
// let dir = testdir("test");
// let path = dir.path("test");
//
// assert!(run_cmd("leo new setup-test", &Some(path.clone())).is_ok());
//
// let setup_path = &Some(path.join("setup-test"));
//
// assert!(run_cmd("leo setup", setup_path).is_ok());
// assert!(run_cmd("leo setup", setup_path).is_ok());
// assert!(run_cmd("leo setup --skip-key-check", setup_path).is_ok());
// assert!(run_cmd("leo prove --skip-key-check", setup_path).is_ok());
// assert!(run_cmd("leo run --skip-key-check", setup_path).is_ok());
// assert!(run_cmd("leo clean", setup_path).is_ok());
// }
//
// #[test]
// #[ignore]
// fn test_import() {
// let dir = testdir("test");
// let path = dir.path("test");
//
// assert!(run_cmd("leo new import", &Some(path.clone())).is_ok());
//
// let import_path = &Some(path.join("import"));
//
// assert!(run_cmd("leo add no-package/definitely-no", import_path).is_err());
// assert!(run_cmd("leo add justice-league/u8u32", import_path).is_ok());
// assert!(run_cmd("leo remove u8u32", import_path).is_ok());
// assert!(run_cmd("leo add --author justice-league --package u8u32", import_path).is_ok());
// assert!(run_cmd("leo remove u8u32", import_path).is_ok());
// assert!(run_cmd("leo remove u8u32", import_path).is_err());
// }
//
// #[test]
// fn test_missing_file() {
// let dir = testdir("test");
// let path = dir.path("test");
//
// assert!(run_cmd("leo new test-file-missing", &Some(path.clone())).is_ok());
//
// let path = path.join("test-file-missing");
// let file = path.join("src/main.leo");
// let path = Some(path);
//
// assert!(run_cmd("leo test", &path).is_ok());
// std::fs::remove_file(&file).unwrap();
// assert!(run_cmd("leo test", &path).is_err());
// }
//
// #[test]
// fn test_sudoku() {
// let path = &Some(PathBuf::from("examples/silly-sudoku"));
//
// assert!(run_cmd("leo build", path).is_ok());
// assert!(run_cmd("leo test", path).is_ok());
// assert!(run_cmd("leo test -f examples/silly-sudoku/src/lib.leo", path).is_ok());
// assert!(run_cmd("leo test -f examples/silly-sudoku/src/main.leo", path).is_ok());
// }
//
// #[test]
// fn test_install() {
// let dir = testdir("test");
// let path = dir.path("test");
//
// assert!(run_cmd("leo new install", &Some(path.clone())).is_ok());
//
// let install_path = &Some(path.join("install"));
//
// let mut file = std::fs::OpenOptions::new()
// .write(true)
// .append(true)
// .open(path.join("install/Leo.toml"))
// .unwrap();
//
// assert!(run_cmd("leo fetch", install_path).is_ok());
// assert!(file
// .write_all(
// br#"
// sudoku = {author = "justice-league", package = "u8u32", version = "0.1.0"}
// "#
// )
// .is_ok());
//
// assert!(run_cmd("leo fetch", install_path).is_ok());
// assert!(run_cmd("leo build", install_path).is_ok());
// }
// }