Skip to content

Commit

Permalink
Comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ksew1 committed Jul 23, 2024
1 parent 655adbf commit 3eb4cf5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion scarb/src/bin/scarb/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub struct ScriptsRunnerArgs {
#[derive(ValueEnum, Clone, Debug)]
pub enum TestRunner {
StarknetFoundry,
CairoNativeRunner,
CairoTest,
}

/// Arguments accepted by the `init` command.
Expand Down
10 changes: 9 additions & 1 deletion scarb/src/bin/scarb/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use scarb::core::Config;
use scarb::ops::{self, VersionControl};

use crate::args::{InitArgs, TestRunner};
use crate::interactive::ask_for_test_runner;

#[tracing::instrument(skip_all, level = "info")]
pub fn run(args: InitArgs, config: &Config) -> Result<()> {
Expand All @@ -24,7 +25,14 @@ pub fn run(args: InitArgs, config: &Config) -> Result<()> {
} else {
VersionControl::Git
},
snforge: matches!(args.test_runner, Some(TestRunner::StarknetFoundry)),
snforge: matches!(
if let Some(test_runner) = args.test_runner {
test_runner
} else {
ask_for_test_runner()?
},
TestRunner::StarknetFoundry
),
},
config,
)?;
Expand Down
10 changes: 9 additions & 1 deletion scarb/src/bin/scarb/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use scarb::core::Config;
use scarb::ops::{self, VersionControl};

use crate::args::{NewArgs, TestRunner};
use crate::interactive::ask_for_test_runner;

#[tracing::instrument(skip_all, level = "info")]
pub fn run(args: NewArgs, config: &Config) -> Result<()> {
Expand All @@ -18,7 +19,14 @@ pub fn run(args: NewArgs, config: &Config) -> Result<()> {
} else {
VersionControl::Git
},
snforge: matches!(args.init.test_runner, Some(TestRunner::StarknetFoundry)),
snforge: matches!(
if let Some(test_runner) = args.init.test_runner {
test_runner
} else {
ask_for_test_runner()?
},
TestRunner::StarknetFoundry
),
},
config,
)?;
Expand Down
28 changes: 6 additions & 22 deletions scarb/src/bin/scarb/interactive.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
use crate::args::{Command, TestRunner};
use crate::args::TestRunner;
use anyhow::Result;
use inquire::Select;
use which::which;

pub fn resolve_command(command: &Command) -> Result<Command> {
let mut command = command.clone();
match &mut command {
Command::Init(args) if args.test_runner.is_none() => {
let test_runner = ask_for_test_runner()?;
args.test_runner = Some(test_runner);
}
Command::New(args) if args.init.test_runner.is_none() => {
let test_runner = ask_for_test_runner()?;
args.init.test_runner = Some(test_runner);
}
_ => {}
}
Ok(command)
}

fn ask_for_test_runner() -> Result<TestRunner> {
pub fn ask_for_test_runner() -> Result<TestRunner> {
let options = if which("snforge").is_ok() {
vec!["Starknet Foundry (default)", "Cairo Native runner"]
vec!["Starknet Foundry (default)", "Cairo Test"]
} else {
vec![
"Cairo Native runner (default)",
"Cairo Test (default)",
"Starknet Foundry (recommended, requires snforge installed)",
]
};

let answer = Select::new("Which test runner do you want to set up?", options).prompt()?;

if answer.starts_with("Cairo Native") {
Ok(TestRunner::CairoNativeRunner)
if answer.starts_with("Cairo Test") {
Ok(TestRunner::CairoTest)
} else {
Ok(TestRunner::StarknetFoundry)
}
Expand Down
3 changes: 1 addition & 2 deletions scarb/src/bin/scarb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use scarb::ops;
use scarb_ui::Ui;

use crate::errors::ErrorWithExitCode;
use crate::interactive::resolve_command;

mod args;
mod commands;
Expand Down Expand Up @@ -79,5 +78,5 @@ fn cli_main(args: ScarbArgs) -> Result<()> {
.profile(args.profile_spec.determine()?)
.build()?;

commands::run(resolve_command(&args.command)?, &mut config)
commands::run(args.command, &mut config)
}
4 changes: 1 addition & 3 deletions scarb/tests/new_and_init.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::fs;

use assert_fs::prelude::*;
use indoc::indoc;
use predicates::prelude::*;
Expand All @@ -9,7 +7,7 @@ use scarb::core::TomlManifest;
use scarb_test_support::command::Scarb;
use scarb_test_support::fsx::AssertFsUtf8Ext;

const CAIRO_NATIVE_RUNNER: [&str; 2] = ["--test-runner", "cairo-native-runner"];
const CAIRO_NATIVE_RUNNER: [&str; 2] = ["--test-runner", "cairo-test"];

#[test]
fn new_simple() {
Expand Down
2 changes: 1 addition & 1 deletion scarb/tests/snforge_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn new_simple() {
Scarb::quick_snapbox()
.arg("new")
.arg("hello")
.arg("--snforge")
.args(["--test-runner", "starknet-foundry"])
.current_dir(&pt)
.assert()
.success();
Expand Down

0 comments on commit 3eb4cf5

Please sign in to comment.