Add 'eval' command to evaluate target aiken function
Pretty useful for debbugging. Though, on second-thoughts, this is something we may want to review later and maybe have that done by default for tests. At the moment, we expects tests to unify to `bool`, and treat `false` values as failing tests. Yet, on failures, this gives little information about what's wrong with the test. It'd be nice to either have better way to assert in tests, or, to simply accept non-bool tests, and show whatever the test evaluates to as a debug output.
This commit is contained in:
27
crates/cli/src/cmd/eval.rs
Normal file
27
crates/cli/src/cmd/eval.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use aiken_project::options::{CodeGenMode, Options};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(clap::Args)]
|
||||
/// Evaluate a chosen function with no argument.
|
||||
pub struct Args {
|
||||
/// Path to project
|
||||
#[clap(short, long)]
|
||||
directory: Option<PathBuf>,
|
||||
|
||||
/// Evaluate the given function
|
||||
#[clap(short, long)]
|
||||
function_name: String,
|
||||
}
|
||||
|
||||
pub fn exec(
|
||||
Args {
|
||||
directory,
|
||||
function_name,
|
||||
}: Args,
|
||||
) -> miette::Result<()> {
|
||||
crate::with_project(directory, |p| {
|
||||
p.compile(Options {
|
||||
code_gen_mode: CodeGenMode::Eval(function_name.clone()),
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod build;
|
||||
pub mod check;
|
||||
pub mod error;
|
||||
pub mod eval;
|
||||
pub mod fmt;
|
||||
pub mod lsp;
|
||||
pub mod new;
|
||||
|
||||
Reference in New Issue
Block a user