Skip to content

Commit

Permalink
Merge pull request #3 from CloudCannon/feta/run-one
Browse files Browse the repository at this point in the history
Add arguments to the CLI to run a specific test
  • Loading branch information
bglw authored Sep 27, 2024
2 parents 9292beb + aa52368 commit afa8079
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

## Unreleased

* Adds `-n <name>` / `--name <name>` arguments to the CLI to run a specific test

## v0.3.0 (August 16, 2024)

* Adds platform flags for tests and individual steps
Expand Down
8 changes: 8 additions & 0 deletions test_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR

TOOLPROOF=$(realpath "$SCRIPT_DIR/target/$1/toolproof")

cargo run --release -- --placeholders toolproof_path="$TOOLPROOF" -c 1
9 changes: 8 additions & 1 deletion toolproof/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,14 @@ async fn main_inner() -> Result<(), ()> {
ctx,
});

let run_mode = if universe.ctx.params.interactive && !universe.ctx.params.all {
let run_mode = if let Some(run_name) = universe.ctx.params.run_name.as_ref() {
let Some((path, _)) = universe.tests.iter().find(|(_, t)| t.name == *run_name) else {
eprintln!("Test name {run_name} does not exist");
return Err(());
};

RunMode::One(path.clone())
} else if universe.ctx.params.interactive && !universe.ctx.params.all {
match get_run_mode(&universe) {
Ok(mode) => mode,
Err(e) => {
Expand Down
14 changes: 14 additions & 0 deletions toolproof/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ fn get_cli_matches() -> ArgMatches {
)
.action(clap::ArgAction::SetTrue),
)
.arg(
arg!(
-n --name <NAME> "Exact name of a test to run")
.long_help("case-sensitive")
.required(false)
)
.arg(
arg!(
--browser <IMPL> ... "Specify which browser to use when running browser automation tests"
Expand Down Expand Up @@ -145,6 +151,10 @@ pub struct ToolproofParams {
/// Run all tests when in interactive mode
pub all: bool,

/// Run a specific test
#[setting(env = "TOOLPROOF_RUN_NAME")]
pub run_name: Option<String>,

/// Specify which browser to use when running browser automation tests
#[setting(env = "TOOLPROOF_BROWSER")]
pub browser: ToolproofBrowserImpl,
Expand Down Expand Up @@ -205,6 +215,10 @@ impl ToolproofParams {
self.all = true;
}

if let Some(name) = cli_matches.get_one::<String>("name") {
self.run_name = Some(name.clone());
}

if let Some(root) = cli_matches.get_one::<PathBuf>("root") {
self.root = Some(root.clone());
}
Expand Down
29 changes: 29 additions & 0 deletions toolproof/test_suite/base/run_one.toolproof.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run a single toolproof test

steps:
- step: I have a "my_test_a.toolproof.yml" file with the content {yaml}
yaml: |-
name: Inner test A
steps:
- I run 'echo "toolproof πŸ™‚"'
- stdout should contain "πŸ™‚"
- step: I have a "my_test_b.toolproof.yml" file with the content {yaml}
yaml: |-
name: Inner test B
steps:
- I run 'echo "toolproof πŸ™"'
- stdout should contain "πŸ™‚"
- I run "%toolproof_path% -n 'Inner test A'"
- step: "stdout should contain 'Passing tests: 1'"
- step: "stdout should contain 'Failing tests: 0'"
- step: "stdout should contain 'Skipped tests: 0'"
- step: "stdout should contain 'All tests passed'"
- stderr should be empty
- I run "%toolproof_path% -n 'Inner test B'" and expect it to fail
- step: "stdout should contain 'Passing tests: 0'"
- step: "stdout should contain 'Failing tests: 1'"
- step: "stdout should contain 'Skipped tests: 0'"
- step: "stdout should contain 'Some tests failed'"
- stderr should be empty

0 comments on commit afa8079

Please sign in to comment.