Skip to content

Commit

Permalink
Properly use Status message when testing workspace
Browse files Browse the repository at this point in the history
- Status should always be a single verb.
- Print what command is going to be called, like Cargo does

commit-id:9877aa8b
  • Loading branch information
mkaput committed Aug 18, 2023
1 parent c183d11 commit 11db5de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 9 additions & 4 deletions scarb/src/ops/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,24 @@ pub fn execute_test_subcommand(
args: &[OsString],
ws: &Workspace<'_>,
) -> Result<()> {
ws.config().ui().print(Status::new(
"Running tests",
format!("for package: {}", package.id.name).as_str(),
));
let package_name = &package.id.name;
let env = Some(HashMap::from_iter([(
SCARB_MANIFEST_PATH_ENV.into(),
package.manifest_path().into(),
)]));
if let Some(script_definition) = package.manifest.scripts.get("test") {
debug!("using `test` script: {script_definition}");
ws.config().ui().print(Status::new(
"Running",
&format!("test {package_name} ({script_definition})"),
));
ops::execute_script(script_definition, args, ws, package.root(), env)
} else {
debug!("no explicit `test` script found, delegating to scarb-cairo-test");
ws.config().ui().print(Status::new(
"Running",
&format!("cairo-test {package_name}"),
));
let args = args.iter().map(OsString::from).collect::<Vec<_>>();
execute_external_subcommand("cairo-test", args.as_ref(), ws.config(), env)
}
Expand Down
6 changes: 3 additions & 3 deletions scarb/tests/test_subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn delegates_to_cairo_test() {
.assert()
.success()
.stdout_eq(indoc! {r#"
Running tests for package: pkg0
Running cairo-test pkg0
Hello beautiful world
"#});
}
Expand All @@ -44,7 +44,7 @@ fn prefers_test_script() {
.assert()
.success()
.stdout_eq(indoc! {r#"
Running tests for package: pkg0
Running test pkg0 (echo 'Hello from script')
Hello from script beautiful world
"#});
}
Expand All @@ -67,7 +67,7 @@ fn errors_when_missing_script_and_cairo_test() {
.assert()
.failure()
.stdout_eq(indoc! {r#"
Running tests for package: pkg0
Running cairo-test pkg0
error: no such command: `cairo-test`
"#});
}
2 changes: 2 additions & 0 deletions utils/scarb-ui/src/components/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use serde::{Serialize, Serializer};

use crate::Message;

/// Notes:
/// - `status` should always be a single verb, for example _Compiling_, _Running_.
#[derive(Serialize)]
pub struct Status<'a> {
status: &'a str,
Expand Down

0 comments on commit 11db5de

Please sign in to comment.