Skip to content

Commit 18f1ca1

Browse files
authored
Fix scarb execute outputs (#1918)
Update config to prepare trace and memory files for standard output - Fixes empty memory output for bootloader target - Don't generate trace for cairo-pie output
1 parent 9c9625a commit 18f1ca1

File tree

6 files changed

+54
-10
lines changed

6 files changed

+54
-10
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/scarb-execute/src/main.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ enum OutputFormat {
102102
Standard,
103103
}
104104
impl OutputFormat {
105+
pub fn is_standard(&self) -> bool {
106+
matches!(self, OutputFormat::Standard)
107+
}
105108
pub fn is_cairo_pie(&self) -> bool {
106109
matches!(self, OutputFormat::CairoPie)
107110
}
@@ -218,9 +221,9 @@ fn main_inner(args: Args, ui: Ui) -> Result<(), anyhow::Error> {
218221
allow_missing_builtins: Some(true),
219222
layout: LayoutName::all_cairo,
220223
proof_mode: args.run.target.is_standalone(),
221-
relocate_mem: args.run.target.is_standalone(),
222224
secure_run: None,
223-
trace_enabled: true,
225+
relocate_mem: args.run.output.is_standard(),
226+
trace_enabled: args.run.output.is_standard(),
224227
..Default::default()
225228
};
226229

extensions/scarb-execute/tests/build.rs

+37-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use assert_fs::assert::PathAssert;
22
use assert_fs::fixture::PathChild;
33
use assert_fs::TempDir;
44
use indoc::indoc;
5+
use predicates::prelude::*;
56
use scarb_test_support::command::Scarb;
7+
use scarb_test_support::fsx::ChildPathEx;
8+
use scarb_test_support::predicates::is_file_empty;
69
use scarb_test_support::project_builder::ProjectBuilder;
710
use snapbox::cmd::OutputAssert;
811

@@ -41,13 +44,13 @@ fn can_execute_default_main_function_from_executable() {
4144
"#});
4245

4346
t.child("target/execute/hello/air_private_input.json")
44-
.assert(predicates::path::exists());
47+
.assert_is_json::<serde_json::Value>();
4548
t.child("target/execute/hello/air_public_input.json")
46-
.assert(predicates::path::exists());
49+
.assert_is_json::<serde_json::Value>();
4750
t.child("target/execute/hello/memory.bin")
48-
.assert(predicates::path::exists());
51+
.assert(predicates::path::exists().and(is_file_empty().not()));
4952
t.child("target/execute/hello/trace.bin")
50-
.assert(predicates::path::exists());
53+
.assert(predicates::path::exists().and(is_file_empty().not()));
5154
}
5255

5356
#[test]
@@ -66,13 +69,39 @@ fn can_execute_prebuilt_executable() {
6669
"#});
6770

6871
t.child("target/execute/hello/air_private_input.json")
69-
.assert(predicates::path::exists());
72+
.assert_is_json::<serde_json::Value>();
7073
t.child("target/execute/hello/air_public_input.json")
71-
.assert(predicates::path::exists());
74+
.assert_is_json::<serde_json::Value>();
7275
t.child("target/execute/hello/memory.bin")
73-
.assert(predicates::path::exists());
76+
.assert(predicates::path::exists().and(is_file_empty().not()));
7477
t.child("target/execute/hello/trace.bin")
75-
.assert(predicates::path::exists());
78+
.assert(predicates::path::exists().and(is_file_empty().not()));
79+
}
80+
81+
#[test]
82+
fn can_execute_bootloader_target() {
83+
let t = build_executable_project();
84+
Scarb::quick_snapbox()
85+
.arg("execute")
86+
.arg("--target=bootloader")
87+
.current_dir(&t)
88+
.assert()
89+
.success()
90+
.stdout_matches(indoc! {r#"
91+
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
92+
[..]Finished `dev` profile target(s) in [..]
93+
[..]Executing hello
94+
Saving output to: target/execute/hello
95+
"#});
96+
97+
t.child("target/execute/hello/air_private_input.json")
98+
.assert_is_json::<serde_json::Value>();
99+
t.child("target/execute/hello/air_public_input.json")
100+
.assert_is_json::<serde_json::Value>();
101+
t.child("target/execute/hello/memory.bin")
102+
.assert(predicates::path::exists().and(is_file_empty().not()));
103+
t.child("target/execute/hello/trace.bin")
104+
.assert(predicates::path::exists().and(is_file_empty().not()));
76105
}
77106

78107
#[test]

utils/scarb-test-support/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ tokio.workspace = true
2828
toml_edit.workspace = true
2929
tower-http.workspace = true
3030
url.workspace = true
31+
predicates.workspace = true
32+

utils/scarb-test-support/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod filesystem;
66
pub mod fsx;
77
pub mod gitx;
88
pub mod manifest_edit;
9+
pub mod predicates;
910
pub mod proc_macro_server;
1011
pub mod project_builder;
1112
pub mod registry;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use predicates::function::function;
2+
use predicates::Predicate;
3+
use std::fs;
4+
use std::path::Path;
5+
6+
pub fn is_file_empty() -> impl Predicate<Path> {
7+
function(|path| fs::metadata(path).map(|m| m.len() == 0).unwrap_or(true))
8+
}

0 commit comments

Comments
 (0)