Skip to content

Commit

Permalink
Add --test to cargo odra test #48
Browse files Browse the repository at this point in the history
  • Loading branch information
kpob committed Jun 25, 2024
1 parent d3e7a29 commit 13e6680
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/actions/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use crate::{
command::{rename_file, replace_in_file},
consts::{ODRA_TEMPLATE_GH_RAW_REPO, ODRA_TEMPLATE_GH_REPO},
errors::Error,
log, paths,
log,
paths,
project::OdraLocation,
template::TemplateGenerator,
utils::odra_latest_version,
Expand Down
21 changes: 19 additions & 2 deletions src/actions/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct TestAction<'a> {
backend: Option<String>,
passthrough_args: Vec<String>,
skip_build: bool,
test: Option<String>,
}

/// TestAction implementation.
Expand All @@ -17,6 +18,7 @@ impl<'a> TestAction<'a> {
pub fn new(
project: &Project,
backend: Option<String>,
test: Option<String>,
passthrough_args: Vec<String>,
skip_build: bool,
) -> TestAction {
Expand All @@ -25,6 +27,7 @@ impl<'a> TestAction<'a> {
passthrough_args,
skip_build,
project,
test,
}
}
}
Expand All @@ -45,7 +48,7 @@ impl TestAction<'_> {
/// Test code against OdraVM.
fn test_odra_vm(&self) {
log::info("Testing against OdraVM ...");
command::cargo_test_odra_vm(self.project.project_root(), self.get_passthrough_args());
command::cargo_test_odra_vm(self.project.project_root(), self.args());
}

/// Test specific backend.
Expand All @@ -54,7 +57,7 @@ impl TestAction<'_> {
command::cargo_test_backend(
self.project.project_root(),
self.backend_name(),
self.get_passthrough_args(),
self.args(),
);
}

Expand All @@ -68,6 +71,20 @@ impl TestAction<'_> {
self.passthrough_args.iter().map(AsRef::as_ref).collect()
}

/// Returns arguments to be passed to `cargo test` command.
///
/// This includes the test name and passthrough arguments.
fn args(&self) -> Vec<&str> {
[
self.test
.as_ref()
.map(|t| vec![t.as_str()])
.unwrap_or_default(),
self.get_passthrough_args(),
]
.concat()
}

/// Build *.wasm files before testing.
fn build_wasm_files(&self) {
BuildAction::new(self.project, None).build();
Expand Down
12 changes: 11 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ pub struct TestCommand {
/// Skip building wasm files.
#[clap(value_parser, long, short, default_value = "false")]
pub skip_build: bool,
/// Run only tests containing the given name.
#[clap(value_parser, long, short)]
pub test: Option<String>,
}

#[derive(clap::Args, Debug)]
Expand Down Expand Up @@ -170,7 +173,14 @@ pub fn make_action() {
}
OdraSubcommand::Test(test) => {
let project = Project::detect(current_dir);
TestAction::new(&project, test.backend, test.args, test.skip_build).test();
TestAction::new(
&project,
test.backend,
test.test,
test.args,
test.skip_build,
)
.test();
}
OdraSubcommand::Generate(generate) => {
let project = Project::detect(current_dir);
Expand Down

0 comments on commit 13e6680

Please sign in to comment.