Skip to content

Commit

Permalink
Add env variable for test-runner flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ksew1 committed Jul 26, 2024
1 parent 3eb4cf5 commit c44da4b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
1 change: 1 addition & 0 deletions scarb-metadata/tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fn manifest_path() {
fn init_project(t: &TempDir) {
Command::new(scarb_bin())
.args(["init", "--name", "hello"])
.env("SCARB_TEST_RUNNER", "cairo-test")
.current_dir(t)
.assert()
.success();
Expand Down
1 change: 1 addition & 0 deletions scarb-metadata/tests/scarb_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn sample_project() {
fn init_project(t: &TempDir) {
Command::new(scarb_bin())
.args(["init", "--name", "hello"])
.env("SCARB_TEST_RUNNER", "cairo-test")
.current_dir(t)
.assert()
.success();
Expand Down
2 changes: 1 addition & 1 deletion scarb/src/bin/scarb/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub struct InitArgs {
pub no_vcs: bool,

/// Test runner to use. Starts interactive session if not specified.
#[arg(long)]
#[arg(long, env = "SCARB_TEST_RUNNER")]
pub test_runner: Option<TestRunner>,
}

Expand Down
8 changes: 3 additions & 5 deletions scarb/src/bin/scarb/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ pub fn run(args: InitArgs, config: &Config) -> Result<()> {
VersionControl::Git
},
snforge: matches!(
if let Some(test_runner) = args.test_runner {
test_runner
} else {
ask_for_test_runner()?
},
Ok(args.test_runner)
.transpose()
.unwrap_or_else(ask_for_test_runner)?,
TestRunner::StarknetFoundry
),
},
Expand Down
8 changes: 3 additions & 5 deletions scarb/src/bin/scarb/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ pub fn run(args: NewArgs, config: &Config) -> Result<()> {
VersionControl::Git
},
snforge: matches!(
if let Some(test_runner) = args.init.test_runner {
test_runner
} else {
ask_for_test_runner()?
},
Ok(args.init.test_runner)
.transpose()
.unwrap_or_else(ask_for_test_runner)?,
TestRunner::StarknetFoundry
),
},
Expand Down
2 changes: 1 addition & 1 deletion scarb/src/bin/scarb/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn ask_for_test_runner() -> Result<TestRunner> {
} else {
vec![
"Cairo Test (default)",
"Starknet Foundry (recommended, requires snforge installed)",
"Starknet Foundry (recommended, requires snforge installed: https://github.com/foundry-rs/starknet-foundry)",
]
};

Expand Down
23 changes: 12 additions & 11 deletions website/docs/writing-extensions/subcommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ Any additional arguments on the command line after `${command}` will be forwarde

Additionally, Scarb passes more contextual information via environment variables:

| Environment variable | Description |
| --------------------- | ------------------------------------------------------------------------------------------ |
| `SCARB` | Path to Scarb executable. |
| `PATH` | System `$PATH` but augmented with `bin` directory in Scarb's [local data directory][dirs]. |
| `SCARB_CACHE` | Path to Scarb's [cache][dirs] directory. |
| `SCARB_CONFIG` | Path to Scarb's [config][dirs] directory. |
| `SCARB_TARGET_DIR` | Path to the current target directory. |
| `SCARB_PROFILE` | Name of the current profile. |
| `SCARB_MANIFEST_PATH` | Absolute path to current `Scarb.toml`. |
| `SCARB_UI_VERBOSITY` | Scarb's messages verbosity, possible values: `quiet`, `normal`, `verbose`. |
| `SCARB_LOG` | Scarb's logger directives, follows [`tracing`'s `EnvFilter` syntax][tracing-env-filter]. |
| Environment variable | Description |
|-----------------------|-----------------------------------------------------------------------------------------------------|
| `SCARB` | Path to Scarb executable. |
| `PATH` | System `$PATH` but augmented with `bin` directory in Scarb's [local data directory][dirs]. |
| `SCARB_CACHE` | Path to Scarb's [cache][dirs] directory. |
| `SCARB_CONFIG` | Path to Scarb's [config][dirs] directory. |
| `SCARB_TARGET_DIR` | Path to the current target directory. |
| `SCARB_PROFILE` | Name of the current profile. |
| `SCARB_MANIFEST_PATH` | Absolute path to current `Scarb.toml`. |
| `SCARB_UI_VERBOSITY` | Scarb's messages verbosity, possible values: `quiet`, `normal`, `verbose`. |
| `SCARB_LOG` | Scarb's logger directives, follows [`tracing`'s `EnvFilter` syntax][tracing-env-filter]. |
| `SCARB_TEST_RUNNER` | Test runner to use when calling `new` or `init`. possible values: `starknet-foundry`, `cairo-test`. |

## Implementation recommendations

Expand Down

0 comments on commit c44da4b

Please sign in to comment.