Skip to content

Commit

Permalink
Add deprecation warning to cairo-run (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr authored Jan 30, 2025
1 parent 7078d83 commit d9fd2ec
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 90 deletions.
1 change: 1 addition & 0 deletions extensions/scarb-cairo-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct Args {
fn main() -> ExitCode {
let args: Args = Args::parse();
let ui = Ui::new(args.verbose.clone().into(), OutputFormat::Text);
ui.warn("`scarb cairo-run` will be deprecated soon\nhelp: use `scarb execute` instead");
if let Err(err) = main_inner(&ui, args) {
ui.anyhow(&err);
return ExitCode::FAILURE;
Expand Down
127 changes: 62 additions & 65 deletions extensions/scarb-cairo-run/tests/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use assert_fs::TempDir;
use indoc::indoc;
use scarb_test_support::command::Scarb;
use scarb_test_support::project_builder::ProjectBuilder;
use snapbox::cmd::OutputAssert;

fn setup_fib_three_felt_args(t: &TempDir) {
ProjectBuilder::start()
Expand Down Expand Up @@ -35,6 +36,8 @@ fn valid_number_of_args() {
.assert()
.success()
.stdout_matches(indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
Compiling hello v0.1.0 ([..]/Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
Expand Down Expand Up @@ -64,6 +67,8 @@ fn can_deserialize_big_number() {
.assert()
.success()
.stdout_matches(indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
Compiling hello v0.1.0 ([..]/Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
Expand All @@ -84,27 +89,20 @@ fn invalid_number_of_args() {
.assert()
.failure();

#[cfg(windows)]
snapbox.stdout_matches(indoc! {r#"
Compiling hello v0.1.0 ([..]/Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
error: failed to run the function
Caused by:
Function expects arguments of size 3 and received 4 instead.
error: process did not exit successfully: exit code: 1
"#});
#[cfg(not(windows))]
snapbox.stdout_matches(indoc! {r#"
Compiling hello v0.1.0 ([..]/Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
error: failed to run the function
Caused by:
Function expects arguments of size 3 and received 4 instead.
"#});
output_assert(
snapbox,
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
Compiling hello v0.1.0 ([..]/Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
error: failed to run the function
Caused by:
Function expects arguments of size 3 and received 4 instead.
"#},
);
}

#[test]
Expand All @@ -120,27 +118,20 @@ fn array_instead_of_felt() {
.assert()
.failure();

#[cfg(windows)]
snapbox.stdout_matches(indoc! {r#"
Compiling hello v0.1.0 ([..]Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
error: failed to run the function
Caused by:
Function param 2 only partially contains argument 2.
error: process did not exit successfully: exit code: 1
"#});
#[cfg(not(windows))]
snapbox.stdout_matches(indoc! {r#"
output_assert(
snapbox,
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
Compiling hello v0.1.0 ([..]Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
error: failed to run the function
Caused by:
Function param 2 only partially contains argument 2.
"#});
"#},
);
}

#[test]
Expand Down Expand Up @@ -218,6 +209,8 @@ fn struct_deserialization() {
.assert()
.success()
.stdout_matches(indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
Compiling hello v0.1.0 ([..]/Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
Expand Down Expand Up @@ -264,27 +257,20 @@ fn invalid_struct_deserialization() {
.failure();

// Received 2, because arrays in Cairo are represented as [begin_addr, end_addr]
#[cfg(windows)]
snapbox.stdout_matches(indoc! {r#"
Compiling hello v0.1.0 ([..]Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
error: failed to run the function
Caused by:
Function expects arguments of size 3 and received 2 instead.
error: process did not exit successfully: exit code: 1
"#});
#[cfg(not(windows))]
snapbox.stdout_matches(indoc! {r#"
Compiling hello v0.1.0 ([..]Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
error: failed to run the function
Caused by:
Function expects arguments of size 3 and received 2 instead.
"#});
output_assert(
snapbox,
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
Compiling hello v0.1.0 ([..]Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello
error: failed to run the function
Caused by:
Function expects arguments of size 3 and received 2 instead.
"#},
);
}

#[test]
Expand All @@ -308,6 +294,8 @@ fn can_accept_nested_array() {
.assert()
.success()
.stdout_matches(indoc! {r#"
[..]warn: `scarb cairo-run` will be deprecated soon
[..]help: use `scarb execute` instead
[..] Compiling hello v0.1.0 ([..]Scarb.toml)
[..] Finished `dev` profile target(s) in [..]
[..] Running hello
Expand Down Expand Up @@ -354,15 +342,15 @@ fn cannot_set_gas_limit_for_package_with_disabled_gas_calculation() {
.current_dir(&t)
.assert()
.failure();
#[cfg(windows)]
output.stdout_eq(indoc! {r#"
error: gas calculation disabled for package `hello`, cannot define custom gas limit
error: process did not exit successfully: exit code: 1
"#});
#[cfg(not(windows))]
output.stdout_eq(indoc! {r#"
error: gas calculation disabled for package `hello`, cannot define custom gas limit
"#});

output_assert(
output,
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
error: gas calculation disabled for package `hello`, cannot define custom gas limit
"#},
);
}

#[test]
Expand All @@ -387,3 +375,12 @@ fn can_control_verbosity() {
something
"#});
}

fn output_assert(output: OutputAssert, expected: &str) {
#[cfg(windows)]
output.stdout_matches(format!(
"{expected}error: process did not exit successfully: exit code: 1\n"
));
#[cfg(not(windows))]
output.stdout_matches(expected);
}
20 changes: 20 additions & 0 deletions extensions/scarb-cairo-run/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fn can_run_default_main_function() {
.assert()
.success()
.stdout_matches(indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand All @@ -49,6 +51,8 @@ fn can_run_default_main_function_with_plugin() {
.assert()
.success()
.stdout_matches(indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand Down Expand Up @@ -76,6 +80,8 @@ fn no_entrypoint_fails() {
.assert()
.failure(),
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand Down Expand Up @@ -108,6 +114,8 @@ fn no_debug_build_fails() {
.assert()
.failure(),
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand Down Expand Up @@ -141,6 +149,8 @@ fn can_run_executable() {
.assert()
.success()
.stdout_matches(indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand Down Expand Up @@ -173,6 +183,8 @@ fn ambiguous_executables_will_fail() {
.assert()
.failure(),
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand Down Expand Up @@ -213,6 +225,8 @@ fn ambiguous_executables_will_fail_no_debug_names() {
.failure(),
// Note that we cannot list available executables, as we don't know their debug names.
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand Down Expand Up @@ -295,6 +309,8 @@ fn cannot_choose_non_executable_if_any_present() {
.assert()
.failure(),
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand Down Expand Up @@ -334,6 +350,8 @@ fn can_choose_executable_to_run() {
.assert()
.success()
.stdout_matches(indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand Down Expand Up @@ -362,6 +380,8 @@ fn choose_not_existing_function() {
.assert()
.failure(),
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Running hello
Expand Down
57 changes: 32 additions & 25 deletions extensions/scarb-cairo-run/tests/examples.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use assert_fs::TempDir;
use indoc::indoc;
use snapbox::cmd::{cargo_bin, Command};
use snapbox::cmd::{cargo_bin, Command, OutputAssert};

use scarb_test_support::cargo::manifest_dir;

Expand All @@ -26,6 +26,8 @@ fn scarb_build_is_called() {
.assert()
.success()
.stdout_matches(indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
Compiling hello_world v0.1.0 ([..]/Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello_world
Expand Down Expand Up @@ -56,17 +58,15 @@ fn build_can_be_skipped() {
.assert()
.failure();

#[cfg(windows)]
snapbox.stdout_eq(indoc! {r#"
error: package has not been compiled, file does not exist: `hello_world.sierra.json`
help: run `scarb build` to compile the package
error: process did not exit successfully: exit code: 1
"#});
#[cfg(not(windows))]
snapbox.stdout_eq(indoc! {r#"
error: package has not been compiled, file does not exist: `hello_world.sierra.json`
help: run `scarb build` to compile the package
"#});
output_assert(
snapbox,
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
error: package has not been compiled, file does not exist: `hello_world.sierra.json`
help: run `scarb build` to compile the package
"#},
);
}

#[test]
Expand All @@ -93,6 +93,8 @@ fn can_limit_gas() {
.assert()
.success()
.stdout_matches(indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
Compiling hello_world v0.1.0 ([..]/Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello_world
Expand Down Expand Up @@ -125,19 +127,24 @@ fn can_disable_gas() {
.assert()
.failure();

output_assert(
snapbox,
indoc! {r#"
warn: `scarb cairo-run` will be deprecated soon
help: use `scarb execute` instead
Compiling hello_world v0.1.0 ([..]Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello_world
error: program requires gas counter, please provide `--available-gas` argument
"#},
);
}

fn output_assert(output: OutputAssert, expected: &str) {
#[cfg(windows)]
snapbox.stdout_matches(indoc! {r#"
Compiling hello_world v0.1.0 ([..]Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello_world
error: program requires gas counter, please provide `--available-gas` argument
error: process did not exit successfully: exit code: 1
"#});
output.stdout_matches(format!(
"{expected}error: process did not exit successfully: exit code: 1\n"
));
#[cfg(not(windows))]
snapbox.stdout_matches(indoc! {r#"
Compiling hello_world v0.1.0 ([..]Scarb.toml)
Finished `dev` profile target(s) in [..]
Running hello_world
error: program requires gas counter, please provide `--available-gas` argument
"#});
output.stdout_matches(expected);
}
Loading

0 comments on commit d9fd2ec

Please sign in to comment.